smartacme/test/test.ts

91 lines
2.5 KiB
TypeScript
Raw Permalink Normal View History

2017-04-28 16:56:55 +00:00
import { expect, tap } from 'tapbundle'
2017-01-14 17:36:33 +00:00
import * as cflare from 'cflare'
2017-01-15 21:30:33 +00:00
import * as qenv from 'qenv'
2016-11-01 17:27:57 +00:00
2017-01-22 20:50:04 +00:00
let testQenv = new qenv.Qenv(process.cwd(), process.cwd() + '/.nogit')
2016-11-01 17:27:57 +00:00
// import the module to test
import * as smartacme from '../dist/index'
2017-01-22 20:50:04 +00:00
let myCflareAccount = new cflare.CflareAccount()
myCflareAccount.auth({
2017-04-28 16:56:55 +00:00
email: process.env.CF_EMAIL,
key: process.env.CF_KEY
2017-01-22 20:50:04 +00:00
})
2017-04-28 16:56:55 +00:00
let testSmartAcme: smartacme.SmartAcme
let testAcmeAccount: smartacme.AcmeAccount
let testAcmeCert: smartacme.AcmeCert
let testChallenge: smartacme.ISmartAcmeChallengeChosen
2017-01-14 13:14:50 +00:00
2017-04-28 16:56:55 +00:00
tap.test('smartacme -> should create a valid instance', async (tools) => {
tools.timeout(10000)
testSmartAcme = new smartacme.SmartAcme(false)
await testSmartAcme.init().then(async () => {
expect(testSmartAcme).to.be.instanceOf(smartacme.SmartAcme)
})
})
2017-01-01 20:20:12 +00:00
2017-04-28 16:56:55 +00:00
tap.test('smartacme -> should have created keyPair', async () => {
expect(testSmartAcme.acmeUrl).to.be.a('string')
})
2017-01-01 20:20:12 +00:00
2017-04-28 16:56:55 +00:00
tap.test('smartacme -> should register a new account', async (tools) => {
tools.timeout(10000)
await testSmartAcme.createAcmeAccount().then(async x => {
testAcmeAccount = x
})
})
2017-01-15 11:21:29 +00:00
2017-04-28 16:56:55 +00:00
tap.test('smartacme -> should create a AcmeCert', async () => {
await testAcmeAccount.createAcmeCert('test2.bleu.de').then(async x => {
testAcmeCert = x
expect(testAcmeAccount).to.be.instanceOf(smartacme.AcmeCert)
})
})
2017-01-14 13:14:50 +00:00
2017-04-28 16:56:55 +00:00
tap.test('smartacme -> should get a challenge for a AcmeCert', async (tools) => {
tools.timeout(10000)
await testAcmeCert.requestChallenge().then(async (challengeChosen) => {
console.log(challengeChosen)
testChallenge = challengeChosen
})
})
2017-01-22 20:50:04 +00:00
2017-04-28 16:56:55 +00:00
tap.test('smartacme -> should set the challenge', async (tools) => {
tools.timeout(20000)
await myCflareAccount.createRecord(
testChallenge.domainNamePrefixed,
'TXT', testChallenge.dnsKeyHash
)
})
2017-01-15 21:30:33 +00:00
2017-04-28 16:56:55 +00:00
tap.test('smartacme -> should check for a DNS record', async (tools) => {
tools.timeout(20000)
await testAcmeCert.checkDns().then(x => {
console.log(x)
})
})
2017-01-25 01:45:48 +00:00
2017-04-28 16:56:55 +00:00
tap.test('smartacme -> should accept the challenge', async (tools) => {
tools.timeout(10000)
await testAcmeCert.acceptChallenge()
})
2017-01-27 00:09:38 +00:00
2017-04-28 16:56:55 +00:00
tap.test('smartacme -> should poll for validation of a challenge', async (tools) => {
tools.timeout(10000)
await testAcmeCert.requestValidation().then(async x => {
console.log(x)
})
2016-11-01 17:27:57 +00:00
})
2017-04-28 16:56:55 +00:00
tap.test('smartacme -> should remove the challenge', async (tools) => {
tools.timeout(20000)
await myCflareAccount.removeRecord(
testChallenge.domainNamePrefixed,
'TXT'
)
})
tap.start()