Skip to content

Commit

Permalink
Réinitialise statut récupération document sur déconnexion utilisateur
Browse files Browse the repository at this point in the history
… Pour des besoins de démo, en attendant d'avoir une gestion spécifique
des documents récupérés pour chaque utilisateur.

Co-authored-by: Fabien Lamarque <[email protected]>
  • Loading branch information
egaillot and Fabinout committed Sep 16, 2024
1 parent a264bc4 commit 03287d1
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/api/destructionSessionFCPlus.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const destructionSessionFCPlus = (config, requete, reponse) => {
adaptateurChiffrement,
adaptateurEnvironnement,
adaptateurFranceConnectPlus,
depotDonnees,
} = config;

const { jwtSessionFCPlus } = requete.session;
Expand All @@ -11,7 +12,8 @@ const destructionSessionFCPlus = (config, requete, reponse) => {
const etat = adaptateurChiffrement.cleHachage(`${Math.random()}`);
const urlRedirectionDeconnexion = adaptateurEnvironnement.urlRedirectionDeconnexion();

return adaptateurFranceConnectPlus.urlDestructionSession()
return depotDonnees.reinitialiseRecuperationDocument()
.then(() => adaptateurFranceConnectPlus.urlDestructionSession())
.then((url) => reponse.redirect(
`${url}?id_token_hint=${jwtSessionFCPlus}&state=${etat}&post_logout_redirect_uri=${urlRedirectionDeconnexion}`,
));
Expand Down
5 changes: 5 additions & 0 deletions src/depotDonnees.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ class DepotDonnees {
return Promise.resolve();
}

reinitialiseRecuperationDocument() {
this.donnees.statutRecuperationDocument = StatutRecuperationDocument.INITIAL;
return Promise.resolve();
}

statutRecuperationDocument() {
return Promise.resolve(new StatutRecuperationDocument(this.donnees.statutRecuperationDocument));
}
Expand Down
2 changes: 2 additions & 0 deletions src/routes/routesAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const routesAuth = (config) => {
adaptateurChiffrement,
adaptateurEnvironnement,
adaptateurFranceConnectPlus,
depotDonnees,
fabriqueSessionFCPlus,
journal,
middleware,
Expand Down Expand Up @@ -74,6 +75,7 @@ const routesAuth = (config) => {
adaptateurChiffrement,
adaptateurEnvironnement,
adaptateurFranceConnectPlus,
depotDonnees,
},
requete,
reponse,
Expand Down
1 change: 1 addition & 0 deletions src/siteVitrine.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const creeServeur = (config) => {
adaptateurChiffrement,
adaptateurEnvironnement,
adaptateurFranceConnectPlus,
depotDonnees,
fabriqueSessionFCPlus,
journal,
middleware,
Expand Down
21 changes: 20 additions & 1 deletion test/api/destructionSessionFCPlus.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ describe('Le requêteur de destruction de session FC+', () => {
const adaptateurChiffrement = {};
const adaptateurEnvironnement = {};
const adaptateurFranceConnectPlus = {};
const config = { adaptateurChiffrement, adaptateurEnvironnement, adaptateurFranceConnectPlus };
const depotDonnees = {};
const config = {
adaptateurChiffrement,
adaptateurEnvironnement,
adaptateurFranceConnectPlus,
depotDonnees,
};
const reponse = {};

let requete = {};
Expand All @@ -13,6 +19,7 @@ describe('Le requêteur de destruction de session FC+', () => {
adaptateurChiffrement.cleHachage = () => '';
adaptateurEnvironnement.urlRedirectionDeconnexion = () => '';
adaptateurFranceConnectPlus.urlDestructionSession = () => Promise.resolve('');
depotDonnees.reinitialiseRecuperationDocument = () => Promise.resolve();
requete = { session: {} };
reponse.end = () => Promise.resolve();
reponse.redirect = () => Promise.resolve();
Expand Down Expand Up @@ -86,6 +93,18 @@ describe('Le requêteur de destruction de session FC+', () => {

return destructionSessionFCPlus(config, requete, reponse);
});

it('réinitialise le statut de récupération du document (pour les besoins de la démo, en attendant gestion spécifique par utilisateur)', () => {
let depotDonneesAppele = false;

depotDonnees.reinitialiseRecuperationDocument = () => {
depotDonneesAppele = true;
return Promise.resolve();
};

return destructionSessionFCPlus(config, requete, reponse)
.then(() => expect(depotDonneesAppele).toBe(true));
});
});

describe('Quand le JWT de session est inexistant', () => {
Expand Down
10 changes: 10 additions & 0 deletions test/depotDonnees.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,14 @@ describe('Le dépôt de données', () => {
.then(() => depot.statutRecuperationDocument())
.then((statut) => expect(statut.estTermine()).toBe(true));
});

it('repasse le statut de récupération de document à « initial »', () => {
const depot = new DepotDonnees({
statutRecuperationDocument: StatutRecuperationDocument.EN_COURS,
});

return depot.reinitialiseRecuperationDocument()
.then(() => depot.statutRecuperationDocument())
.then((statut) => expect(statut.estInitial()).toBe(true));
});
});
1 change: 1 addition & 0 deletions test/routes/serveurTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const serveurTest = () => {

depotDonnees = {
demarreRecuperationDocument: () => Promise.resolve(),
reinitialiseRecuperationDocument: () => Promise.resolve(),
statutRecuperationDocument: () => Promise.resolve(new StatutRecuperationDocument()),
termineRecuperationDocument: () => Promise.resolve(),
};
Expand Down

0 comments on commit 03287d1

Please sign in to comment.