Skip to content

Commit

Permalink
Protège la route GET /documentRecu par variable environnement
Browse files Browse the repository at this point in the history
  • Loading branch information
egaillot committed Dec 2, 2024
1 parent c301d8a commit 0f56b9f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
7 changes: 6 additions & 1 deletion src/routes/routesBase.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const express = require('express');

const { protegeRouteAvecOOTS } = require('./utils');
const documentRecu = require('../api/documentRecu');

const routesBase = (config) => {
Expand All @@ -25,7 +26,11 @@ const routesBase = (config) => {
},
);

routes.get('/documentRecu', (requete, reponse) => documentRecu(depotDonnees, reponse));
routes.get(
'/documentRecu',
protegeRouteAvecOOTS(adaptateurEnvironnement),
(_requete, reponse) => documentRecu(depotDonnees, reponse),
);

return routes;
};
Expand Down
9 changes: 9 additions & 0 deletions src/routes/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const protegeRouteAvecOOTS = (adaptateurEnvironnement) => (
(_requete, reponse, suite) => (
adaptateurEnvironnement.avecOOTS()
? suite()
: reponse.status(501).send('Not Implemented Yet!')
)
);

module.exports = { protegeRouteAvecOOTS };
11 changes: 5 additions & 6 deletions src/siteVitrine.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const express = require('express');
const routesAuth = require('./routes/routesAuth');
const routesBase = require('./routes/routesBase');
const routesOOTS = require('./routes/routesOOTS');
const { protegeRouteAvecOOTS } = require('./routes/utils');

const creeServeur = (config) => {
const {
Expand Down Expand Up @@ -47,14 +48,12 @@ const creeServeur = (config) => {
middleware,
}));

const protegeRoute = (_requete, reponse, suite) => (
adaptateurEnvironnement.avecOOTS()
? suite()
: reponse.status(501).send('Not Implemented Yet!')
app.use(
'/oots',
protegeRouteAvecOOTS(adaptateurEnvironnement),
routesOOTS({ adaptateurEnvironnement, depotDonnees }),
);

app.use('/oots', protegeRoute, routesOOTS({ adaptateurEnvironnement, depotDonnees }));

app.use('/', routesBase({ adaptateurEnvironnement, depotDonnees, middleware }));

const arreteEcoute = (suite) => serveur.close(suite);
Expand Down
13 changes: 13 additions & 0 deletions test/routes/routesBase.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,17 @@ describe('Le serveur des routes `/`', () => {
});
});
});

describe('sur GET /documentRecu', () => {
it('retourne une erreur HTTP 501 (Not Implemented) si feature flip désactivé', () => {
expect.assertions(2);
serveur.adaptateurEnvironnement().avecOOTS = () => false;

return axios.get(`http://localhost:${port}/documentRecu`)
.catch(({ response }) => {
expect(response.status).toBe(501);
expect(response.data).toBe('Not Implemented Yet!');
});
});
});
});

0 comments on commit 0f56b9f

Please sign in to comment.