Update record test, use random prefix

* Test multiple zone records (@, foo, *.foo)
* Use random _acme-challenge-xxxx
This commit is contained in:
AJ ONeal 2019-06-06 22:48:34 -06:00
parent e179188bc0
commit f2373a09de
4 changed files with 144 additions and 119 deletions

View File

@ -1,10 +1,10 @@
"use strict";
'use strict';
//var tester = require('acme-challenge-test');
var tester = require("./");
var tester = require('./');
var type = "http-01";
var challenger = require("acme-http-01-cli").create({});
var type = 'http-01';
var challenger = require('acme-http-01-cli').create({});
//var type = 'dns-01';
//var challenger = require('acme-dns-01-cli').create({});
//var challenger = require('./YOUR-CHALLENGE-STRATEGY').create({});
@ -12,16 +12,15 @@ var challenger = require("acme-http-01-cli").create({});
// The dry-run tests can pass on, literally, 'example.com'
// but the integration tests require that you have control over the domain
var domain = "example.com";
//var domain = '*.example.com';
var zone = 'example.com';
tester
.test(type, domain, challenger)
.test(type, zone, challenger)
.then(function() {
console.info("PASS");
console.info('ALL PASSED');
})
.catch(function(err) {
console.error("FAIL");
console.error('FAIL');
console.error(err);
process.exit(20);
});

View File

@ -75,8 +75,7 @@ function run(challenger, opts) {
// The first time we just check it against itself
// this will cause the prompt to appear
return set(opts)
.then(function() {
return set(opts).then(function() {
// this will cause the final completion message to appear
// _test is used by the manual cli reference implementations
var query = { type: ch.type, /*debug*/ status: ch.status, _test: true };
@ -177,8 +176,28 @@ function run(challenger, opts) {
});
});
});
})
.then(function() {
});
}
module.exports.test = function(type, zone, challenger) {
var domains = [zone, 'foo.' + zone];
if ('dns-01' === type) {
domains.push('*.foo.' + zone);
}
function next() {
var domain = domains.shift();
if (!domain) {
return;
}
console.info("TEST '%s'", domain);
return testOne(type, domain, challenger).then(function() {
console.info("PASS '%s'", domain);
return next();
});
}
return next().then(function() {
console.info('All soft tests: PASS');
console.warn(
'Hard tests (actually checking http URLs and dns records) is implemented in acme-v2.'
@ -187,9 +206,9 @@ function run(challenger, opts) {
"We'll copy them over here as well, but that's a TODO for next week."
);
});
}
};
module.exports.test = function(type, altname, challenger) {
function testOne(type, altname, challenger) {
var expires = new Date(Date.now() + 10 * 60 * 1000).toISOString();
var token = crypto.randomBytes(8).toString('hex');
var thumb = crypto.randomBytes(16).toString('hex');
@ -212,7 +231,7 @@ module.exports.test = function(type, altname, challenger) {
thumbprint: thumb,
keyAuthorization: keyAuth,
url: null, // completed below
dnsHost: '_acme-challenge.', // completed below
dnsHost: '_acme-challenge-' + token.slice(0, 4) + '.', // completed below
dnsAuthorization: dnsAuth,
altname: altname,
_test: true // used by CLI referenced implementations
@ -227,4 +246,6 @@ module.exports.test = function(type, altname, challenger) {
challenge.dnsHost += altname;
return run(challenger, { challenge: challenge });
};
}
module.exports._test = testOne;

5
package-lock.json generated Normal file
View File

@ -0,0 +1,5 @@
{
"name": "acme-challenge-test",
"version": "3.0.4",
"lockfileVersion": 1
}

View File

@ -1,6 +1,6 @@
{
"name": "acme-challenge-test",
"version": "3.0.4",
"version": "3.0.5",
"description": "The base set of tests for all ACME challenge strategies. Any `acme-http-01-`, `acme-dns-01-`, `acme-challenge-`, or greenlock plugin should be able to pass these tests.",
"main": "index.js",
"homepage": "https://git.rootprojects.org/root/acme-challenge-test.js",