Skip to content

Commit cf88fa8

Browse files
nlepageHEYGULVincentHardouin
committed
fix(maddo): register applications token route in maddo server
Co-authored-by: Ce que tu veux <guillaume.lagorce@pix.fr> Co-authored-by: Vincent Hardouin <vincent.hardouin@pix.fr>
1 parent bbee960 commit cf88fa8

File tree

4 files changed

+84
-17
lines changed

4 files changed

+84
-17
lines changed

api/server.maddo.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { parse } from 'neoqs';
44

55
import { setupErrorHandling } from './config/server-setup-error-handling.js';
66
import { knex } from './db/knex-database-connection.js';
7-
import * as authenticationRoutes from './lib/application/authentication/index.js';
87
import { authentication } from './lib/infrastructure/authentication.js';
8+
import { identityAccessManagementRoutes } from './src/identity-access-management/application/routes.js';
99
import * as replicationRoutes from './src/maddo/application/replications-routes.js';
1010
import { Metrics } from './src/monitoring/infrastructure/metrics.js';
1111
import * as healthcheckRoutes from './src/shared/application/healthcheck/index.js';
@@ -179,7 +179,13 @@ const setupAuthentication = function (server) {
179179
};
180180

181181
const setupRoutesAndPlugins = async function (server) {
182-
await server.register([...plugins, healthcheckRoutes, authenticationRoutes, replicationRoutes]);
182+
const routes = [healthcheckRoutes, ...identityAccessManagementRoutes, replicationRoutes];
183+
const routesWithOptions = routes.map((route) => ({
184+
plugin: route,
185+
options: { tags: ['maddo'] },
186+
}));
187+
188+
await server.register([...plugins, ...routesWithOptions]);
183189
};
184190

185191
const setupOpenApiSpecification = async function (server) {

api/src/identity-access-management/application/routes.js

+24-14
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,30 @@ import { tokenRoutes } from './token/token.route.js';
99
import { userAdminRoutes } from './user/user.admin.route.js';
1010
import { userRoutes } from './user/user.route.js';
1111

12-
const register = async function (server) {
13-
server.route([
14-
...accountRecoveryRoutes,
15-
...anonymizationAdminRoutes,
16-
...ltiRoutes,
17-
...oidcProviderAdminRoutes,
18-
...oidcProviderRoutes,
19-
...passwordRoutes,
20-
...samlRoutes,
21-
...tokenRoutes,
22-
...userAdminRoutes,
23-
...userRoutes,
24-
]);
25-
};
12+
const allRoutes = [
13+
...accountRecoveryRoutes,
14+
...anonymizationAdminRoutes,
15+
...ltiRoutes,
16+
...oidcProviderAdminRoutes,
17+
...oidcProviderRoutes,
18+
...passwordRoutes,
19+
...samlRoutes,
20+
...tokenRoutes,
21+
...userAdminRoutes,
22+
...userRoutes,
23+
];
24+
25+
function register(server, { routes = allRoutes, tags }) {
26+
if (!tags) {
27+
server.route(routes);
28+
return;
29+
}
30+
31+
const filteredRoutes = routes.filter((route) =>
32+
(route.config ?? route.options).tags.some((tag) => tags.includes(tag)),
33+
);
34+
server.route(filteredRoutes);
35+
}
2636

2737
const name = 'identity-access-management-api';
2838

api/src/identity-access-management/application/token/token.route.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export const tokenRoutes = [
4646
},
4747
},
4848
handler: tokenController.authenticateApplication,
49-
tags: ['api', 'authorization-server', 'parcoursup'],
49+
tags: ['api', 'authorization-server', 'parcoursup', 'maddo'],
5050
},
5151
},
5252
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { identityAccessManagementRoutes } from '../../../../src/identity-access-management/application/routes.js';
2+
import { expect, sinon } from '../../../test-helper.js';
3+
4+
describe('Unit | Identity Access Management | Application | Routes', function () {
5+
let routes;
6+
let server;
7+
8+
beforeEach(function () {
9+
routes = [
10+
{ config: { tags: ['tag1', 'tag2'] } },
11+
{ config: { tags: ['tag3'] } },
12+
{ options: { tags: ['tag3'] } },
13+
{ options: { tags: ['tag4'] } },
14+
{ options: { tags: ['tag2', 'tag5'] } },
15+
];
16+
17+
server = {
18+
route: sinon.stub(),
19+
};
20+
});
21+
22+
context('when no tags are given', function () {
23+
it('registers all routes', function () {
24+
// given
25+
const options = { routes, tags: undefined };
26+
27+
// when
28+
identityAccessManagementRoutes[0].register(server, options);
29+
30+
// then
31+
expect(server.route).to.have.been.calledOnceWith(routes);
32+
});
33+
});
34+
35+
context('when tags are given', function () {
36+
it('registers routes having at least one of the tags', function () {
37+
// given
38+
const options = { routes, tags: ['tag2', 'tag4'] };
39+
40+
// when
41+
identityAccessManagementRoutes[0].register(server, options);
42+
43+
// then
44+
expect(server.route).to.have.been.calledOnceWith([
45+
{ config: { tags: ['tag1', 'tag2'] } },
46+
{ options: { tags: ['tag4'] } },
47+
{ options: { tags: ['tag2', 'tag5'] } },
48+
]);
49+
});
50+
});
51+
});

0 commit comments

Comments
 (0)