From 7730ffc319207ba877cd45e8e1004aa143af49f1 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 9 Aug 2016 14:17:26 -0400 Subject: [PATCH] bugfix middleware with templated :hostname --- lib/middleware.js | 4 ++-- tests/challenge-middleware.js | 22 +++++++++++++--------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/middleware.js b/lib/middleware.js index 6efe68b..5473a15 100644 --- a/lib/middleware.js +++ b/lib/middleware.js @@ -30,11 +30,11 @@ module.exports.create = function (le) { log(le.debug, "this must be tinder, 'cuz it's a match!"); var token = req.url.slice(prefix.length); - var hostname = req.hostname || (req.headers.host || '').toLowerCase().replace(/:*/, ''); + var hostname = req.hostname || (req.headers.host || '').toLowerCase().replace(/:.*/, ''); log(le.debug, "hostname", hostname, "token", token); - var copy = utils.merge({}, le); + var copy = utils.merge({ domains: [ hostname ] }, le); copy = utils.tplCopy(copy); // TODO tpl copy? diff --git a/tests/challenge-middleware.js b/tests/challenge-middleware.js index 625b27f..917ef83 100644 --- a/tests/challenge-middleware.js +++ b/tests/challenge-middleware.js @@ -1,17 +1,18 @@ 'use strict'; var PromiseA = require('bluebird'); +var path = require('path'); var requestAsync = PromiseA.promisify(require('request')); var LE = require('../').LE; var le = LE.create({ server: 'staging' , acme: require('le-acme-core').ACME.create() , store: require('le-store-certbot').create({ - configDir: '~/letsencrypt.test/etc' - , webrootPath: '~/letsencrypt.test/var/:hostname' + configDir: '~/letsencrypt.test/etc'.split('/').join(path.sep) + , webrootPath: '~/letsencrypt.test/var/:hostname'.split('/').join(path.sep) }) , challenge: require('le-challenge-fs').create({ - webrootPath: '~/letsencrypt.test/var/:hostname' + webrootPath: '~/letsencrypt.test/var/:hostname'.split('/').join(path.sep) }) , debug: true }); @@ -22,7 +23,10 @@ if ('/.well-known/acme-challenge/' !== LE.acmeChallengePrefix) { } var baseUrl; -var domain = 'example.com'; +// could use localhost as well, but for the sake of an FQDN for testing, we use this +// also, example.com is just a junk domain to make sure that it is ignored +// (even though it should always be an array of only one element in lib/core.js) +var domains = [ 'localhost.daplie.com', 'example.com' ]; // or just localhost var token = 'token-id'; var secret = 'key-secret'; @@ -38,9 +42,9 @@ var tests = [ } , function () { - var copy = utils.merge({}, le); + var copy = utils.merge({ domains: domains }, le); copy = utils.tplCopy(copy); - return PromiseA.promisify(le.challenge.set)(copy, domain, token, secret); + return PromiseA.promisify(le.challenge.set)(copy, domains[0], token, secret); } , function () { @@ -58,9 +62,9 @@ var tests = [ } , function () { - var copy = utils.merge({}, le); + var copy = utils.merge({ domains: domains }, le); copy = utils.tplCopy(copy); - return PromiseA.promisify(le.challenge.remove)(copy, domain, token); + return PromiseA.promisify(le.challenge.remove)(copy, domains[0], token); } , function () { @@ -78,7 +82,7 @@ function run() { var server = require('http').createServer(le.middleware()); server.listen(0, function () { console.log('Server running, proceeding to test.'); - baseUrl = 'http://localhost.daplie.com:' + server.address().port + LE.acmeChallengePrefix; + baseUrl = 'http://' + domains[0] + ':' + server.address().port + LE.acmeChallengePrefix; function next() { var test = tests.shift();