Skip to content

Commit 2380bec

Browse files
author
Robert Winterbottom
committed
2 parents 70a5709 + d9654bd commit 2380bec

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/server/router.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ function enableOperationRoutesForProfile(app, config, profile, key, parameters,
116116
cors(corsOptions),
117117
versionValidationMiddleware(profile),
118118
sanitizeMiddleware([routeArgs.BASE, routeArgs.ID, ...parameters]),
119-
authenticationMiddleware({ config }),
119+
authenticationMiddleware( config ),
120120
sofScopeMiddleware({ route, auth: config.auth, name: key }),
121121
// TODO: REMOVE: logger in future versions
122122
operationsController[interaction]({ profile, name: functionName, logger: deprecatedLogger }),
@@ -229,7 +229,7 @@ function enableResourceRoutes(app, config, corsDefaults) {
229229
cors(corsOptions),
230230
versionValidationMiddleware(profile),
231231
sanitizeMiddleware(route.args),
232-
authenticationMiddleware({ config }),
232+
authenticationMiddleware( config ),
233233
sofScopeMiddleware({ route, auth: config.auth, name: key }),
234234
loadController(lowercaseKey, route.interaction, profile.serviceModule),
235235
);

src/server/router.test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ jest.mock('./middleware/version-validation.middleware.js');
33
const router = require('./router.js');
44
const path = require('path');
55

6+
const passport = require('passport');
7+
jest.mock('passport');
8+
69
let app, config;
710

811
let mockServiceModule = {
@@ -145,4 +148,29 @@ describe('Router Tests', () => {
145148
expect(app.post.mock.calls[0][0]).toBe('/:base_version/patient/([$])aggregate-results');
146149
expect(app.post.mock.calls[1][0]).toBe('/:base_version/patient/_search');
147150
});
151+
152+
test('config should not be wrapped in another object before being passed to authentication middleware', () => {
153+
let originalEnv = process.env.NODE_ENV;
154+
process.env.NODE_ENV = 'development';
155+
156+
config.auth = {
157+
strategy: {
158+
name: 'test',
159+
useSession: true,
160+
}
161+
};
162+
config.profiles.patient.serviceModule = mockServiceModule;
163+
config.profiles.patient.operation = mockOperationConfig;
164+
165+
try {
166+
router.setRoutes({ app, config });
167+
} catch (e) {
168+
// Failed
169+
}
170+
171+
expect(passport.authenticate.mock.calls.length).toBe(3);
172+
173+
process.env.NODE_ENV = originalEnv;
174+
});
175+
148176
});

0 commit comments

Comments
 (0)