Skip to content

Commit

Permalink
Fix parsing of "events_default" level in m.room.power_levels events
Browse files Browse the repository at this point in the history
  • Loading branch information
neilalexander committed Aug 15, 2022
1 parent 6a49c18 commit 723fd49
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
59 changes: 59 additions & 0 deletions eventauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1137,3 +1137,62 @@ func newMemberContent(
ThirdPartyInvite: thirdPartyInvite,
}
}

var negativePowerLevelTestRoom = &testAuthEvents{
CreateJSON: json.RawMessage(`{
"type": "m.room.create",
"state_key": "",
"sender": "@u1:a",
"room_id": "!r1:a",
"event_id": "$e1:a",
"content": {
"room_version": "10"
}
}`),
PowerLevelsJSON: json.RawMessage(`{
"type": "m.room.power_levels",
"state_key": "",
"sender": "@u1:a",
"room_id": "!r1:a",
"event_id": "$e3:a",
"content": {
"events_default": -9007199254740990,
"state_default": -9007199254740990,
"users_default": -9007199254740990,
"users": {
}
}
}`),
MemberJSON: map[string]json.RawMessage{
"@u1:a": json.RawMessage(`{
"type": "m.room.member",
"state_key": "@u1:a",
"sender": "@u1:a",
"room_id": "!r1:a",
"event_id": "$e2:a",
"content": {
"membership": "join"
}
}`),
},
}

func TestNegativePowerLevels(t *testing.T) {
// User should be able to demote the user default level
// below their own effective level.
eventShouldSucceed, err := NewEventFromTrustedJSON(RawJSON(`{
"type": "m.room.message",
"sender": "@u1:a",
"room_id": "!r1:a",
"event_id": "$e5:a",
"content": {
"stuff": "i am a message event"
}
}`), false, RoomVersionV1)
if err != nil {
t.Fatal(err)
}
if err = Allowed(eventShouldSucceed, negativePowerLevelTestRoom); err != nil {
t.Error("TestNegativePowerLevels should have succeeded but it didn't:", err)
}
}
2 changes: 1 addition & 1 deletion eventcontent.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ func NewPowerLevelContentFromEvent(event *Event) (c PowerLevelContent, err error
UsersDefaultLevel levelJSONValue `json:"users_default"`
EventLevels map[string]levelJSONValue `json:"events"`
StateDefaultLevel levelJSONValue `json:"state_default"`
EventDefaultLevel levelJSONValue `json:"event_default"`
EventDefaultLevel levelJSONValue `json:"events_default"`
NotificationLevels map[string]levelJSONValue `json:"notifications"`
}
if err = json.Unmarshal(event.Content(), &content); err != nil {
Expand Down

0 comments on commit 723fd49

Please sign in to comment.