First working prototype of the keyserver
This commit is contained in:
@@ -2,62 +2,70 @@
|
||||
|
||||
require('co-mocha')(require('mocha')); // monkey patch mocha for generators
|
||||
|
||||
const Mongo = require('../../src/dao/mongo'),
|
||||
expect = require('chai').expect,
|
||||
fs = require('fs');
|
||||
const log = require('npmlog');
|
||||
const Mongo = require('../../src/dao/mongo');
|
||||
const expect = require('chai').expect;
|
||||
|
||||
describe('Mongo Integration Tests', function() {
|
||||
this.timeout(20000);
|
||||
|
||||
const defaultType = 'apple';
|
||||
const secondaryType = 'orange';
|
||||
const DB_TYPE = 'apple';
|
||||
let mongo;
|
||||
|
||||
before(function *() {
|
||||
let credentials;
|
||||
try {
|
||||
credentials = JSON.parse(fs.readFileSync(__dirname + '/../../credentials.json'));
|
||||
} catch(e) {}
|
||||
credentials = require('../../credentials.json');
|
||||
} catch(e) {
|
||||
log.info('mongo-test', 'No credentials.json found ... using environment vars.');
|
||||
}
|
||||
mongo = new Mongo({
|
||||
uri: process.env.MONGO_URI || credentials.mongoUri,
|
||||
user: process.env.MONGO_USER || credentials.mongoUser,
|
||||
password: process.env.MONGO_PASS || credentials.mongoPass,
|
||||
type: defaultType
|
||||
password: process.env.MONGO_PASS || credentials.mongoPass
|
||||
});
|
||||
yield mongo.connect();
|
||||
});
|
||||
|
||||
beforeEach(function *() {
|
||||
yield mongo.clear();
|
||||
yield mongo.clear(secondaryType);
|
||||
yield mongo.clear(DB_TYPE);
|
||||
});
|
||||
|
||||
afterEach(function() {});
|
||||
|
||||
after(function *() {
|
||||
yield mongo.clear();
|
||||
yield mongo.clear(secondaryType);
|
||||
yield mongo.clear(DB_TYPE);
|
||||
yield mongo.disconnect();
|
||||
});
|
||||
|
||||
describe("create", function() {
|
||||
it('should insert a document', function *() {
|
||||
let r = yield mongo.create({ _id:'0' });
|
||||
expect(r.insertedCount).to.equal(1);
|
||||
});
|
||||
|
||||
it('should insert a document with a type', function *() {
|
||||
let r = yield mongo.create({ _id:'0' });
|
||||
expect(r.insertedCount).to.equal(1);
|
||||
r = yield mongo.create({ _id:'0' }, secondaryType);
|
||||
let r = yield mongo.create({ _id:'0' }, DB_TYPE);
|
||||
expect(r.insertedCount).to.equal(1);
|
||||
});
|
||||
|
||||
it('should fail if two with the same ID are inserted', function *() {
|
||||
let r = yield mongo.create({ _id:'0' });
|
||||
let r = yield mongo.create({ _id:'0' }, DB_TYPE);
|
||||
expect(r.insertedCount).to.equal(1);
|
||||
try {
|
||||
r = yield mongo.create({ _id:'0' });
|
||||
r = yield mongo.create({ _id:'0' }, DB_TYPE);
|
||||
} catch(e) {
|
||||
expect(e.message).to.match(/duplicate/);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("batch", function() {
|
||||
it('should insert a document', function *() {
|
||||
let r = yield mongo.batch([{ _id:'0' }, { _id:'1' }], DB_TYPE);
|
||||
expect(r.insertedCount).to.equal(2);
|
||||
});
|
||||
|
||||
it('should fail if docs with the same ID are inserted', function *() {
|
||||
let r = yield mongo.batch([{ _id:'0' }, { _id:'1' }], DB_TYPE);
|
||||
expect(r.insertedCount).to.equal(2);
|
||||
try {
|
||||
r = yield mongo.batch([{ _id:'0' }, { _id:'1' }], DB_TYPE);
|
||||
} catch(e) {
|
||||
expect(e.message).to.match(/duplicate/);
|
||||
}
|
||||
@@ -66,64 +74,35 @@ describe('Mongo Integration Tests', function() {
|
||||
|
||||
describe("update", function() {
|
||||
it('should update a document', function *() {
|
||||
let r = yield mongo.create({ _id:'0' });
|
||||
r = yield mongo.update({ _id:'0' }, { foo:'bar' });
|
||||
let r = yield mongo.create({ _id:'0' }, DB_TYPE);
|
||||
r = yield mongo.update({ _id:'0' }, { foo:'bar' }, DB_TYPE);
|
||||
expect(r.modifiedCount).to.equal(1);
|
||||
r = yield mongo.get({ _id:'0' });
|
||||
expect(r.foo).to.equal('bar');
|
||||
});
|
||||
|
||||
it('should update a document with a type', function *() {
|
||||
let r = yield mongo.create({ _id:'0' }, secondaryType);
|
||||
r = yield mongo.update({ _id:'0' }, { foo:'bar' }, secondaryType);
|
||||
expect(r.modifiedCount).to.equal(1);
|
||||
r = yield mongo.get({ _id:'0' }, secondaryType);
|
||||
r = yield mongo.get({ _id:'0' }, DB_TYPE);
|
||||
expect(r.foo).to.equal('bar');
|
||||
});
|
||||
});
|
||||
|
||||
describe("get", function() {
|
||||
it('should get a document', function *() {
|
||||
let r = yield mongo.create({ _id:'0' });
|
||||
r = yield mongo.get({ _id:'0' });
|
||||
expect(r).to.exist;
|
||||
});
|
||||
|
||||
it('should get a document with a type', function *() {
|
||||
let r = yield mongo.create({ _id:'0' }, secondaryType);
|
||||
r = yield mongo.get({ _id:'0' }, secondaryType);
|
||||
let r = yield mongo.create({ _id:'0' }, DB_TYPE);
|
||||
r = yield mongo.get({ _id:'0' }, DB_TYPE);
|
||||
expect(r).to.exist;
|
||||
});
|
||||
});
|
||||
|
||||
describe("list", function() {
|
||||
it('should list documents', function *() {
|
||||
let r = yield mongo.create({ _id:'0', foo:'bar' });
|
||||
r = yield mongo.create({ _id:'1', foo:'bar' });
|
||||
r = yield mongo.list({ foo:'bar' });
|
||||
expect(r).to.deep.equal([{ _id:'0', foo:'bar' }, { _id:'1', foo:'bar' }]);
|
||||
});
|
||||
|
||||
it('should list documents with a type', function *() {
|
||||
let r = yield mongo.create({ _id:'0', foo:'bar' }, secondaryType);
|
||||
r = yield mongo.create({ _id:'1', foo:'bar' }, secondaryType);
|
||||
r = yield mongo.list({ foo:'bar' }, secondaryType);
|
||||
expect(r).to.deep.equal([{ _id:'0', foo:'bar' }, { _id:'1', foo:'bar' }]);
|
||||
let r = yield mongo.batch([{ _id:'0', foo:'bar' }, { _id:'1', foo:'bar' }], DB_TYPE);
|
||||
r = yield mongo.list({ foo:'bar' }, DB_TYPE);
|
||||
expect(r).to.deep.equal([{ _id:'0', foo:'bar' }, { _id:'1', foo:'bar' }], DB_TYPE);
|
||||
});
|
||||
});
|
||||
|
||||
describe("remove", function() {
|
||||
it('should remove a document', function *() {
|
||||
let r = yield mongo.create({ _id:'0' });
|
||||
r = yield mongo.remove({ _id:'0' });
|
||||
r = yield mongo.get({ _id:'0' });
|
||||
expect(r).to.not.exist;
|
||||
});
|
||||
|
||||
it('should remove a document with a type', function *() {
|
||||
let r = yield mongo.create({ _id:'0' }, secondaryType);
|
||||
r = yield mongo.remove({ _id:'0' }, secondaryType);
|
||||
r = yield mongo.get({ _id:'0' }, secondaryType);
|
||||
let r = yield mongo.create({ _id:'0' }, DB_TYPE);
|
||||
r = yield mongo.remove({ _id:'0' }, DB_TYPE);
|
||||
r = yield mongo.get({ _id:'0' }, DB_TYPE);
|
||||
expect(r).to.not.exist;
|
||||
});
|
||||
});
|
||||
|
||||
69
test/integration/worker-test.js
Normal file
69
test/integration/worker-test.js
Normal file
@@ -0,0 +1,69 @@
|
||||
'use strict';
|
||||
|
||||
require('co-mocha')(require('mocha')); // monkey patch mocha for generators
|
||||
|
||||
const request = require('supertest');
|
||||
const fs = require('fs');
|
||||
|
||||
describe.skip('Koa HTTP Server (worker) Integration Tests', function() {
|
||||
this.timeout(20000);
|
||||
|
||||
let app, pgpKey1;
|
||||
|
||||
before(function *() {
|
||||
pgpKey1 = fs.readFileSync(__dirname + '/../key1.asc', 'utf8');
|
||||
global.testing = true;
|
||||
let init = require('../../src/worker');
|
||||
app = yield init();
|
||||
});
|
||||
|
||||
beforeEach(function () {});
|
||||
|
||||
afterEach(function() {});
|
||||
|
||||
after(function () {});
|
||||
|
||||
describe('REST api', function() {
|
||||
describe('POST /api/v1/key', function() {
|
||||
it('should return 400 for an invalid body', function (done) {
|
||||
request(app.listen())
|
||||
.post('/api/v1/key')
|
||||
.send({ foo: 'bar' })
|
||||
.expect(400)
|
||||
.end(done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('HKP api', function() {
|
||||
describe('GET /pks/add', function() {
|
||||
it('should return 200 for a valid request', function (done) {
|
||||
request(app.listen())
|
||||
.get('/pks/lookup?op=get&search=0xDBC0B3D92B1B86E9')
|
||||
.expect(200)
|
||||
.end(done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /pks/add', function() {
|
||||
it('should return 400 for an invalid body', function (done) {
|
||||
request(app.listen())
|
||||
.post('/pks/add')
|
||||
.type('form')
|
||||
.send('keytext=asdf')
|
||||
.expect(400)
|
||||
.end(done);
|
||||
});
|
||||
|
||||
it('should return 200 for a valid PGP key', function (done) {
|
||||
request(app.listen())
|
||||
.post('/pks/add')
|
||||
.type('form')
|
||||
.send('keytext=' + encodeURIComponent(pgpKey1))
|
||||
.expect(200)
|
||||
.end(done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
32
test/key1.asc
Normal file
32
test/key1.asc
Normal file
@@ -0,0 +1,32 @@
|
||||
-----BEGIN PGP PUBLIC KEY BLOCK-----
|
||||
Version: OpenPGP.js v1.4.1
|
||||
|
||||
xsBNBFZ+SREBCADFXPrLlyXIFHmBcRFEs2nwzID8X3+YmUOvY55+TJbyeggt
|
||||
Ccgd21JiBNuL3yilZ2HmQbjzmJvuLFIKCBSmGeg3LU3QhcoSdHZu+NtiimuJ
|
||||
/CruUFD0JJJn0LdV+4R9nlsoUaNtmTfmgS0ErfcICTmzASgjIwk1bKwFN6qh
|
||||
L+LAVNOU7QL5Jk/6MDUVIU/6sijqGAANAy3aDnFx0x0e0A0QUVdXZU4TUV42
|
||||
wu31rN39ZhgfHwvSEDZsljh2UvoYgS9uFfmO2CxXhoSsp3LKbwP9Os9atlOr
|
||||
7vNOO+nL6GXuBFqNNNycpajiIMBLm6XTeY4ci+EaUX54q7DFUJfamBS3ABEB
|
||||
AAHNM3NhZmV3aXRobWUgdGVzdHVzZXIgPHNhZmV3aXRobWUudGVzdHVzZXJA
|
||||
Z21haWwuY29tPsLAcgQQAQgAJgUCVn5JEgYLCQgHAwIJENvAs9krG4bpBBUI
|
||||
AgoDFgIBAhsDAh4BAAAr6Qf/WWCYCBL2Izau5S+H5zZtCk5Rde51pGw1fsMd
|
||||
gMlZK7knMUSlfjIEx6C/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0xM97+ER
|
||||
FtBVBq+eZC88+gSiwcmxsB8s3rMPQhJ6Q0Y=
|
||||
=/POi
|
||||
-----END PGP PUBLIC KEY BLOCK-----
|
||||
Reference in New Issue
Block a user