2016-05-27 17:57:48 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
require('co-mocha')(require('mocha')); // monkey patch mocha for generators
|
|
|
|
|
|
|
|
const request = require('supertest');
|
|
|
|
const fs = require('fs');
|
|
|
|
|
2016-05-28 13:17:46 +00:00
|
|
|
describe.skip('Koa App (HTTP Server) Integration Tests', function() {
|
2016-05-27 17:57:48 +00:00
|
|
|
this.timeout(20000);
|
|
|
|
|
|
|
|
let app, pgpKey1;
|
|
|
|
|
|
|
|
before(function *() {
|
|
|
|
pgpKey1 = fs.readFileSync(__dirname + '/../key1.asc', 'utf8');
|
|
|
|
global.testing = true;
|
2016-05-28 13:17:46 +00:00
|
|
|
let init = require('../../src/app');
|
2016-05-27 17:57:48 +00:00
|
|
|
app = yield init();
|
|
|
|
});
|
|
|
|
|
2016-05-31 11:52:18 +00:00
|
|
|
describe('REST api', () => {
|
|
|
|
describe('POST /api/v1/key', () => {
|
|
|
|
it('should return 400 for an invalid body', done => {
|
2016-05-27 17:57:48 +00:00
|
|
|
request(app.listen())
|
|
|
|
.post('/api/v1/key')
|
|
|
|
.send({ foo: 'bar' })
|
|
|
|
.expect(400)
|
|
|
|
.end(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-05-31 11:52:18 +00:00
|
|
|
describe('HKP api', () => {
|
|
|
|
describe('GET /pks/add', () => {
|
|
|
|
it.skip('should return 200 for a valid request', done => {
|
2016-05-27 17:57:48 +00:00
|
|
|
request(app.listen())
|
|
|
|
.get('/pks/lookup?op=get&search=0xDBC0B3D92B1B86E9')
|
|
|
|
.expect(200)
|
|
|
|
.end(done);
|
|
|
|
});
|
2016-05-29 16:59:14 +00:00
|
|
|
|
2016-05-31 11:52:18 +00:00
|
|
|
it('should return 404 if not found', done => {
|
2016-05-29 16:59:14 +00:00
|
|
|
request(app.listen())
|
|
|
|
.get('/pks/lookup?op=get&search=0xDBC0B3D92A1B86E9')
|
|
|
|
.expect(404)
|
|
|
|
.end(done);
|
|
|
|
});
|
2016-05-27 17:57:48 +00:00
|
|
|
});
|
|
|
|
|
2016-05-31 11:52:18 +00:00
|
|
|
describe('POST /pks/add', () => {
|
|
|
|
it('should return 400 for an invalid body', done => {
|
2016-05-27 17:57:48 +00:00
|
|
|
request(app.listen())
|
|
|
|
.post('/pks/add')
|
|
|
|
.type('form')
|
|
|
|
.send('keytext=asdf')
|
|
|
|
.expect(400)
|
|
|
|
.end(done);
|
|
|
|
});
|
|
|
|
|
2016-05-31 11:52:18 +00:00
|
|
|
it('should return 201 for a valid PGP key', done => {
|
2016-05-27 17:57:48 +00:00
|
|
|
request(app.listen())
|
|
|
|
.post('/pks/add')
|
|
|
|
.type('form')
|
|
|
|
.send('keytext=' + encodeURIComponent(pgpKey1))
|
2016-05-29 16:59:14 +00:00
|
|
|
.expect(201)
|
2016-05-27 17:57:48 +00:00
|
|
|
.end(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|