Ind.ie is now Small Technology Foundation.
Commit e253c0b0 authored by Frauke's avatar Frauke

Added server test.

parent cf0964e6
......@@ -48,6 +48,9 @@ You will be redirected to the index page.
On the **/index** page you can find the logout button. When you click the button, the indexedDB and cookies will be cleared.
When you're logged in, you can visit **/hello** and you will see the hello text on the screen.
When you're not logged in and you visit **/hello**, you will be redirected to sign in page.
## Changelog
__0.1.0__
......
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