Commit b0e971a1 authored by Frauke's avatar Frauke
Browse files

Added tests for server1.

parent b827a8fb
......@@ -302,6 +302,12 @@
"acorn": "4.0.13"
}
},
"asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=",
"dev": true
},
"atob": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/atob/-/atob-2.0.3.tgz",
......@@ -930,6 +936,15 @@
"source-map": "0.5.7"
}
},
"combined-stream": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.5.tgz",
"integrity": "sha1-k4NwpXtKUd6ix3wV1cX9+JUWQAk=",
"dev": true,
"requires": {
"delayed-stream": "1.0.0"
}
},
"commander": {
"version": "2.11.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.11.0.tgz",
......@@ -1028,6 +1043,12 @@
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
"integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw="
},
"cookiejar": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/cookiejar/-/cookiejar-2.1.1.tgz",
"integrity": "sha1-Qa1XsbVVlR7BcUEqgZQrHoIA00o=",
"dev": true
},
"copy-descriptor": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/copy-descriptor/-/copy-descriptor-0.1.1.tgz",
......@@ -1237,6 +1258,12 @@
"rimraf": "2.2.8"
}
},
"delayed-stream": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=",
"dev": true
},
"depd": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz",
......@@ -2355,6 +2382,23 @@
"integrity": "sha1-C+4AUBiusmDQo6865ljdATbsG5k=",
"dev": true
},
"form-data": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.1.tgz",
"integrity": "sha1-b7lPvXGIUwbXPRXMSX/kzE7NRL8=",
"dev": true,
"requires": {
"asynckit": "0.4.0",
"combined-stream": "1.0.5",
"mime-types": "2.1.17"
}
},
"formidable": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/formidable/-/formidable-1.1.1.tgz",
"integrity": "sha1-lriIb3w8NQi5Mta9cMTTqI818ak=",
"dev": true
},
"forwarded": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz",
......@@ -6030,6 +6074,75 @@
"minimist": "1.2.0"
}
},
"superagent": {
"version": "3.8.2",
"resolved": "https://registry.npmjs.org/superagent/-/superagent-3.8.2.tgz",
"integrity": "sha512-gVH4QfYHcY3P0f/BZzavLreHW3T1v7hG9B+hpMQotGQqurOvhv87GcMCd6LWySmBuf+BDR44TQd0aISjVHLeNQ==",
"dev": true,
"requires": {
"component-emitter": "1.2.1",
"cookiejar": "2.1.1",
"debug": "3.1.0",
"extend": "3.0.1",
"form-data": "2.3.1",
"formidable": "1.1.1",
"methods": "1.1.2",
"mime": "1.4.1",
"qs": "6.5.1",
"readable-stream": "2.3.3"
},
"dependencies": {
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"dev": true,
"requires": {
"ms": "2.0.0"
}
},
"isarray": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
"integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=",
"dev": true
},
"readable-stream": {
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.3.tgz",
"integrity": "sha512-m+qzzcn7KUxEmd1gMbchF+Y2eIUbieUaxkWtptyHywrX0rE8QEYqPC07Vuy4Wm32/xE16NcdBctb8S0Xe/5IeQ==",
"dev": true,
"requires": {
"core-util-is": "1.0.2",
"inherits": "2.0.3",
"isarray": "1.0.0",
"process-nextick-args": "1.0.7",
"safe-buffer": "5.1.1",
"string_decoder": "1.0.3",
"util-deprecate": "1.0.2"
}
},
"string_decoder": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz",
"integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==",
"dev": true,
"requires": {
"safe-buffer": "5.1.1"
}
}
}
},
"supertest": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/supertest/-/supertest-3.0.0.tgz",
"integrity": "sha1-jUu2j9GDDuBwM7HFpamkAhyWUpY=",
"dev": true,
"requires": {
"methods": "1.1.2",
"superagent": "3.8.2"
}
},
"supports-color": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz",
......
......@@ -24,6 +24,7 @@
"gulp-rename": "^1.2.2",
"mocha": "^4.1.0",
"standard": "^10.0.3",
"supertest": "^3.0.0",
"vinyl-source-stream": "^2.0.0"
},
"dependencies": {
......
......@@ -142,3 +142,7 @@ app.get('/nonce', (req, res) => {
console.log('Server 1 started on port 8080')
app.listen(8080)
module.exports = {
app
}
const expect = require('expect')
const request = require('supertest')
const {app} = require('../server')
const fileUtils = require('../utils/fileUtils')
const testSalt = 'TestSalt'
const testSignPublicKey = 'TestSignPublicKey'
const testSignPrivateKey = 'TestSignPrivateKey'
const testEncryptPublicKey = 'testEncryptPublicKey'
const testEncryptPrivateKey = 'TestEncryptPrivateKey'
describe('POST /register', () => {
it('should create a new signpublic, signprivate, encryptpublic and encryptprivatekey file', (done) => {
const keys = {
salt: 'REZARFE',
signPublicKey: 'SDFGHNFGBSDFG',
signPrivateKey: 'DFGSDFHGSDFHSREH',
encryptPublicKey: 'SDFGERUERTZFNYJU',
encryptPrivateKey: 'SDGETYYTKJNBGFDZRETY'
}
request(app)
.post('/register')
.send(keys)
.expect(200)
.end((err, res) => {
if (err) {
return done(err)
}
const readSignPublicKey = fileUtils.readFile('./server/files/signpublickey.json')
const readSignPrivateKey = fileUtils.readFile('./server/files/signprivatekey.json')
const readEncryptPublicKey = fileUtils.readFile('./server/files/encryptpublickey.json')
const readEncryptPrivateKey = fileUtils.readFile('./server/files/encryptprivatekey.json')
Promise.all([readSignPublicKey, readSignPrivateKey, readEncryptPublicKey, readEncryptPrivateKey]).then((result) => {
expect(JSON.parse(result[0]).publicKey).toBe(keys.signPublicKey)
expect(JSON.parse(result[1]).privateKey).toBe(keys.signPrivateKey)
expect(JSON.parse(result[1]).salt).toBe(keys.salt)
expect(JSON.parse(result[2]).publicKey).toBe(keys.encryptPublicKey)
expect(JSON.parse(result[3]).privateKey).toBe(keys.encryptPrivateKey)
expect(JSON.parse(result[3]).salt).toBe(keys.salt)
done()
}).catch((err) => done(err))
})
})
})
describe('GET /encryptpublickey', () => {
beforeEach(() => {
fileUtils.writeFile('encryptpublickey.json', JSON.stringify({publicKey: testEncryptPublicKey}), './server/files').catch((err) => console.log(err))
})
it('should return the encryptpublickey value', (done) => {
request(app)
.get('/encryptpublickey')
.expect(200)
.expect((res) => {
expect(res.body.publicKey).toBe(testEncryptPublicKey)
})
.end(done)
})
})
describe('GET /encryptprivatekey', () => {
beforeEach(() => {
fileUtils.writeFile('encryptprivatekey.json', JSON.stringify({publicKey: testEncryptPrivateKey}), './server/files').catch((err) => console.log(err))
})
it('should return the encryptprivatekey value', (done) => {
request(app)
.get('/encryptprivatekey')
.expect(200)
.expect((res) => {
expect(res.body.publicKey).toBe(testEncryptPrivateKey)
})
.end(done)
})
})
describe('GET /signpublickey', () => {
beforeEach(() => {
fileUtils.writeFile('signpublickey.json', JSON.stringify({publicKey: testSignPublicKey}), './server/files').catch((err) => console.log(err))
})
it('should return the signpublickey value', (done) => {
request(app)
.get('/signpublickey')
.expect(200)
.expect((res) => {
expect(res.body.publicKey).toBe(testSignPublicKey)
})
.end(done)
})
})
describe('GET /signprivatekey', () => {
beforeEach(() => {
fileUtils.writeFile('signprivatekey.json', JSON.stringify({publicKey: testSignPrivateKey}), './server/files').catch((err) => console.log(err))
})
it('should return the signprivatekey value', (done) => {
request(app)
.get('/signprivatekey')
.expect(200)
.expect((res) => {
expect(res.body.publicKey).toBe(testSignPrivateKey)
})
.end(done)
})
})
describe('GET /nonce', () => {
it('should return a nonce', (done) => {
request(app)
.get('/nonce')
.expect(200)
.expect((res) => {
expect(res.body).toBeBuffer()
})
.end(done)
})
})
expect.extend({
toBeBuffer (received, argument) {
if (Buffer.isBuffer(received)) {
return {
message: () =>
`expected ${received} to be a Buffer`,
pass: true
}
} else {
return {
message: () => `${received} must be Buffer`,
pass: false
}
}
}
})
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment