1
1
package tests
2
2
3
3
import (
4
+ "encoding/json"
4
5
"testing"
5
6
6
7
"github.com/matrix-org/complement"
@@ -17,8 +18,17 @@ func TestFederationRoomsInvite(t *testing.T) {
17
18
deployment := complement .Deploy (t , 2 )
18
19
defer deployment .Destroy (t )
19
20
20
- alice := deployment .Register (t , "hs1" , helpers.RegistrationOpts {})
21
- bob := deployment .Register (t , "hs2" , helpers.RegistrationOpts {})
21
+ alice := deployment .Register (t , "hs1" , helpers.RegistrationOpts {LocalpartSuffix : "alice" })
22
+ bob := deployment .Register (t , "hs2" , helpers.RegistrationOpts {LocalpartSuffix : "bob" })
23
+ bob2 := deployment .Register (t , "hs2" , helpers.RegistrationOpts {LocalpartSuffix : "bob2" })
24
+
25
+ includeLeaveSyncFilterBytes , err := json .Marshal (map [string ]interface {}{
26
+ "room" : map [string ]interface {}{
27
+ "include_leave" : true ,
28
+ },
29
+ })
30
+ must .NotError (t , "failed to marshal include_leave filter" , err )
31
+ includeLeaveSyncFilter := string (includeLeaveSyncFilterBytes )
22
32
23
33
t .Run ("Parallel" , func (t * testing.T ) {
24
34
// sytest: Invited user can reject invite over federation
@@ -30,7 +40,7 @@ func TestFederationRoomsInvite(t *testing.T) {
30
40
})
31
41
bob .MustSyncUntil (t , client.SyncReq {}, client .SyncInvitedTo (bob .UserID , roomID ))
32
42
bob .MustLeaveRoom (t , roomID )
33
- alice .MustSyncUntil (t , client.SyncReq {}, client .SyncLeftFrom (bob .UserID , roomID ))
43
+ alice .MustSyncUntil (t , client.SyncReq {Filter : includeLeaveSyncFilter }, client .SyncLeftFrom (bob .UserID , roomID ))
34
44
})
35
45
36
46
// sytest: Invited user can reject invite over federation several times
@@ -43,7 +53,7 @@ func TestFederationRoomsInvite(t *testing.T) {
43
53
alice .MustInviteRoom (t , roomID , bob .UserID )
44
54
bob .MustSyncUntil (t , client.SyncReq {}, client .SyncInvitedTo (bob .UserID , roomID ))
45
55
bob .MustLeaveRoom (t , roomID )
46
- alice .MustSyncUntil (t , client.SyncReq {}, client .SyncLeftFrom (bob .UserID , roomID ))
56
+ alice .MustSyncUntil (t , client.SyncReq {Filter : includeLeaveSyncFilter }, client .SyncLeftFrom (bob .UserID , roomID ))
47
57
}
48
58
})
49
59
@@ -57,9 +67,9 @@ func TestFederationRoomsInvite(t *testing.T) {
57
67
aliceSince := alice .MustSyncUntil (t , client.SyncReq {}, client .SyncJoinedTo (alice .UserID , roomID ))
58
68
bobSince := bob .MustSyncUntil (t , client.SyncReq {}, client .SyncInvitedTo (bob .UserID , roomID ))
59
69
alice .MustLeaveRoom (t , roomID )
60
- alice .MustSyncUntil (t , client.SyncReq {Since : aliceSince }, client .SyncLeftFrom (alice .UserID , roomID ))
70
+ alice .MustSyncUntil (t , client.SyncReq {Since : aliceSince , Filter : includeLeaveSyncFilter }, client .SyncLeftFrom (alice .UserID , roomID ))
61
71
bob .MustLeaveRoom (t , roomID )
62
- bob .MustSyncUntil (t , client.SyncReq {Since : bobSince }, client .SyncLeftFrom (bob .UserID , roomID ))
72
+ bob .MustSyncUntil (t , client.SyncReq {Since : bobSince , Filter : includeLeaveSyncFilter }, client .SyncLeftFrom (bob .UserID , roomID ))
63
73
})
64
74
65
75
// sytest: Remote invited user can see room metadata
@@ -85,6 +95,50 @@ func TestFederationRoomsInvite(t *testing.T) {
85
95
verifyState (t , res , wantFields , wantValues , roomID , alice )
86
96
})
87
97
98
+ t .Run ("Remote invited user can join the room when homeserver is already participating in the room" , func (t * testing.T ) {
99
+ t .Parallel ()
100
+ roomID := alice .MustCreateRoom (t , map [string ]interface {}{
101
+ "preset" : "private_chat" ,
102
+ })
103
+ alice .MustSyncUntil (t , client.SyncReq {}, client .SyncJoinedTo (alice .UserID , roomID ))
104
+
105
+ // bob1 is invited and can join the room (hs2 is now participating of the room)
106
+ alice .MustInviteRoom (t , roomID , bob .UserID )
107
+ bob .MustSyncUntil (t , client.SyncReq {}, client .SyncInvitedTo (bob .UserID , roomID ))
108
+ bob .MustJoinRoom (t , roomID , []string {"hs1" })
109
+ // Make sure alice can see bob in the room
110
+ alice .MustSyncUntil (t , client.SyncReq {}, client .SyncJoinedTo (bob .UserID , roomID ))
111
+
112
+ // bob2 is invited and can also join the room
113
+ alice .MustInviteRoom (t , roomID , bob2 .UserID )
114
+ bob2 .MustSyncUntil (t , client.SyncReq {}, client .SyncInvitedTo (bob2 .UserID , roomID ))
115
+ bob2 .MustJoinRoom (t , roomID , []string {"hs1" })
116
+ // Make sure alice can see bob2 in the room
117
+ alice .MustSyncUntil (t , client.SyncReq {}, client .SyncJoinedTo (bob2 .UserID , roomID ))
118
+ })
119
+
120
+ t .Run ("Remote invited user can reject invite when homeserver is already participating in the room" , func (t * testing.T ) {
121
+ t .Parallel ()
122
+ roomID := alice .MustCreateRoom (t , map [string ]interface {}{
123
+ "preset" : "private_chat" ,
124
+ })
125
+ alice .MustSyncUntil (t , client.SyncReq {}, client .SyncJoinedTo (alice .UserID , roomID ))
126
+
127
+ // bob1 is invited and can join the room (hs2 is now participating of the room)
128
+ alice .MustInviteRoom (t , roomID , bob .UserID )
129
+ bob .MustSyncUntil (t , client.SyncReq {}, client .SyncInvitedTo (bob .UserID , roomID ))
130
+ bob .MustJoinRoom (t , roomID , []string {"hs1" })
131
+ // Make sure alice can see bob in the room
132
+ alice .MustSyncUntil (t , client.SyncReq {}, client .SyncJoinedTo (bob .UserID , roomID ))
133
+
134
+ // bob2 is invited and can reject the invite (leave the room)
135
+ alice .MustInviteRoom (t , roomID , bob2 .UserID )
136
+ bob2 .MustSyncUntil (t , client.SyncReq {}, client .SyncInvitedTo (bob2 .UserID , roomID ))
137
+ bob2 .MustLeaveRoom (t , roomID )
138
+ // Make sure alice can see bob2 left the room
139
+ alice .MustSyncUntil (t , client.SyncReq {Filter : includeLeaveSyncFilter }, client .SyncLeftFrom (bob2 .UserID , roomID ))
140
+ })
141
+
88
142
t .Run ("Invited user has 'is_direct' flag in prev_content after joining" , func (t * testing.T ) {
89
143
roomID := alice .MustCreateRoom (t , map [string ]interface {}{
90
144
"preset" : "private_chat" ,
0 commit comments