Skip to content

Commit

Permalink
Redirige vers la destruction de session quand incident d'authentifica…
Browse files Browse the repository at this point in the history
…tion

Co-authored-by: Emmanuel Gaillot <[email protected]>
  • Loading branch information
Fabinout and egaillot committed Jul 4, 2024
1 parent 4f4d43a commit a4370a6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/api/connexionFCPlus.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ const connexionFCPlus = (config, code, requete, reponse) => {
return stockeDansCookieSession(infos, adaptateurChiffrement, requete);
}))
.then(() => reponse.render('redirectionNavigateur', { destination: '/' }))
.catch((e) => {
.catch(() => {
requete.session.jeton = undefined;
reponse.render('erreur', { descriptionErreur: `Échec authentification (${e.message})` });
reponse.render('redirectionNavigateur', { destination: '/auth/fcplus/destructionSession' });
});
};

Expand Down
9 changes: 5 additions & 4 deletions test/api/connexionFCPlus.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,19 @@ describe('Le requêteur de connexion FC+', () => {
.then(() => expect(requete.session.jeton).toBeUndefined());
});

it("sert une page d'erreur si le nonce retourné est différent du nonce en session", () => {
expect.assertions(1);
it('redirige vers la destruction de session FC+ si le nonce retourné est différent du nonce en session', () => {
expect.assertions(2);
adaptateurChiffrement.verifieJeton = () => Promise.resolve({ nonce: 'unNonce' });

requete.session.jeton = { nonce: 'abcde' };
fabriqueSessionFCPlus.nouvelleSession = () => Promise.resolve({
enJSON: () => Promise.resolve({ nonce: 'oups' }),
});

reponse.render = (_nomModelePage, { descriptionErreur }) => {
reponse.render = (nomModelePage, { destination }) => {
try {
expect(descriptionErreur).toBe('Échec authentification (nonce invalide)');
expect(nomModelePage).toBe('redirectionNavigateur');
expect(destination).toBe('/auth/fcplus/destructionSession');
return Promise.resolve();
} catch (e) {
return Promise.reject(e);
Expand Down
5 changes: 3 additions & 2 deletions test/routes/routesAuth.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,14 @@ describe('Le serveur des routes `/auth`', () => {
.catch(leveErreur);
});

it("sert une page d'erreur quand l'authentification échoue", () => {
it("redirige vers la destruction de session FranceConnect+ quand l'authentification échoue", () => {
serveur.fabriqueSessionFCPlus().nouvelleSession = () => Promise.resolve({
enJSON: () => Promise.reject(new Error('Oups')),
});

return axios.get(`http://localhost:${port}/auth/fcplus/connexion_apres_redirection?code=unCode&state=unState`)
.then((reponse) => expect(reponse.data).toContain('Échec authentification (Oups)'));
.then((reponse) => expect(reponse.data).toContain('<meta http-equiv="refresh" content="0; url=\'/auth/fcplus/destructionSession\'">'))
.catch(leveErreur);
});
});
});
Expand Down

0 comments on commit a4370a6

Please sign in to comment.