Merge pull request #336 from mozilla/deepCopy-route-definition

fix(test): Avoid cross test pollution caused by mutating route objects.
This commit is contained in:
Vlad Filippov 2019-01-02 11:58:43 -05:00 коммит произвёл GitHub
Родитель 7ff96fb21d 769d17da5d
Коммит 45e593de6d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 9 добавлений и 4 удалений

Просмотреть файл

@ -5,6 +5,7 @@
const Hapi = require('hapi');
const Raven = require('raven');
const ScopeSet = require('fxa-shared').oauth.scopes;
const cloneDeep = require('lodash.clonedeep');
const AppError = require('../error');
const config = require('../config').getProperties();
@ -148,19 +149,22 @@ exports.create = function createServer() {
// Expand the scope list on each route to include all super-scopes,
// so that Hapi can easily check them via simple string comparison.
routes.forEach(function(route) {
routes = routes.map(function(routeDefinition) {
// create a copy of the route definition to avoid cross-unit test
// contamination since we make local changes to the definition object.
const route = cloneDeep(routeDefinition);
var scope = route.config.auth && route.config.auth.scope;
if (scope) {
route.config.auth.scope = ScopeSet.fromArray(scope).getImplicantValues();
}
});
routes.forEach(function(route) {
return route;
}).map(function(route) {
if (route.config.cache === undefined) {
route.config.cache = {
otherwise: 'private, no-cache, no-store, must-revalidate'
};
}
return route;
});
server.route(routes);

Просмотреть файл

@ -27,6 +27,7 @@
"hapi": "16.6.3",
"inert": "4.0.2",
"joi": "9.0.4",
"lodash.clonedeep": "4.5.0",
"mozlog": "2.2.0",
"mysql": "2.16.0",
"mysql-patcher": "0.7.0",