Skip to content

Commit 4b4c7f3

Browse files
Add 3 sytests (#263)
* 3 sytests - Rooms can be created with an initial invite list (SYN-205) - Getting push rules doesn't corrupt the cache SYN-390 - Non-present room members cannot ban others * fix blueprint naming * use must.MatchResponse
1 parent 277e258 commit 4b4c7f3

File tree

3 files changed

+140
-0
lines changed

3 files changed

+140
-0
lines changed

tests/csapi/apidoc_room_create_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,23 @@ func TestRoomCreate(t *testing.T) {
146146
})
147147
})
148148
}
149+
150+
// sytest: Rooms can be created with an initial invite list (SYN-205)
151+
func TestRoomCreateWithInvites(t *testing.T) {
152+
deployment := Deploy(t, b.BlueprintOneToOneRoom)
153+
defer deployment.Destroy(t)
154+
155+
alice := deployment.Client(t, "hs1", "@alice:hs1")
156+
bob := deployment.Client(t, "hs1", "@bob:hs1")
157+
158+
roomID := alice.CreateRoom(t, map[string]interface{}{
159+
"invite": []string{bob.UserID},
160+
})
161+
162+
bob.SyncUntil(t, "", "", "rooms.invite."+client.GjsonEscape(roomID)+".invite_state.events", func(event gjson.Result) bool {
163+
return event.Get("type").Str == "m.room.member" &&
164+
event.Get("content.membership").Str == "invite" &&
165+
event.Get("state_key").Str == bob.UserID &&
166+
event.Get("sender").Str == alice.UserID
167+
})
168+
}

tests/csapi/push_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package csapi_tests
2+
3+
import (
4+
"testing"
5+
6+
"github.com/matrix-org/complement/internal/b"
7+
"github.com/matrix-org/complement/internal/client"
8+
"github.com/matrix-org/complement/internal/match"
9+
"github.com/matrix-org/complement/internal/must"
10+
"github.com/matrix-org/complement/runtime"
11+
)
12+
13+
// @shadowjonathan: do we need this test anymore?
14+
// sytest: Getting push rules doesn't corrupt the cache SYN-390
15+
func TestPushRuleCacheHealth(t *testing.T) {
16+
runtime.SkipIf(t, runtime.Dendrite) // Dendrite does not support push notifications (yet)
17+
18+
deployment := Deploy(t, b.BlueprintAlice)
19+
defer deployment.Destroy(t)
20+
21+
alice := deployment.Client(t, "hs1", "@alice:hs1")
22+
23+
alice.MustDoFunc(t, "PUT", []string{"_matrix", "client", "r0", "pushrules", "global", "sender", alice.UserID}, client.WithJSONBody(t, map[string]interface{}{
24+
"actions": []string{"dont_notify"},
25+
}))
26+
27+
// the extra "" is to make sure the submitted URL ends with a trailing slash
28+
res := alice.MustDoFunc(t, "GET", []string{"_matrix", "client", "r0", "pushrules", ""})
29+
30+
must.MatchResponse(t, res, match.HTTPResponse{
31+
JSON: []match.JSON{
32+
match.JSONKeyEqual("global.sender.0.actions.0", "dont_notify"),
33+
},
34+
})
35+
36+
res = alice.MustDoFunc(t, "GET", []string{"_matrix", "client", "r0", "pushrules", ""})
37+
38+
must.MatchResponse(t, res, match.HTTPResponse{
39+
JSON: []match.JSON{
40+
match.JSONKeyEqual("global.sender.0.actions.0", "dont_notify"),
41+
},
42+
})
43+
}

tests/csapi/room_ban_test.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package csapi_tests
2+
3+
import (
4+
"testing"
5+
6+
"github.com/tidwall/gjson"
7+
8+
"github.com/matrix-org/complement/internal/b"
9+
"github.com/matrix-org/complement/internal/client"
10+
"github.com/matrix-org/complement/internal/match"
11+
"github.com/matrix-org/complement/internal/must"
12+
)
13+
14+
// This is technically a tad different from the sytest, in that it doesnt try to ban a @random_dude:test,
15+
// but this will actually validate against a present user in the room.
16+
// sytest: Non-present room members cannot ban others
17+
func TestNotPresentUserCannotBanOthers(t *testing.T) {
18+
deployment := Deploy(t, b.MustValidate(b.Blueprint{
19+
Name: "abc",
20+
Homeservers: []b.Homeserver{
21+
{
22+
Name: "hs1",
23+
Users: []b.User{
24+
{
25+
Localpart: "@alice",
26+
DisplayName: "Alice",
27+
},
28+
{
29+
Localpart: "@bob",
30+
DisplayName: "Bob",
31+
},
32+
{
33+
Localpart: "@charlie",
34+
DisplayName: "Charlie",
35+
},
36+
},
37+
},
38+
},
39+
}))
40+
defer deployment.Destroy(t)
41+
42+
alice := deployment.Client(t, "hs1", "@alice:hs1")
43+
bob := deployment.Client(t, "hs1", "@bob:hs1")
44+
charlie := deployment.Client(t, "hs1", "@charlie:hs1")
45+
46+
roomID := alice.CreateRoom(t, map[string]interface{}{
47+
"preset": "public_chat",
48+
})
49+
50+
bob.JoinRoom(t, roomID, nil)
51+
52+
alice.SendEventSynced(t, roomID, b.Event{
53+
Type: "m.room.power_levels",
54+
StateKey: b.Ptr(""),
55+
Content: map[string]interface{}{
56+
"users": map[string]interface{}{
57+
charlie.UserID: 100,
58+
},
59+
},
60+
})
61+
62+
// todo: replace with `SyncUntilJoined`
63+
bob.SyncUntilTimelineHas(t, roomID, func(event gjson.Result) bool {
64+
return event.Get("type").Str == "m.room.member" &&
65+
event.Get("content.membership").Str == "join" &&
66+
event.Get("state_key").Str == bob.UserID
67+
})
68+
69+
res := charlie.DoFunc(t, "POST", []string{"_matrix", "client", "r0", "rooms", roomID, "ban"}, client.WithJSONBody(t, map[string]interface{}{
70+
"user_id": bob.UserID,
71+
"reason": "testing",
72+
}))
73+
74+
must.MatchResponse(t, res, match.HTTPResponse{
75+
StatusCode: 403,
76+
})
77+
}

0 commit comments

Comments
 (0)