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

Add test for being removed from a group #88

Merged
merged 13 commits into from
Apr 13, 2023
28 changes: 28 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,34 @@ module.exports = {
if (err) return cb(clarify(err, 'Error finding or creating additions feed when starting ssb-tribes2'))
return cb()
})

ssb.metafeeds.findOrCreate((err, myRoot) => {
// prettier-ignore
if (err) return cb(clarify(err, 'todo'))

pull(
ssb.db.query(
where(and(isDecrypted('box2'), type('group/exclude'))),
live({ old: true }),
toPullStream()
),
Powersource marked this conversation as resolved.
Show resolved Hide resolved
pull.filter((msg) =>
// it's an exclusion of us
msg.value?.content?.excludes?.includes(myRoot.id)
),
pull.drain(
(msg) => {
const groupId = msg.value?.content?.recps?.[0]
console.log('removing for groupid', groupId)
ssb.box2.removeGroupInfo(groupId, null)
},
(err) => {
// prettier-ignore
if (err) return cb(clarify(err, 'todo'))
}
)
)
})
}

return {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"pull-paramap": "^1.2.2",
"pull-stream": "^3.7.0",
"ssb-bfe": "^3.7.0",
"ssb-box2": "^6.0.0",
"ssb-box2": "github:ssbc/ssb-box2#remove-group-info",
Powersource marked this conversation as resolved.
Show resolved Hide resolved
"ssb-crut": "^4.6.2",
"ssb-db2": "^6.3.3",
"ssb-meta-feeds": "^0.39.0",
Expand Down
77 changes: 77 additions & 0 deletions test/exclude-members.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,80 @@ test('add and remove a person, post on the new feed', async (t) => {
await p(alice.close)(true)
await p(bob.close)(true)
})

test('Verify that you actually get removed from a group', async (t) => {
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'
),
})

await alice.tribes2.start()
await bob.tribes2.start()
t.pass('tribes2 started for both alice and bob')

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

await replicate(alice, bob)
t.pass('alice and bob replicate their trees')

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

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

await replicate(alice, bob)

await bob.tribes2.acceptInvite(groupId).catch(t.error)

await bob.tribes2
.publish({
type: 'test',
text: 'bob first post',
recps: [groupId],
})
.then(() => t.pass("bob posts in the group while he's in it"))
.catch(t.error)

await replicate(alice, bob)

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

await replicate(alice, bob)

// TODO: lower
await p(setTimeout)(4000)

await bob.tribes2
.publish({
type: 'test',
text: 'bob second post',
recps: [groupId],
})
.then(() =>
t.fail("Bob posted again in the group even if he's removed from it")
)
.catch(() =>
t.pass("Bob can't post in the group anymore since he's removed from it")
)
Powersource marked this conversation as resolved.
Show resolved Hide resolved

// TODO: check bob's group list, it should still have an entry for the group but it should be marked that he's removed from it or something. or an opt for the function?
Powersource marked this conversation as resolved.
Show resolved Hide resolved

// TODO: try to check the messages encrypted to the new key/epoch, and fail
// checking the re-addition messages on alice's additions feed should do
Powersource marked this conversation as resolved.
Show resolved Hide resolved
})