Implement and test key removal in user-id.js
This commit is contained in:
parent
27155278a8
commit
33d3ad737e
@ -109,19 +109,44 @@ class UserId {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Flag all user IDs of a key for removal by generating a new nonce and
|
* Flag all user IDs of a key for removal by generating a new nonce and
|
||||||
* saving it.
|
* saving it. Either a key id or email address must be provided
|
||||||
* @param {String} keyid The public key id
|
* @param {String} keyid (optional) The public key id
|
||||||
|
* @param {String} email (optional) The user's email address
|
||||||
* @yield {Array} A list of user ids with nonces
|
* @yield {Array} A list of user ids with nonces
|
||||||
*/
|
*/
|
||||||
*flagForRemove(options) {
|
*flagForRemove(options) {
|
||||||
let keyid = options.keyid;
|
let keyid = options.keyid, email = options.email;
|
||||||
let uids = yield this._mongo.list({ keyid }, DB_TYPE);
|
if (email) {
|
||||||
for (let uid of uids) {
|
let uid = yield this._mongo.get({ email }, DB_TYPE);
|
||||||
let nonce = uuid.v4();
|
if (uid) {
|
||||||
yield this._mongo.update(uid, { nonce }, DB_TYPE);
|
let nonce = uuid.v4();
|
||||||
uid.nonce = nonce;
|
yield this._mongo.update(uid, { nonce }, DB_TYPE);
|
||||||
|
uid.nonce = nonce;
|
||||||
|
return [uid];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return uids;
|
if (keyid) {
|
||||||
|
let uids = yield this._mongo.list({ keyid }, DB_TYPE);
|
||||||
|
for (let uid of uids) {
|
||||||
|
let nonce = uuid.v4();
|
||||||
|
yield this._mongo.update(uid, { nonce }, DB_TYPE);
|
||||||
|
uid.nonce = nonce;
|
||||||
|
}
|
||||||
|
return uids;
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get user id which has been flagged for removal by proving knowledge of
|
||||||
|
* the nonce.
|
||||||
|
* @param {string} keyid public key id
|
||||||
|
* @param {string} nonce The verification nonce proving email address ownership
|
||||||
|
* @yield {Object} The matching user id document
|
||||||
|
*/
|
||||||
|
*getFlaggedForRemove(options) {
|
||||||
|
let keyid = options.keyid, nonce = options.nonce;
|
||||||
|
return yield this._mongo.get({ keyid, nonce }, DB_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -101,14 +101,44 @@ describe('User ID Integration Tests', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("flagForRemove", () => {
|
describe("flagForRemove", () => {
|
||||||
it('should flag all documents', function *() {
|
let stored;
|
||||||
let stored = yield userId.batch({ userIds:[uid1, uid2], keyid });
|
beforeEach(function *() {
|
||||||
|
stored = yield userId.batch({ userIds:[uid1, uid2], keyid });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should flag one documents for email param', function *() {
|
||||||
|
let flagged = yield userId.flagForRemove({ email:uid1.email });
|
||||||
|
expect(flagged.length).to.equal(1);
|
||||||
|
expect(flagged[0]._id.toHexString()).to.equal(stored[0]._id.toHexString());
|
||||||
|
expect(flagged[0].nonce).to.not.equal(stored[0].nonce);
|
||||||
|
let gotten = yield mongo.list({ email:uid1.email }, DB_TYPE);
|
||||||
|
expect(gotten).to.deep.equal(flagged);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should flag all documents for key id param', function *() {
|
||||||
let flagged = yield userId.flagForRemove({ keyid });
|
let flagged = yield userId.flagForRemove({ keyid });
|
||||||
|
expect(flagged.length).to.equal(2);
|
||||||
expect(flagged[0]._id.toHexString()).to.equal(stored[0]._id.toHexString());
|
expect(flagged[0]._id.toHexString()).to.equal(stored[0]._id.toHexString());
|
||||||
expect(flagged[0].nonce).to.not.equal(stored[0].nonce);
|
expect(flagged[0].nonce).to.not.equal(stored[0].nonce);
|
||||||
let gotten = yield mongo.list({ keyid }, DB_TYPE);
|
let gotten = yield mongo.list({ keyid }, DB_TYPE);
|
||||||
expect(gotten).to.deep.equal(flagged);
|
expect(gotten).to.deep.equal(flagged);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should flag no documents no param', function *() {
|
||||||
|
let flagged = yield userId.flagForRemove({});
|
||||||
|
expect(flagged.length).to.equal(0);
|
||||||
|
let gotten = yield mongo.list({ keyid }, DB_TYPE);
|
||||||
|
expect(gotten).to.deep.equal(stored);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("getFlaggedForRemove", () => {
|
||||||
|
it('should find flagged document', function *() {
|
||||||
|
yield userId.batch({ userIds:[uid1, uid2], keyid });
|
||||||
|
let flagged = yield userId.flagForRemove({ keyid });
|
||||||
|
let gotten = yield userId.getFlaggedForRemove({ keyid, nonce:flagged[0].nonce });
|
||||||
|
expect(gotten).to.exist;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("remove", () => {
|
describe("remove", () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user