Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature flippe la connexion FC Plus #5

Merged
merged 3 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.oots.template
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
AVEC_CONNEXION_FC_PLUS= # autorise connexion à FC Plus
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Peut-être qu'on peut être plus explicites – « autorise connexion à FC+ avec valeur true », par exemple.

AVEC_ENVOI_COOKIE_SUR_HTTP= # autorise envoi du cookie de session par HTTP avec valeur true
AVEC_REQUETE_PIECE_JUSTIFICATIVE= # active l'API /requete/pieceJustificative avec valeur true
IDENTIFIANT_EIDAS= # identifiant eIDAS injecté dans les requêtes (tant qu'on ne sait pas le récupérer)
Expand Down
5 changes: 4 additions & 1 deletion src/adaptateurs/adaptateurEnvironnement.js
Fabinout marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const avecRequetePieceJustificative = () => process.env.AVEC_REQUETE_PIECE_JUSTIFICATIVE === 'true';
const avecConnexionFCPlus = () => process.env.AVEC_CONNEXION_FC_PLUS === 'true';

const avecEnvoiCookieSurHTTP = () => process.env.AVEC_ENVOI_COOKIE_SUR_HTTP === 'true';

const avecRequetePieceJustificative = () => process.env.AVEC_REQUETE_PIECE_JUSTIFICATIVE === 'true';

const clePriveeJWK = () => JSON.parse(atob(process.env.CLE_PRIVEE_JWK_EN_BASE64));

const fournisseurIdentiteSuggere = () => (process.env.AVEC_AUTHENTIFICATION_EIDAS === 'true' ? 'eidas-bridge' : '');
Expand All @@ -26,6 +28,7 @@ const urlRedirectionDeconnexion = () => process.env.URL_REDIRECTION_DECONNEXION;

module.exports = {
avecEnvoiCookieSurHTTP,
avecConnexionFCPlus,
avecRequetePieceJustificative,
clePriveeJWK,
fournisseurIdentiteSuggere,
Expand Down
5 changes: 4 additions & 1 deletion src/ootsFrance.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ const creeServeur = (config) => {
depotPointsAcces,
}));

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

const arreteEcoute = (suite) => serveur.close(suite);

Expand Down
52 changes: 30 additions & 22 deletions src/routes/routesAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,37 @@ const routesAuth = (config) => {
deconnexionFCPlus(requete, reponse)
));

routes.get('/fcplus/destructionSession', (...args) => middleware.renseigneUtilisateurCourant(...args), (requete, reponse) => (
destructionSessionFCPlus(
{
adaptateurChiffrement,
adaptateurEnvironnement,
adaptateurFranceConnectPlus,
},
requete,
reponse,
)
));
routes.get('/fcplus/destructionSession', (...args) => middleware.renseigneUtilisateurCourant(...args), (requete, reponse) => {
if (adaptateurEnvironnement.avecConnexionFCPlus()) {
destructionSessionFCPlus(
{
adaptateurChiffrement,
adaptateurEnvironnement,
adaptateurFranceConnectPlus,
},
requete,
reponse,
);
} else {
reponse.status(501).send('Not Implemented Yet!');
}
});

routes.get('/fcplus/creationSession', (requete, reponse) => (
creationSessionFCPlus(
{
adaptateurChiffrement,
adaptateurEnvironnement,
adaptateurFranceConnectPlus,
},
requete,
reponse,
)
));
routes.get('/fcplus/creationSession', (requete, reponse) => {
if (adaptateurEnvironnement.avecConnexionFCPlus()) {
creationSessionFCPlus(
{
adaptateurChiffrement,
adaptateurEnvironnement,
adaptateurFranceConnectPlus,
},
requete,
reponse,
);
} else {
reponse.status(501).send('Not Implemented Yet!');
}
});

return routes;
};
Expand Down
12 changes: 10 additions & 2 deletions src/routes/routesBase.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
const express = require('express');

const routesBase = (config) => {
const { middleware } = config;
const {
adaptateurEnvironnement,
middleware,
} = config;

const routes = express.Router();

routes.get(
'/',
(...args) => middleware.renseigneUtilisateurCourant(...args),
(requete, reponse) => {
const infosUtilisateur = requete.utilisateurCourant;
reponse.render('pageAccueil', { infosUtilisateur });
const avecConnexionFCPlus = adaptateurEnvironnement.avecConnexionFCPlus();
reponse.render('pageAccueil', {
infosUtilisateur,
avecConnexionFCPlus,
});
},
);

Expand Down
6 changes: 6 additions & 0 deletions src/vues/pageAccueil.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<meta charset="utf-8" />
<title>OOTS-France</title>

{{#avecConnexionFCPlus}}
{{#infosUtilisateur}}
<p>Utilisateur courant : {{given_name}} {{family_name}}</p>
<a href="/auth/fcplus/destructionSession">Déconnexion</a>
Expand All @@ -10,3 +11,8 @@
<p>Pas d'utilisateur courant</p>
<a href="/auth/fcplus/creationSession">Connexion</a>
{{/infosUtilisateur}}
{{/avecConnexionFCPlus}}

{{^avecConnexionFCPlus}}
<p>Pas d'utilisateur courant</p>
{{/avecConnexionFCPlus}}
22 changes: 22 additions & 0 deletions test/routes/routesAuth.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ describe('Le serveur des routes `/auth`', () => {
.then((reponse) => expect(reponse.request.path).toContain('id_token_hint=abcdef'))
.catch(leveErreur);
});

it('retourne une erreur 501 si le feature-flipping est désactivé', () => {
expect.assertions(1);

serveur.adaptateurEnvironnement().avecConnexionFCPlus = () => false;

return axios.get(`http://localhost:${port}/auth/fcplus/creationSession`)
.catch(({ response }) => {
expect(response.status).toEqual(501);
});
});
});

describe('sur GET /auth/fcplus/creationSession', () => {
Expand All @@ -139,5 +150,16 @@ describe('Le serveur des routes `/auth`', () => {

return verifieRedirection(`http://localhost:${port}/auth/fcplus/creationSession`, `http://localhost:${port}/redirectionConnexion`);
});

it('retourne une erreur 501 si le feature-flipping est désactivé', () => {
expect.assertions(1);

serveur.adaptateurEnvironnement().avecConnexionFCPlus = () => false;

return axios.get(`http://localhost:${port}/auth/fcplus/creationSession`)
.catch(({ response }) => {
expect(response.status).toEqual(501);
});
});
});
});
11 changes: 11 additions & 0 deletions test/routes/routesBase.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,16 @@ describe('Le serveur des routes `/`', () => {
})
.catch(leveErreur);
});
it("n'affiche pas le bouton quand le feature flip est désactivé", () => {
expect.assertions(2);

serveur.adaptateurEnvironnement().avecConnexionFCPlus = () => false;

return axios.get(`http://localhost:${port}/`)
.then((reponse) => {
expect(reponse.status).toEqual(200);
expect(reponse.data).not.toContain('Connexion');
});
});
});
});
1 change: 1 addition & 0 deletions test/routes/serveurTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const serveurTest = () => {
};

adaptateurEnvironnement = {
avecConnexionFCPlus: () => true,
avecEnvoiCookieSurHTTP: () => true,
avecRequetePieceJustificative: () => true,
fournisseurIdentiteSuggere: () => '',
Expand Down
Loading