Verified Commit fcb74c12 authored by Sebastiaan Deckers's avatar Sebastiaan Deckers 馃悜

fix: store cert/key/ca data as binary in MongoDB

parent e86751dc
......@@ -71,8 +71,8 @@ async function issueCertificate (fastify, domain) {
)
const [key, cert] = await Promise.all([
readFile(join(directory, 'key.pem'), 'utf8'),
readFile(join(directory, 'cert.pem'), 'utf8')
readFile(join(directory, 'key.pem')),
readFile(join(directory, 'cert.pem'))
])
await promisify(rimraf)(directory)
......
......@@ -40,10 +40,11 @@ module.exports = async (configuration) => {
fastify.addHook('preHandler', require('./hooks/normaliseDomain'))
fastify.register(require('./plugins/jwt'), configuration.jwt)
fastify.register(require('./plugins/auth0'), configuration.auth0)
fastify.register(
require('fastify-mongodb'),
{ ...configuration.mongodb, forceClose: true }
)
fastify.register(require('fastify-mongodb'), {
...configuration.mongodb,
forceClose: true,
promoteBuffers: true
})
fastify.register(require('./plugins/pubnub'), configuration.pubnub)
fastify.register(require('./plugins/acme'), configuration.acme)
fastify.use(require('cors')())
......
......@@ -9,10 +9,10 @@ module.exports = (configuration) => {
test('Connecting database', async (t) => {
if (mongo.db === undefined) {
const { url, database } = configuration.mongodb
const client = await MongoClient.connect(
url,
{ useNewUrlParser: true }
)
const client = await MongoClient.connect(url, {
useNewUrlParser: true,
promoteBuffers: true
})
mongo.db = client.db(database)
const halt = async () => {
await client.close()
......
......@@ -19,14 +19,21 @@ const fixture = {
modified: new Date(),
domain: 'example.com',
san: ['www.example.com', 'example.net'],
ca: ['Intermediate CA', 'Root CA'],
key: 'Private key',
cert: 'Public certificate'
ca: [
Buffer.from('Intermediate CA'),
Buffer.from('Root CA')
],
key: Buffer.from('Private key'),
cert: Buffer.from('Public certificate')
}
const expected = {
...fixture,
modified: fixture.modified.toISOString()
modified: fixture.modified.toISOString(),
domain: fixture.domain,
san: fixture.san,
ca: fixture.ca.map((buffer) => buffer.toString()),
key: fixture.key.toString(),
cert: fixture.cert.toString()
}
test('Setup database fixtures', async (t) => {
......
......@@ -154,8 +154,8 @@ test('Deploy a site', async (t) => {
t.is(actualCertificate.domain, fixture.domain)
t.deepEqual(actualCertificate.san, [])
t.deepEqual(actualCertificate.ca, [])
t.is(actualCertificate.key, 'private key')
t.is(actualCertificate.cert, 'public certificate chain')
t.deepEqual(actualCertificate.key, Buffer.from('private key'))
t.deepEqual(actualCertificate.cert, Buffer.from('public certificate chain'))
t.not(Number.isNaN(new Date(actualCertificate.modified).getTime()))
})
......
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