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

Allow being added back into a group after exclusion (using members tangle) #95

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"sodium-native": "^3.4.1",
"ssb-bfe": "^3.7.0",
"ssb-crut": "^4.6.2",
"ssb-keyring": "^5.6.0",
"ssb-keyring": "^7.0.0",
"ssb-keys": "^8.5.0",
"ssb-private-group-keys": "^0.4.1",
"ssb-ref": "^2.16.0",
Expand Down
11 changes: 7 additions & 4 deletions test/api/add-new-author-listener.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ const { promisify: p } = require('util')
const { Server, replicate } = require('../helpers')

test('addNewAuthorListener', t => {
t.plan(6)

const admin = Server({ name: 'admin', debug: false }) // me
const newPerson = Server({ name: 'newPerson', debug: false }) // some friend

Expand Down Expand Up @@ -38,8 +36,13 @@ test('addNewAuthorListener', t => {
t.equal(_groupId, groupId, 'newPerson, returns expected groupId')

setTimeout(() => {
admin.close()
newPerson.close()
Promise.all([
p(admin.close)(true),
p(newPerson.close)(true)
]).then(()=>{
if(numAdded === 2) t.end()
else t.fail("didn't get all listener events")
})
}, 1000)
})

Expand Down
52 changes: 39 additions & 13 deletions test/api/exclude-members.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const test = require('tape')
const { promisify: p } = require('util')
const ssbKeys = require('ssb-keys')
const { Server, replicate, FeedId } = require('../helpers')

test('tribes.excludeMembers', async t => {
const kaitiaki = Server()
const newPerson = Server()
const newPersonKeys = ssbKeys.generate()
const kaitiaki = Server({ name: 'kaitiaki' })
const newPerson = Server({ name: 'newPerson', keys: newPersonKeys })

const name = id => {
if (id === kaitiaki.id) return 'kaitiaki '
Expand Down Expand Up @@ -55,18 +57,42 @@ test('tribes.excludeMembers', async t => {

const excludedList = await p(newPerson.tribes.list)()
t.deepEqual(excludedList, [], "new person can't list any groups anymore")
} catch (err) {
t.fail(err)
}

await p(setTimeout)(500)
// excluding again to make us use the members tangle to calculate membership
await p(kaitiaki.tribes.excludeMembers)(groupId, [newPerson.id]).catch(err => t.error(err, err.message))

await p(kaitiaki.tribes.invite)(
groupId, [newPerson.id], {}
)

const reAddedAuthors = await p(kaitiaki.tribes.listAuthors)(groupId)
t.deepEqual(reAddedAuthors.sort(), [kaitiaki.id, newPerson.id].sort(), 're-added person is listed as a member')

await p(replicate)({ from: kaitiaki, to: newPerson, live: false, name })

const newPersonBackInGroup = await p(newPerson.tribes.get)(groupId)
t.equal(newPersonBackInGroup.excluded, undefined, 'new person is not excluded anymore')

await p(setTimeout)(500)

await Promise.all([
p(kaitiaki.close)(true),
p(newPerson.close)(true)
])
.then(() => t.pass('clients close'))
.catch((err) => t.error(err))

await p(setTimeout)(500)

const newPerson2 = Server({ name: 'newPerson',keys: newPersonKeys, startUnclean: true })

await Promise.all([
p(kaitiaki.close)(true),
p(newPerson.close)(true)
])
.then(() => t.pass('clients close'))
.catch((err) => t.error(err))
const stillInGroup = await p(newPerson2.tribes.get)(groupId)
t.equal(stillInGroup.excluded, undefined, 'new person is still not excluded after client restart')

t.end()
await p(setTimeout)(500)

await p(newPerson2.close)(true)
} catch (err) {
t.fail(err)
}
})
9 changes: 6 additions & 3 deletions test/rebuild.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const test = require('tape')
const pull = require('pull-stream')
const { promisify: p } = require('util')

const { Server, replicate, FeedId } = require('./helpers')

Expand Down Expand Up @@ -166,9 +167,11 @@ test('rebuild (I am added to a group, then someone else is added)', t => {
(err) => {
if (seenMine === 20) t.equal(seenMine, 20, 'bob saw 20 messages from me')
if (err) throw err
bob.close()
admin.close()
t.end()

Promise.all([
p(bob.close)(true),
p(admin.close)(true)
]).then(()=>t.end())
}
)
)
Expand Down
Loading