From 7454a9f357d9197e533ef842a6333c4bc6dfce34 Mon Sep 17 00:00:00 2001 From: Danny Coates Date: Wed, 11 Jun 2014 10:48:28 -0700 Subject: [PATCH] don't move .well-known when there is a basePath in publicUrl --- routes/index.js | 8 ++++---- test/local/base_path_tests.js | 20 +++++++++++++++++++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/routes/index.js b/routes/index.js index 999969ee..3a9abf0e 100644 --- a/routes/index.js +++ b/routes/index.js @@ -58,6 +58,9 @@ module.exports = function ( config.smtp.redirectDomain ) + var basePath = url.parse(config.publicUrl).path + if (basePath === '/') { basePath = '' } + var v1Routes = [].concat( account, password, @@ -65,12 +68,9 @@ module.exports = function ( sign, util ) - v1Routes.forEach(function(r) { r.path = "/v1" + r.path }) + v1Routes.forEach(function(r) { r.path = basePath + "/v1" + r.path }) var allRoutes = defaults.concat(idp, v1Routes) - var basePath = url.parse(config.publicUrl).path - if (basePath === '/') { basePath = '' } - allRoutes.forEach(function (r) { r.path = basePath + r.path }) return allRoutes } diff --git a/test/local/base_path_tests.js b/test/local/base_path_tests.js index 157a238a..ebf92cc5 100644 --- a/test/local/base_path_tests.js +++ b/test/local/base_path_tests.js @@ -6,6 +6,8 @@ var test = require('../ptaptest') var TestServer = require('../test_server') var path = require('path') var Client = require('../client') +var P = require('../../promise') +var request = require('request') process.env.CONFIG_FILES = path.join(__dirname, '../config/base_path.json') var config = require('../../config').root() @@ -18,12 +20,28 @@ TestServer.start(config) function (t) { var email = Math.random() + "@example.com" var password = 'ok' - t.ok(true) // this silences log output. with no assertions tap dumps logs // if this doesn't crash, we're all good return Client.createAndVerify(config.publicUrl, email, password, server.mailbox) } ) + test( + '.well-known did not move', + function (t) { + var d = P.defer() + request('http://127.0.0.1:9000/.well-known/browserid', + function (err, res, body) { + if (err) { d.reject(err) } + t.equal(res.statusCode, 200) + var json = JSON.parse(body) + t.equal(json.authentication, '/.well-known/browserid/sign_in.html') + d.resolve(json) + } + ) + return d.promise + } + ) + test( 'teardown', function (t) {