aboutsummaryrefslogtreecommitdiff
path: root/roomserver/storage
diff options
context:
space:
mode:
authorTill <2353100+S7evinK@users.noreply.github.com>2023-11-22 15:38:04 +0100
committerGitHub <noreply@github.com>2023-11-22 15:38:04 +0100
commitb8f91485b47ac6e92a90988b394e8f3611735250 (patch)
tree5f84b6abb2b6fb8d5feed1b43a5ffe30c1ce0c89 /roomserver/storage
parentc4528b2de8c36657039c3d3f541017ee8964c4ac (diff)
Update ACLs when received as outliers (#3008)
This should fix #3004 by making sure we also update our in-memory ACLs after joining a new room. Also makes use of more caching in `GetStateEvent` Bonus: Adds some tests, as I was about to use `GetBulkStateContent`, but turns out that `GetStateEvent` is basically doing the same, just that it only gets the `eventTypeNID`/`eventStateKeyNID` once and not for every call.
Diffstat (limited to 'roomserver/storage')
-rw-r--r--roomserver/storage/tables/interface_test.go76
1 files changed, 76 insertions, 0 deletions
diff --git a/roomserver/storage/tables/interface_test.go b/roomserver/storage/tables/interface_test.go
new file mode 100644
index 00000000..8727e243
--- /dev/null
+++ b/roomserver/storage/tables/interface_test.go
@@ -0,0 +1,76 @@
+package tables
+
+import (
+ "testing"
+
+ "github.com/matrix-org/dendrite/roomserver/types"
+ "github.com/matrix-org/dendrite/test"
+ "github.com/matrix-org/gomatrixserverlib/spec"
+ "github.com/stretchr/testify/assert"
+)
+
+func TestExtractContentValue(t *testing.T) {
+ alice := test.NewUser(t)
+ room := test.NewRoom(t, alice)
+
+ tests := []struct {
+ name string
+ event *types.HeaderedEvent
+ want string
+ }{
+ {
+ name: "returns creator ID for create events",
+ event: room.Events()[0],
+ want: alice.ID,
+ },
+ {
+ name: "returns the alias for canonical alias events",
+ event: room.CreateEvent(t, alice, spec.MRoomCanonicalAlias, map[string]string{"alias": "#test:test"}),
+ want: "#test:test",
+ },
+ {
+ name: "returns the history_visibility for history visibility events",
+ event: room.CreateEvent(t, alice, spec.MRoomHistoryVisibility, map[string]string{"history_visibility": "shared"}),
+ want: "shared",
+ },
+ {
+ name: "returns the join rules for join_rules events",
+ event: room.CreateEvent(t, alice, spec.MRoomJoinRules, map[string]string{"join_rule": "public"}),
+ want: "public",
+ },
+ {
+ name: "returns the membership for room_member events",
+ event: room.CreateEvent(t, alice, spec.MRoomMember, map[string]string{"membership": "join"}, test.WithStateKey(alice.ID)),
+ want: "join",
+ },
+ {
+ name: "returns the room name for room_name events",
+ event: room.CreateEvent(t, alice, spec.MRoomName, map[string]string{"name": "testing"}, test.WithStateKey(alice.ID)),
+ want: "testing",
+ },
+ {
+ name: "returns the room avatar for avatar events",
+ event: room.CreateEvent(t, alice, spec.MRoomAvatar, map[string]string{"url": "mxc://testing"}, test.WithStateKey(alice.ID)),
+ want: "mxc://testing",
+ },
+ {
+ name: "returns the room topic for topic events",
+ event: room.CreateEvent(t, alice, spec.MRoomTopic, map[string]string{"topic": "testing"}, test.WithStateKey(alice.ID)),
+ want: "testing",
+ },
+ {
+ name: "returns guest_access for guest access events",
+ event: room.CreateEvent(t, alice, "m.room.guest_access", map[string]string{"guest_access": "forbidden"}, test.WithStateKey(alice.ID)),
+ want: "forbidden",
+ },
+ {
+ name: "returns empty string if key can't be found or unknown event",
+ event: room.CreateEvent(t, alice, "idontexist", nil),
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ assert.Equalf(t, tt.want, ExtractContentValue(tt.event), "ExtractContentValue(%v)", tt.event)
+ })
+ }
+}