Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

People not removed in an exclude should be able to post on the new epoch #78

Merged
merged 20 commits into from
Apr 13, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions test/exclude-members.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const { fromMessageSigil } = require('ssb-uri2')
const Testbot = require('./helpers/testbot')
const replicate = require('./helpers/replicate')
const countGroupFeeds = require('./helpers/count-group-feeds')
const pull = require('pull-stream')

test('add and remove a person, post on the new feed', async (t) => {
// Alice's feeds should look like
Expand Down Expand Up @@ -154,3 +155,117 @@ test('add and remove a person, post on the new feed', async (t) => {
await p(alice.close)(true)
await p(bob.close)(true)
})

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) => {
// alice creates the group. adds bob and carol. removes bob.
// bob gets added and is removed
// carol stays in the group
const alice = Testbot({
keys: ssbKeys.generate(null, 'alice'),
mfSeed: Buffer.from(
'000000000000000000000000000000000000000000000000000000000000a1ce',
'hex'
),
})
const bob = Testbot({
keys: ssbKeys.generate(null, 'bob'),
mfSeed: Buffer.from(
'0000000000000000000000000000000000000000000000000000000000000b0b',
'hex'
),
})
const carol = Testbot({
keys: ssbKeys.generate(null, 'carol'),
mfSeed: Buffer.from(
'00000000000000000000000000000000000000000000000000000000000ca201',
'hex'
),
})

await alice.tribes2.start()
await bob.tribes2.start()
await carol.tribes2.start()
t.pass('tribes2 started for everyone')

await p(alice.metafeeds.findOrCreate)()
const bobRoot = await p(bob.metafeeds.findOrCreate)()
const carolRoot = await p(carol.metafeeds.findOrCreate)()

await replicate(alice, bob)
await replicate(alice, carol)
await replicate(bob, carol)
t.pass('everyone replicates their trees')

const { id: groupId, writeKey: writeKey1 } = await alice.tribes2
.create()
.catch((err) => t.error(err, 'alice failed to create group'))

await replicate(alice, carol)

await alice.tribes2
.addMembers(groupId, [bobRoot.id, carolRoot.id])
.catch((err) => t.error(err, 'add bob fail'))

await replicate(alice, carol)

await carol.tribes2.acceptInvite(groupId)

await replicate(alice, carol)

const {
value: { author: firstFeedId },
} = await carol.tribes2
.publish({
type: 'test',
text: 'first post',
recps: [groupId],
})
.catch((err) => t.error(err, 'carol failed to publish on first feed'))

await alice.tribes2
.excludeMembers(groupId, [bobRoot.id])
.catch((err) => t.error(err, 'remove member fail'))

await replicate(alice, carol)

const {
value: { author: secondFeedId },
} = await carol.tribes2
.publish({
type: 'test',
text: 'second post',
recps: [groupId],
})
.catch(t.fail)

t.notEquals(
secondFeedId,
firstFeedId,
'feed for second publish is different to first publish'
)

const { writeKey: writeKey2 } = await carol.tribes2.get(groupId)

const branches = await pull(
carol.metafeeds.branchStream({ root: carolRoot, old: true, live: false }),
pull.toPromise()
)

const groupFeedPurposes = branches
.filter((branch) => branch.length === 4)
.map((branch) => branch[3])
.filter((feed) => feed.recps && feed.purpose.length === 44)
.map((feed) => feed.purpose)

t.true(
groupFeedPurposes.includes(writeKey1.key.toString('base64')),
'Carol has a feed for the old key'
)
t.true(
groupFeedPurposes.includes(writeKey2.key.toString('base64')),
'Carol has a feed for the new key'
)

await p(alice.close)(true)
await p(bob.close)(true)
})