Skip to content

Commit 3bdefee

Browse files
committed
added another test
1 parent 1e11fcb commit 3bdefee

2 files changed

Lines changed: 30 additions & 10 deletions

File tree

src/acme/certUtils.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
const toIssuerCert = (links) => {
2-
const match = /.*<(.*)>;rel="up".*/.exec(links)
3-
return match[1]
4-
}
1+
const toIssuerCert = links =>
2+
/.*<(.*)>;rel="up".*/.exec(links)[1]
53

6-
const toStandardB64 = (str) => {
4+
const toStandardB64 = str => {
75
var b64 = str.replace(/-/g, '+').replace(/_/g, '/').replace(/=/g, '')
86
switch (b64.length % 4) {
97
case 2:
@@ -16,10 +14,7 @@ const toStandardB64 = (str) => {
1614
return b64
1715
}
1816

19-
const toPEM = (cert) => {
20-
cert = toStandardB64(cert.toString('base64'))
21-
cert = cert.match(/.{1,64}/g).join('\n')
22-
return `-----BEGIN CERTIFICATE-----\n${cert}\n-----END CERTIFICATE-----\n`
23-
}
17+
const toPEM = cert =>
18+
`-----BEGIN CERTIFICATE-----\n${toStandardB64(cert.toString('base64')).match(/.{1,64}/g).join('\n')}\n-----END CERTIFICATE-----\n`
2419

2520
module.exports = {toIssuerCert, toPEM, toStandardB64}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const proxyquire = require('../../../proxyquire')
2+
const {toIssuerCert, toStandardB64, toPEM} = require('../../../../src/acme/certUtils')
3+
4+
describe('certUtils', () => {
5+
6+
it('toIssuerCert functions as expected', () => {
7+
const result = toIssuerCert('blah<haha>;rel="up"someotherstuff"')
8+
result.should.eql('haha')
9+
})
10+
11+
it('toIssuerCert error throws error', () => {
12+
(() => toIssuerCert('blah')).should.throw(TypeError)
13+
})
14+
15+
it('toPEM functions as expected', () => {
16+
const result = toPEM('blah')
17+
result.should.eql('-----BEGIN CERTIFICATE-----\nblah\n-----END CERTIFICATE-----\n')
18+
})
19+
20+
it('toStandardB64 functions as expected', () => {
21+
const result = toStandardB64('somewords=plus_equals-this')
22+
result.should.eql('somewordsplus/equals+this')
23+
})
24+
25+
})

0 commit comments

Comments
 (0)