@@ -56,4 +56,85 @@ test.describe("History sharing", function () {
5656 } ) ;
5757 } ,
5858 ) ;
59+
60+ test ( "Messages sent when we believed the room history was unshared should not be visible" , async ( {
61+ labsFlags,
62+ browser,
63+ page : alicePage ,
64+ user : aliceCredentials ,
65+ app : aliceElementApp ,
66+ homeserver,
67+ } , testInfo ) => {
68+ test . setTimeout ( 60000 ) ;
69+
70+ // In this test:
71+ // 1. Alice creates an encrypted room with Bob.
72+ // 2. She sets the history visibility to "shared", but Bob doesn't receive the memo
73+ // 3. Bob sends a message
74+ // 4. Alice invites Charlie
75+ // 5. Charlie can't see the message.
76+
77+ await aliceElementApp . client . bootstrapCrossSigning ( aliceCredentials ) ;
78+ await createRoom ( alicePage , "TestRoom" , true ) ;
79+
80+ // Register a second user, and open it in a second instance of the app
81+ const bobCredentials = await homeserver . registerUser ( `user_${ testInfo . testId } _bob` , "password" , "Bob" ) ;
82+ const bobPage = await createNewInstance ( browser , bobCredentials , { } , labsFlags ) ;
83+ const bobElementApp = new ElementAppPage ( bobPage ) ;
84+ await bobElementApp . client . bootstrapCrossSigning ( bobCredentials ) ;
85+
86+ // ... and a third
87+ const charlieCredentials = await homeserver . registerUser (
88+ `user_${ testInfo . testId } _charlie` ,
89+ "password" ,
90+ "Charlie" ,
91+ ) ;
92+ const charliePage = await createNewInstance ( browser , charlieCredentials , { } , labsFlags ) ;
93+ const charlieElementApp = new ElementAppPage ( charliePage ) ;
94+ await charlieElementApp . client . bootstrapCrossSigning ( charlieCredentials ) ;
95+
96+ // Alice invites Bob, and Bob accepts
97+ const roomId = await aliceElementApp . getCurrentRoomIdFromUrl ( ) ;
98+ await aliceElementApp . inviteUserToCurrentRoom ( bobCredentials . userId ) ;
99+ await bobPage . getByRole ( "option" , { name : "TestRoom" } ) . click ( ) ;
100+ await bobPage . getByRole ( "button" , { name : "Accept" } ) . click ( ) ;
101+
102+ // Bob sends a message with "shared" visibility
103+ await sendMessageInCurrentRoom ( bobPage , "Message1: 'shared' visibility" ) ;
104+ await expect ( alicePage . getByText ( "Message1" ) ) . toBeVisible ( ) ;
105+
106+ // Alice sets the history visibility to "joined"
107+ await aliceElementApp . client . sendStateEvent ( roomId , "m.room.history_visibility" , {
108+ history_visibility : "joined" ,
109+ } ) ;
110+ await expect (
111+ bobPage . getByText (
112+ "Alice made future room history visible to all room members, from the point they joined." ,
113+ ) ,
114+ ) . toBeVisible ( ) ;
115+
116+ // Bob stops syncing, and sends a message with "joined" visibility.
117+ // (Stopping syncing *before* sending the message means that the active sync will be flushed by sending the
118+ // message, so that Alice's change to the history viz below won't be seen by Bob.)
119+ await bobPage . route ( `**/sync*` , ( route ) => route . fulfill ( { } ) ) ;
120+ await sendMessageInCurrentRoom ( bobPage , "Message2: 'joined' visibility" ) ;
121+ await expect ( alicePage . getByText ( "Message2" ) ) . toBeVisible ( ) ;
122+
123+ // Alice changes the history viz, but Bob doesn't receive the memo
124+ await aliceElementApp . client . sendStateEvent ( roomId , "m.room.history_visibility" , {
125+ history_visibility : "shared" ,
126+ } ) ;
127+ await sendMessageInCurrentRoom ( bobPage , "Message3: 'shared' visibility, but Bob thinks it is still 'joined'" ) ;
128+
129+ // Alice now invites Charlie
130+ await aliceElementApp . inviteUserToCurrentRoom ( charlieCredentials . userId ) ;
131+ await charliePage . getByRole ( "option" , { name : "TestRoom" } ) . click ( ) ;
132+ await charliePage . getByRole ( "button" , { name : "Accept" } ) . click ( ) ;
133+
134+ // Message1 should be visible
135+ // Message2 should be invisible
136+ // Message3 should be undecryptable
137+ await expect ( charliePage . getByText ( "Message1" ) ) . toBeVisible ( ) ;
138+ await expect ( charliePage . getByText ( "You don't have access to this message" ) ) . toBeVisible ( ) ;
139+ } ) ;
59140} ) ;
0 commit comments