Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
feat(routes): add support for .well-known/change-password
Browse files Browse the repository at this point in the history
Fixes #6561
  • Loading branch information
vladikoff committed Oct 3, 2018
1 parent 87f40f1 commit 6d5662d
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
1 change: 1 addition & 0 deletions server/lib/routes.js
Expand Up @@ -46,6 +46,7 @@ module.exports = function (config, i18n) {
require('./routes/get-openid-configuration')(config),
require('./routes/get-version.json'),
require('./routes/get-metrics-flow')(config),
require('./routes/get-well-known-change-password')(),
require('./routes/post-metrics')(),
require('./routes/post-metrics-errors')(),
require('./routes/redirect-complete-to-verified')(),
Expand Down
19 changes: 19 additions & 0 deletions server/lib/routes/get-well-known-change-password.js
@@ -0,0 +1,19 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

'use strict';

const CHANGE_PASSWORD_ROUTE = '/settings/change_password';

module.exports = function () {
const route = {};
route.method = 'get';
route.path = '/.well-known/change-password';

route.process = function (req, res) {
res.redirect(301, CHANGE_PASSWORD_ROUTE);
};

return route;
};
53 changes: 53 additions & 0 deletions tests/server/routes/get-well-known-change-password.js
@@ -0,0 +1,53 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const { registerSuite } = intern.getInterface('object');
const assert = intern.getPlugin('chai').assert;
const routeModule = require('../../../server/lib/routes/get-well-known-change-password');
const got = require('got');
const sinon = require('sinon');
const serverUrl = intern._config.fxaContentRoot.replace(/\/$/, '');

const suite = {
tests: {}
};

var route;

suite.tests['get-well-known-change-password route function'] = {

'route function is correct': function () {
route = routeModule();
assert.isObject(route);
assert.lengthOf(Object.keys(route), 3);
assert.equal(route.method, 'get');
assert.equal(route.path, '/.well-known/change-password');
assert.isFunction(route.process);
assert.lengthOf(route.process, 2);
},

'route.process calls redirect': function () {
const response = {redirect: sinon.spy()};

routeModule().process({}, response);
assert.equal(response.redirect.callCount, 1);

const statusCode = response.redirect.args[0][0];
assert.equal(statusCode, 301);
}
};

suite.tests['#get /.well-known/change-password - returns a redirected page'] = function () {
const dfd = this.async(intern._config.asyncTimeout);

got(serverUrl + '/.well-known/change-password', {})
.then(function (res) {
assert.equal(res.statusCode, 200);
assert.equal(res.url, `${serverUrl}/settings/change_password`);
assert.isTrue(res.body.includes('<title>Firefox Accounts</title>'));
}).then(dfd.resolve.bind(dfd), dfd.reject.bind(dfd));

return dfd;
};

registerSuite('well-known-change-password', suite);
1 change: 1 addition & 0 deletions tests/tests_server.js
Expand Up @@ -33,6 +33,7 @@ module.exports = [
'tests/server/routes/get-openid-configuration.js',
'tests/server/routes/get-verify-email.js',
'tests/server/routes/get-index.js',
'tests/server/routes/get-well-known-change-password.js',
'tests/server/routes/post-csp.js',
'tests/server/routes/post-metrics.js',
'tests/server/routes/redirect-m-to-adjust.js',
Expand Down

0 comments on commit 6d5662d

Please sign in to comment.