2016-06-01 10:28:37 +00:00
|
|
|
'use strict';
|
|
|
|
|
2017-08-17 11:28:08 +00:00
|
|
|
const log = require('npmlog');
|
2016-06-01 13:20:49 +00:00
|
|
|
const config = require('config');
|
2016-06-01 10:28:37 +00:00
|
|
|
const nodemailer = require('nodemailer');
|
|
|
|
const Email = require('../../src/email/email');
|
|
|
|
const Mongo = require('../../src/dao/mongo');
|
2016-06-09 15:07:51 +00:00
|
|
|
const PGP = require('../../src/service/pgp');
|
2016-06-01 10:28:37 +00:00
|
|
|
const PublicKey = require('../../src/service/public-key');
|
|
|
|
|
|
|
|
describe('Public Key Integration Tests', function() {
|
|
|
|
this.timeout(20000);
|
|
|
|
|
2017-08-16 09:55:32 +00:00
|
|
|
let sandbox;
|
2017-08-15 08:03:06 +00:00
|
|
|
let publicKey;
|
|
|
|
let email;
|
|
|
|
let mongo;
|
|
|
|
let pgp;
|
|
|
|
let sendEmailStub;
|
|
|
|
let publicKeyArmored;
|
|
|
|
let publicKeyArmored2;
|
|
|
|
let mailsSent;
|
2016-06-01 10:28:37 +00:00
|
|
|
|
2016-06-09 15:07:51 +00:00
|
|
|
const DB_TYPE = 'publickey';
|
|
|
|
const primaryEmail = 'test1@example.com';
|
2016-06-14 11:13:34 +00:00
|
|
|
const primaryEmail2 = 'test2@example.com';
|
2017-08-15 08:03:06 +00:00
|
|
|
const origin = {host: 'localhost', protocol: 'http'};
|
2016-06-01 10:28:37 +00:00
|
|
|
|
2017-08-17 09:44:26 +00:00
|
|
|
before(async () => {
|
2017-08-15 08:03:06 +00:00
|
|
|
publicKeyArmored = require('fs').readFileSync(`${__dirname}/../key3.asc`, 'utf8');
|
|
|
|
publicKeyArmored2 = require('fs').readFileSync(`${__dirname}/../key4.asc`, 'utf8');
|
2017-08-17 11:28:08 +00:00
|
|
|
sinon.stub(log, 'info');
|
2016-06-08 12:01:30 +00:00
|
|
|
mongo = new Mongo();
|
2017-08-16 09:55:32 +00:00
|
|
|
await mongo.init(config.mongo);
|
2016-06-01 10:28:37 +00:00
|
|
|
});
|
|
|
|
|
2017-08-17 09:44:26 +00:00
|
|
|
beforeEach(async () => {
|
2017-08-16 09:55:32 +00:00
|
|
|
sandbox = sinon.sandbox.create();
|
|
|
|
|
|
|
|
await mongo.clear(DB_TYPE);
|
2016-06-14 11:13:34 +00:00
|
|
|
mailsSent = [];
|
2017-08-15 08:03:06 +00:00
|
|
|
sendEmailStub = sinon.stub().returns(Promise.resolve({response: '250'}));
|
2016-06-01 10:28:37 +00:00
|
|
|
sendEmailStub.withArgs(sinon.match(recipient => {
|
2017-08-15 08:03:06 +00:00
|
|
|
mailsSent[mailsSent.length] = {to: recipient.to.address};
|
2016-06-14 11:13:34 +00:00
|
|
|
return true;
|
2016-06-01 10:28:37 +00:00
|
|
|
}), sinon.match(params => {
|
2016-06-14 11:13:34 +00:00
|
|
|
mailsSent[mailsSent.length - 1].params = params;
|
|
|
|
expect(params.nonce).to.exist;
|
|
|
|
expect(params.keyId).to.exist;
|
|
|
|
return true;
|
2016-06-01 10:28:37 +00:00
|
|
|
}));
|
2017-08-16 09:55:32 +00:00
|
|
|
sandbox.stub(nodemailer, 'createTransport').returns({
|
2017-08-15 08:03:06 +00:00
|
|
|
templateSender: () => sendEmailStub
|
2016-06-01 10:28:37 +00:00
|
|
|
});
|
|
|
|
email = new Email(nodemailer);
|
|
|
|
email.init({
|
|
|
|
host: 'localhost',
|
2017-08-15 08:03:06 +00:00
|
|
|
auth: {user: 'user', pass: 'pass'},
|
|
|
|
sender: {name: 'Foo Bar', email: 'foo@bar.com'}
|
2016-06-01 10:28:37 +00:00
|
|
|
});
|
2016-06-09 15:07:51 +00:00
|
|
|
pgp = new PGP();
|
|
|
|
publicKey = new PublicKey(pgp, mongo, email);
|
2016-06-01 10:28:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2017-08-16 09:55:32 +00:00
|
|
|
sandbox.restore();
|
2016-06-01 10:28:37 +00:00
|
|
|
});
|
|
|
|
|
2017-08-17 09:44:26 +00:00
|
|
|
after(async () => {
|
2017-08-16 09:55:32 +00:00
|
|
|
await mongo.clear(DB_TYPE);
|
|
|
|
await mongo.disconnect();
|
2017-08-17 11:28:08 +00:00
|
|
|
log.info.restore();
|
2016-06-01 10:28:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('put', () => {
|
2017-08-17 09:44:26 +00:00
|
|
|
it('should persist key and send verification email with primaryEmail', async () => {
|
2017-08-16 09:55:32 +00:00
|
|
|
await publicKey.put({publicKeyArmored, primaryEmail, origin});
|
2016-06-14 11:13:34 +00:00
|
|
|
expect(mailsSent.length).to.equal(1);
|
|
|
|
expect(mailsSent[0].to).to.equal(primaryEmail);
|
|
|
|
expect(mailsSent[0].params.keyId).to.exist;
|
|
|
|
expect(mailsSent[0].params.nonce).to.exist;
|
2016-06-01 10:28:37 +00:00
|
|
|
});
|
2017-08-17 09:44:26 +00:00
|
|
|
it('should persist key and send verification email without primaryEmail', async () => {
|
2017-08-16 09:55:32 +00:00
|
|
|
await publicKey.put({publicKeyArmored, origin});
|
2016-06-14 11:13:34 +00:00
|
|
|
expect(mailsSent.length).to.equal(4);
|
2016-06-01 13:20:49 +00:00
|
|
|
});
|
2016-06-01 10:28:37 +00:00
|
|
|
|
2017-08-17 09:44:26 +00:00
|
|
|
it('should work twice if not yet verified', async () => {
|
2017-08-16 09:55:32 +00:00
|
|
|
await publicKey.put({publicKeyArmored, primaryEmail, origin});
|
2016-06-14 11:13:34 +00:00
|
|
|
expect(mailsSent.length).to.equal(1);
|
2017-08-16 09:55:32 +00:00
|
|
|
await publicKey.put({publicKeyArmored, primaryEmail, origin});
|
2016-06-14 11:13:34 +00:00
|
|
|
expect(mailsSent.length).to.equal(2);
|
2016-06-01 10:28:37 +00:00
|
|
|
});
|
|
|
|
|
2017-08-17 09:44:26 +00:00
|
|
|
it('should throw 304 if key already exists', async () => {
|
2017-08-16 09:55:32 +00:00
|
|
|
await publicKey.put({publicKeyArmored, primaryEmail, origin});
|
|
|
|
await publicKey.verify(mailsSent[0].params);
|
2016-06-01 10:28:37 +00:00
|
|
|
try {
|
2017-08-16 09:55:32 +00:00
|
|
|
await publicKey.put({publicKeyArmored, primaryEmail, origin});
|
2016-06-01 10:28:37 +00:00
|
|
|
expect(false).to.be.true;
|
2017-08-15 08:03:06 +00:00
|
|
|
} catch (e) {
|
2016-06-01 10:28:37 +00:00
|
|
|
expect(e.status).to.equal(304);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-06-09 15:07:51 +00:00
|
|
|
describe('verify', () => {
|
2017-08-17 09:44:26 +00:00
|
|
|
it('should update the document', async () => {
|
2017-08-16 09:55:32 +00:00
|
|
|
await publicKey.put({publicKeyArmored, primaryEmail, origin});
|
2017-08-15 08:03:06 +00:00
|
|
|
const emailParams = mailsSent[0].params;
|
2017-08-16 09:55:32 +00:00
|
|
|
await publicKey.verify(emailParams);
|
|
|
|
const gotten = await mongo.get({keyId: emailParams.keyId}, DB_TYPE);
|
2016-06-09 15:07:51 +00:00
|
|
|
expect(gotten.userIds[0].verified).to.be.true;
|
|
|
|
expect(gotten.userIds[0].nonce).to.be.null;
|
|
|
|
expect(gotten.userIds[1].verified).to.be.false;
|
|
|
|
expect(gotten.userIds[1].nonce).to.exist;
|
|
|
|
});
|
|
|
|
|
2017-08-17 09:44:26 +00:00
|
|
|
it('should not find the document', async () => {
|
2017-08-16 09:55:32 +00:00
|
|
|
await publicKey.put({publicKeyArmored, primaryEmail, origin});
|
2017-08-15 08:03:06 +00:00
|
|
|
const emailParams = mailsSent[0].params;
|
2016-06-09 15:07:51 +00:00
|
|
|
try {
|
2017-08-16 09:55:32 +00:00
|
|
|
await publicKey.verify({keyId: emailParams.keyId, nonce: 'fake_nonce'});
|
2016-06-09 15:07:51 +00:00
|
|
|
expect(true).to.be.false;
|
2017-08-15 08:03:06 +00:00
|
|
|
} catch (e) {
|
2016-06-09 15:07:51 +00:00
|
|
|
expect(e.status).to.equal(404);
|
|
|
|
}
|
2017-08-16 09:55:32 +00:00
|
|
|
const gotten = await mongo.get({keyId: emailParams.keyId}, DB_TYPE);
|
2016-06-09 15:07:51 +00:00
|
|
|
expect(gotten.userIds[0].verified).to.be.false;
|
|
|
|
expect(gotten.userIds[0].nonce).to.equal(emailParams.nonce);
|
|
|
|
expect(gotten.userIds[1].verified).to.be.false;
|
|
|
|
expect(gotten.userIds[1].nonce).to.exist;
|
|
|
|
});
|
2016-06-14 11:13:34 +00:00
|
|
|
|
2017-08-17 09:44:26 +00:00
|
|
|
it('should not verify a second key for already verified user id of another key', async () => {
|
2017-08-16 09:55:32 +00:00
|
|
|
await publicKey.put({publicKeyArmored, primaryEmail: primaryEmail2, origin});
|
2016-06-14 11:13:34 +00:00
|
|
|
expect(mailsSent.length).to.equal(1);
|
2017-08-16 09:55:32 +00:00
|
|
|
await publicKey.put({publicKeyArmored: publicKeyArmored2, primaryEmail: primaryEmail2, origin});
|
2016-06-14 11:13:34 +00:00
|
|
|
expect(mailsSent.length).to.equal(2);
|
2017-08-16 09:55:32 +00:00
|
|
|
await publicKey.verify(mailsSent[1].params);
|
2016-06-14 11:13:34 +00:00
|
|
|
|
|
|
|
try {
|
2017-08-16 09:55:32 +00:00
|
|
|
await publicKey.verify(mailsSent[0].params);
|
2016-06-14 11:13:34 +00:00
|
|
|
expect(true).to.be.false;
|
2017-08-15 08:03:06 +00:00
|
|
|
} catch (e) {
|
2016-06-14 11:13:34 +00:00
|
|
|
expect(e.status).to.equal(304);
|
|
|
|
}
|
2017-08-16 09:55:32 +00:00
|
|
|
const gotten = await mongo.get({keyId: mailsSent[0].params.keyId}, DB_TYPE);
|
2016-06-14 11:13:34 +00:00
|
|
|
expect(gotten.userIds[1].email).to.equal(primaryEmail2);
|
|
|
|
expect(gotten.userIds[1].verified).to.be.false;
|
|
|
|
expect(gotten.userIds[1].nonce).to.equal(mailsSent[0].params.nonce);
|
|
|
|
});
|
2016-06-17 17:56:33 +00:00
|
|
|
|
2017-08-17 09:44:26 +00:00
|
|
|
it('should be able to verify multiple user ids', async () => {
|
2017-08-16 09:55:32 +00:00
|
|
|
await publicKey.put({publicKeyArmored, origin});
|
2016-06-17 17:56:33 +00:00
|
|
|
expect(mailsSent.length).to.equal(4);
|
2017-08-16 09:55:32 +00:00
|
|
|
await publicKey.verify(mailsSent[0].params);
|
|
|
|
await publicKey.verify(mailsSent[1].params);
|
|
|
|
await publicKey.verify(mailsSent[2].params);
|
|
|
|
await publicKey.verify(mailsSent[3].params);
|
|
|
|
const gotten = await mongo.get({keyId: mailsSent[0].params.keyId}, DB_TYPE);
|
2016-06-17 17:56:33 +00:00
|
|
|
expect(gotten.userIds[0].verified).to.be.true;
|
|
|
|
expect(gotten.userIds[1].verified).to.be.true;
|
|
|
|
expect(gotten.userIds[2].verified).to.be.true;
|
|
|
|
expect(gotten.userIds[3].verified).to.be.true;
|
|
|
|
});
|
2016-06-09 15:07:51 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('getVerified', () => {
|
|
|
|
let key;
|
|
|
|
|
|
|
|
describe('should find a verified key', () => {
|
2017-08-17 09:44:26 +00:00
|
|
|
beforeEach(async () => {
|
2016-06-09 15:07:51 +00:00
|
|
|
key = pgp.parseKey(publicKeyArmored);
|
2017-08-16 09:55:32 +00:00
|
|
|
await publicKey.put({publicKeyArmored, primaryEmail, origin});
|
|
|
|
await publicKey.verify(mailsSent[0].params);
|
2016-06-09 15:07:51 +00:00
|
|
|
});
|
|
|
|
|
2017-08-17 09:44:26 +00:00
|
|
|
it('by fingerprint', async () => {
|
2017-08-16 09:55:32 +00:00
|
|
|
const verified = await publicKey.getVerified({fingerprint: key.fingerprint});
|
2016-06-09 15:07:51 +00:00
|
|
|
expect(verified).to.exist;
|
|
|
|
});
|
|
|
|
|
2017-08-17 09:44:26 +00:00
|
|
|
it('by all userIds', async () => {
|
2017-08-16 09:55:32 +00:00
|
|
|
const verified = await publicKey.getVerified({userIds: key.userIds});
|
2016-06-09 15:07:51 +00:00
|
|
|
expect(verified).to.exist;
|
|
|
|
});
|
|
|
|
|
2017-08-17 09:44:26 +00:00
|
|
|
it('by verified userId', async () => {
|
2017-08-16 09:55:32 +00:00
|
|
|
const verified = await publicKey.getVerified({userIds: [key.userIds[0]]});
|
2016-06-09 15:07:51 +00:00
|
|
|
expect(verified).to.exist;
|
|
|
|
});
|
|
|
|
|
2017-08-17 09:44:26 +00:00
|
|
|
it('by unverified userId', async () => {
|
2017-08-16 09:55:32 +00:00
|
|
|
const verified = await publicKey.getVerified({userIds: [key.userIds[1]]});
|
2016-06-09 15:07:51 +00:00
|
|
|
expect(verified).to.not.exist;
|
|
|
|
});
|
|
|
|
|
2017-08-17 09:44:26 +00:00
|
|
|
it('by keyId', async () => {
|
2017-08-16 09:55:32 +00:00
|
|
|
const verified = await publicKey.getVerified({keyId: key.keyId});
|
2016-06-09 15:07:51 +00:00
|
|
|
expect(verified).to.exist;
|
|
|
|
});
|
|
|
|
|
2017-08-17 09:44:26 +00:00
|
|
|
it('by all params', async () => {
|
2017-08-16 09:55:32 +00:00
|
|
|
const verified = await publicKey.getVerified(key);
|
2016-06-09 15:07:51 +00:00
|
|
|
expect(verified).to.exist;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('should not find an unverified key', () => {
|
2017-08-17 09:44:26 +00:00
|
|
|
beforeEach(async () => {
|
2016-06-09 15:07:51 +00:00
|
|
|
key = pgp.parseKey(publicKeyArmored);
|
|
|
|
key.userIds[0].verified = false;
|
2017-08-16 09:55:32 +00:00
|
|
|
await mongo.create(key, DB_TYPE);
|
2016-06-09 15:07:51 +00:00
|
|
|
});
|
|
|
|
|
2017-08-17 09:44:26 +00:00
|
|
|
it('by fingerprint', async () => {
|
2017-08-16 09:55:32 +00:00
|
|
|
const verified = await publicKey.getVerified({fingerprint: key.fingerprint});
|
2016-06-09 15:07:51 +00:00
|
|
|
expect(verified).to.not.exist;
|
|
|
|
});
|
|
|
|
|
2017-08-17 09:44:26 +00:00
|
|
|
it('by userIds', async () => {
|
2017-08-16 09:55:32 +00:00
|
|
|
const verified = await publicKey.getVerified({userIds: key.userIds});
|
2016-06-09 15:07:51 +00:00
|
|
|
expect(verified).to.not.exist;
|
|
|
|
});
|
|
|
|
|
2017-08-17 09:44:26 +00:00
|
|
|
it('by keyId', async () => {
|
2017-08-16 09:55:32 +00:00
|
|
|
const verified = await publicKey.getVerified({keyId: key.keyId});
|
2016-06-09 15:07:51 +00:00
|
|
|
expect(verified).to.not.exist;
|
|
|
|
});
|
|
|
|
|
2017-08-17 09:44:26 +00:00
|
|
|
it('by all params', async () => {
|
2017-08-16 09:55:32 +00:00
|
|
|
const verified = await publicKey.getVerified(key);
|
2016-06-09 15:07:51 +00:00
|
|
|
expect(verified).to.not.exist;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-06-01 10:28:37 +00:00
|
|
|
describe('get', () => {
|
2016-06-14 11:13:34 +00:00
|
|
|
let emailParams;
|
|
|
|
|
2017-08-17 09:44:26 +00:00
|
|
|
beforeEach(async () => {
|
2017-08-16 09:55:32 +00:00
|
|
|
await publicKey.put({publicKeyArmored, primaryEmail, origin});
|
2016-06-14 11:13:34 +00:00
|
|
|
emailParams = mailsSent[0].params;
|
2016-06-01 10:28:37 +00:00
|
|
|
});
|
|
|
|
|
2017-08-17 09:44:26 +00:00
|
|
|
it('should return verified key by key id', async () => {
|
2017-08-16 09:55:32 +00:00
|
|
|
await publicKey.verify(emailParams);
|
|
|
|
const key = await publicKey.get({keyId: emailParams.keyId});
|
2016-06-09 15:07:51 +00:00
|
|
|
expect(key.publicKeyArmored).to.exist;
|
|
|
|
});
|
|
|
|
|
2017-08-17 09:44:26 +00:00
|
|
|
it('should return verified key by key id (uppercase)', async () => {
|
2017-08-16 09:55:32 +00:00
|
|
|
await publicKey.verify(emailParams);
|
|
|
|
const key = await publicKey.get({keyId: emailParams.keyId.toUpperCase()});
|
2016-06-09 15:07:51 +00:00
|
|
|
expect(key.publicKeyArmored).to.exist;
|
|
|
|
});
|
|
|
|
|
2017-08-17 09:44:26 +00:00
|
|
|
it('should return verified key by fingerprint', async () => {
|
2017-08-16 09:55:32 +00:00
|
|
|
await publicKey.verify(emailParams);
|
2017-08-15 08:03:06 +00:00
|
|
|
const fingerprint = pgp.parseKey(publicKeyArmored).fingerprint;
|
2017-08-16 09:55:32 +00:00
|
|
|
const key = await publicKey.get({fingerprint});
|
2016-06-09 15:07:51 +00:00
|
|
|
expect(key.publicKeyArmored).to.exist;
|
|
|
|
});
|
|
|
|
|
2017-08-17 09:44:26 +00:00
|
|
|
it('should return verified key by fingerprint (uppercase)', async () => {
|
2017-08-16 09:55:32 +00:00
|
|
|
await publicKey.verify(emailParams);
|
2017-08-15 08:03:06 +00:00
|
|
|
const fingerprint = pgp.parseKey(publicKeyArmored).fingerprint.toUpperCase();
|
2017-08-16 09:55:32 +00:00
|
|
|
const key = await publicKey.get({fingerprint});
|
2016-06-09 15:07:51 +00:00
|
|
|
expect(key.publicKeyArmored).to.exist;
|
2016-06-01 10:28:37 +00:00
|
|
|
});
|
|
|
|
|
2017-08-17 09:44:26 +00:00
|
|
|
it('should return verified key by email address', async () => {
|
2017-08-16 09:55:32 +00:00
|
|
|
await publicKey.verify(emailParams);
|
|
|
|
const key = await publicKey.get({email: primaryEmail});
|
2016-06-09 15:07:51 +00:00
|
|
|
expect(key.publicKeyArmored).to.exist;
|
|
|
|
});
|
|
|
|
|
2017-08-17 09:44:26 +00:00
|
|
|
it('should return verified key by email address (uppercase)', async () => {
|
2017-08-16 09:55:32 +00:00
|
|
|
await publicKey.verify(emailParams);
|
|
|
|
const key = await publicKey.get({email: primaryEmail.toUpperCase()});
|
2016-06-09 15:07:51 +00:00
|
|
|
expect(key.publicKeyArmored).to.exist;
|
2016-06-01 10:28:37 +00:00
|
|
|
});
|
|
|
|
|
2017-08-17 09:44:26 +00:00
|
|
|
it('should throw 404 for unverified key', async () => {
|
2016-06-01 10:28:37 +00:00
|
|
|
try {
|
2017-08-16 09:55:32 +00:00
|
|
|
await publicKey.get({keyId: emailParams.keyId});
|
2016-06-01 10:28:37 +00:00
|
|
|
expect(false).to.be.true;
|
2017-08-15 08:03:06 +00:00
|
|
|
} catch (e) {
|
2016-06-01 10:28:37 +00:00
|
|
|
expect(e.status).to.equal(404);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('requestRemove', () => {
|
2016-06-09 15:07:51 +00:00
|
|
|
let keyId;
|
2016-06-01 10:28:37 +00:00
|
|
|
|
2017-08-17 09:44:26 +00:00
|
|
|
beforeEach(async () => {
|
2017-08-16 09:55:32 +00:00
|
|
|
await publicKey.put({publicKeyArmored, primaryEmail, origin});
|
2016-06-14 11:13:34 +00:00
|
|
|
keyId = mailsSent[0].params.keyId;
|
2016-06-01 10:28:37 +00:00
|
|
|
});
|
|
|
|
|
2017-08-17 09:44:26 +00:00
|
|
|
it('should work for verified key', async () => {
|
2017-08-16 09:55:32 +00:00
|
|
|
await publicKey.verify(mailsSent[0].params);
|
|
|
|
await publicKey.requestRemove({keyId, origin});
|
2016-06-14 11:13:34 +00:00
|
|
|
expect(mailsSent.length).to.equal(5);
|
2016-06-01 10:28:37 +00:00
|
|
|
});
|
|
|
|
|
2017-08-17 09:44:26 +00:00
|
|
|
it('should work for unverified key', async () => {
|
2017-08-16 09:55:32 +00:00
|
|
|
await publicKey.requestRemove({keyId, origin});
|
2016-06-14 11:13:34 +00:00
|
|
|
expect(mailsSent.length).to.equal(5);
|
2016-06-01 10:28:37 +00:00
|
|
|
});
|
|
|
|
|
2017-08-17 09:44:26 +00:00
|
|
|
it('should work by email address', async () => {
|
2017-08-16 09:55:32 +00:00
|
|
|
await publicKey.requestRemove({email: primaryEmail, origin});
|
2016-06-14 11:13:34 +00:00
|
|
|
expect(mailsSent.length).to.equal(2);
|
2016-06-01 10:28:37 +00:00
|
|
|
});
|
|
|
|
|
2017-08-17 09:44:26 +00:00
|
|
|
it('should throw 404 for no key', async () => {
|
2017-08-16 09:55:32 +00:00
|
|
|
await mongo.remove({keyId}, DB_TYPE);
|
2016-06-01 10:28:37 +00:00
|
|
|
try {
|
2017-08-16 09:55:32 +00:00
|
|
|
await publicKey.requestRemove({keyId, origin});
|
2016-06-01 10:28:37 +00:00
|
|
|
expect(false).to.be.true;
|
2017-08-15 08:03:06 +00:00
|
|
|
} catch (e) {
|
2016-06-01 10:28:37 +00:00
|
|
|
expect(e.status).to.equal(404);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('verifyRemove', () => {
|
2016-06-09 15:07:51 +00:00
|
|
|
let keyId;
|
2016-06-01 10:28:37 +00:00
|
|
|
|
2017-08-17 09:44:26 +00:00
|
|
|
beforeEach(async () => {
|
2017-08-16 09:55:32 +00:00
|
|
|
await publicKey.put({publicKeyArmored, primaryEmail, origin});
|
2016-06-14 11:13:34 +00:00
|
|
|
keyId = mailsSent[0].params.keyId;
|
2017-08-16 09:55:32 +00:00
|
|
|
await publicKey.requestRemove({keyId, origin});
|
2016-06-01 10:28:37 +00:00
|
|
|
});
|
|
|
|
|
2017-08-17 09:44:26 +00:00
|
|
|
it('should remove key', async () => {
|
2017-08-16 09:55:32 +00:00
|
|
|
await publicKey.verifyRemove(mailsSent[1].params);
|
|
|
|
const key = await mongo.get({keyId}, DB_TYPE);
|
2016-06-01 10:28:37 +00:00
|
|
|
expect(key).to.not.exist;
|
|
|
|
});
|
|
|
|
|
2017-08-17 09:44:26 +00:00
|
|
|
it('should throw 404 for no key', async () => {
|
2017-08-16 09:55:32 +00:00
|
|
|
await mongo.remove({keyId}, DB_TYPE);
|
2016-06-01 10:28:37 +00:00
|
|
|
try {
|
2017-08-16 09:55:32 +00:00
|
|
|
await publicKey.verifyRemove(mailsSent[1].params);
|
2016-06-01 10:28:37 +00:00
|
|
|
expect(false).to.be.true;
|
2017-08-15 08:03:06 +00:00
|
|
|
} catch (e) {
|
2016-06-01 10:28:37 +00:00
|
|
|
expect(e.status).to.equal(404);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2017-08-15 08:03:06 +00:00
|
|
|
});
|