@@ -10,6 +10,7 @@ const { fromMessageSigil } = require('ssb-uri2')
10
10
const Testbot = require ( './helpers/testbot' )
11
11
const replicate = require ( './helpers/replicate' )
12
12
const countGroupFeeds = require ( './helpers/count-group-feeds' )
13
+ const pull = require ( 'pull-stream' )
13
14
14
15
test ( 'add and remove a person, post on the new feed' , async ( t ) => {
15
16
// Alice's feeds should look like
@@ -174,3 +175,131 @@ test('add and remove a person, post on the new feed', async (t) => {
174
175
await p ( alice . close ) ( true )
175
176
await p ( bob . close ) ( true )
176
177
} )
178
+
179
+ test ( "If you're not the excluder nor the excludee then you should still be in the group and have access to the new epoch" , async ( t ) => {
180
+ // alice creates the group. adds bob and carol. removes bob.
181
+ // bob gets added and is removed
182
+ // carol stays in the group
183
+ const alice = Testbot ( {
184
+ keys : ssbKeys . generate ( null , 'alice' ) ,
185
+ mfSeed : Buffer . from (
186
+ '000000000000000000000000000000000000000000000000000000000000a1ce' ,
187
+ 'hex'
188
+ ) ,
189
+ } )
190
+ const bob = Testbot ( {
191
+ keys : ssbKeys . generate ( null , 'bob' ) ,
192
+ mfSeed : Buffer . from (
193
+ '0000000000000000000000000000000000000000000000000000000000000b0b' ,
194
+ 'hex'
195
+ ) ,
196
+ } )
197
+ const carol = Testbot ( {
198
+ keys : ssbKeys . generate ( null , 'carol' ) ,
199
+ mfSeed : Buffer . from (
200
+ '00000000000000000000000000000000000000000000000000000000000ca201' ,
201
+ 'hex'
202
+ ) ,
203
+ } )
204
+
205
+ await alice . tribes2 . start ( )
206
+ await bob . tribes2 . start ( )
207
+ await carol . tribes2 . start ( )
208
+ t . pass ( 'tribes2 started for everyone' )
209
+
210
+ await p ( alice . metafeeds . findOrCreate ) ( )
211
+ const bobRoot = await p ( bob . metafeeds . findOrCreate ) ( )
212
+ const carolRoot = await p ( carol . metafeeds . findOrCreate ) ( )
213
+
214
+ await replicate ( alice , bob )
215
+ await replicate ( alice , carol )
216
+ await replicate ( bob , carol )
217
+ t . pass ( 'everyone replicates their trees' )
218
+
219
+ const { id : groupId , writeKey : writeKey1 } = await alice . tribes2
220
+ . create ( )
221
+ . catch ( ( err ) => t . error ( err , 'alice failed to create group' ) )
222
+
223
+ await replicate ( alice , carol )
224
+
225
+ await alice . tribes2
226
+ . addMembers ( groupId , [ bobRoot . id , carolRoot . id ] )
227
+ . catch ( ( err ) => t . error ( err , 'add bob fail' ) )
228
+
229
+ await replicate ( alice , carol )
230
+
231
+ await carol . tribes2 . acceptInvite ( groupId )
232
+
233
+ await replicate ( alice , carol )
234
+
235
+ const {
236
+ value : { author : firstFeedId } ,
237
+ } = await carol . tribes2
238
+ . publish ( {
239
+ type : 'test' ,
240
+ text : 'first post' ,
241
+ recps : [ groupId ] ,
242
+ } )
243
+ . catch ( ( err ) => t . error ( err , 'carol failed to publish on first feed' ) )
244
+ if ( firstFeedId ) t . pass ( 'carol posted first post' )
245
+
246
+ await alice . tribes2
247
+ . excludeMembers ( groupId , [ bobRoot . id ] )
248
+ . then ( ( res ) => {
249
+ t . pass ( 'alice excluded bob' )
250
+ return res
251
+ } )
252
+ . catch ( ( err ) => t . error ( err , 'remove member fail' ) )
253
+
254
+ await replicate ( alice , carol ) . catch ( t . error )
255
+
256
+ // let carol find the new epoch and switch to the new key
257
+ await p ( setTimeout ) ( 500 )
258
+
259
+ const {
260
+ value : { author : secondFeedId } ,
261
+ } = await carol . tribes2
262
+ . publish ( {
263
+ type : 'test' ,
264
+ text : 'second post' ,
265
+ recps : [ groupId ] ,
266
+ } )
267
+ . catch ( t . fail )
268
+ if ( secondFeedId ) t . pass ( 'carol posted second post' )
269
+
270
+ t . notEquals (
271
+ secondFeedId ,
272
+ firstFeedId ,
273
+ 'feed for second publish is different to first publish'
274
+ )
275
+
276
+ const { writeKey : writeKey2 } = await carol . tribes2 . get ( groupId )
277
+
278
+ const branches = await pull (
279
+ carol . metafeeds . branchStream ( {
280
+ root : carolRoot . id ,
281
+ old : true ,
282
+ live : false ,
283
+ } ) ,
284
+ pull . collectAsPromise ( )
285
+ )
286
+
287
+ const groupFeedPurposes = branches
288
+ . filter ( ( branch ) => branch . length === 4 )
289
+ . map ( ( branch ) => branch [ 3 ] )
290
+ . filter ( ( feed ) => feed . recps && feed . purpose . length === 44 )
291
+ . map ( ( feed ) => feed . purpose )
292
+
293
+ t . true (
294
+ groupFeedPurposes . includes ( writeKey1 . key . toString ( 'base64' ) ) ,
295
+ 'Carol has a feed for the old key'
296
+ )
297
+ t . true (
298
+ groupFeedPurposes . includes ( writeKey2 . key . toString ( 'base64' ) ) ,
299
+ 'Carol has a feed for the new key'
300
+ )
301
+
302
+ await p ( alice . close ) ( true )
303
+ await p ( bob . close ) ( true )
304
+ await p ( carol . close ) ( true )
305
+ } )
0 commit comments