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

[CORRECTION] Pas d'utilisateur courant si processus authent interrompu #31

Merged
merged 1 commit into from
Jun 25, 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
2 changes: 2 additions & 0 deletions src/erreurs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class ErreurEchecAuthentification extends Error {}
class ErreurInstructionSOAPInconnue extends Error {}
class ErreurJetonInvalide extends Error {}
class ErreurReponseRequete extends Error {}
class ErreurSessionFCPlusInexistante extends Error {}

module.exports = {
ErreurAbsenceReponseDestinataire,
Expand All @@ -14,4 +15,5 @@ module.exports = {
ErreurInstructionSOAPInconnue,
ErreurJetonInvalide,
ErreurReponseRequete,
ErreurSessionFCPlusInexistante,
};
6 changes: 5 additions & 1 deletion src/modeles/utilisateur.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
const { ErreurSessionFCPlusInexistante } = require('../erreurs');

class Utilisateur {
constructor(donnees) {
if (typeof donnees.jwtSessionFCPlus === 'undefined') { throw new ErreurSessionFCPlusInexistante(); }

this.jwtSessionFCPlus = donnees.jwtSessionFCPlus;
this.prenom = donnees.prenom;
this.nomUsage = donnees.nomUsage;
this.jwtSessionFCPlus = donnees.jwtSessionFCPlus;
}

afficheToi() {
Expand Down
13 changes: 12 additions & 1 deletion test/modeles/utilisateur.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
const { ErreurSessionFCPlusInexistante } = require('../../src/erreurs');
const Utilisateur = require('../../src/modeles/utilisateur');

describe("L'utilisateur courant", () => {
it("sait s'afficher", () => {
const utilisateur = new Utilisateur({ prenom: 'Juliette', nomUsage: 'Haucourt' });
const utilisateur = new Utilisateur({ prenom: 'Juliette', nomUsage: 'Haucourt', jwtSessionFCPlus: 'abcdef' });
expect(utilisateur.afficheToi()).toBe('Juliette Haucourt');
});

it("vérifie qu'il est initialisé avec un jeton de session FC+", () => {
expect.assertions(1);

try {
new Utilisateur({ prenom: 'Juliette', nomUsage: 'Haucourt' });
} catch (e) {
expect(e).toBeInstanceOf(ErreurSessionFCPlusInexistante);
}
});
});
11 changes: 9 additions & 2 deletions test/routes/middleware.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,21 @@ describe('Le middleware OOTS-France', () => {
});

it("renseigne les infos de l'utilisateur courant dans la requête", (suite) => {
adaptateurChiffrement.verifieJeton = () => Promise.resolve({ prenom: 'Pierre', nomUsage: 'Jax' });
adaptateurChiffrement.verifieJeton = () => Promise.resolve({
jwtSessionFCPlus: 'abcdef',
prenom: 'Pierre',
nomUsage: 'Jax',
});

const middleware = new Middleware(config);
expect(requete.utilisateurCourant).toBeUndefined();

middleware.renseigneUtilisateurCourant(requete, null, () => {
try {
expect(requete.utilisateurCourant).toEqual({ prenom: 'Pierre', nomUsage: 'Jax' });
const utilisateur = requete.utilisateurCourant;
expect(utilisateur.jwtSessionFCPlus).toEqual('abcdef');
expect(utilisateur.prenom).toEqual('Pierre');
expect(utilisateur.nomUsage).toEqual('Jax');
suite();
} catch (e) { suite(e); }
})
Expand Down
1 change: 1 addition & 0 deletions test/routes/routesBase.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('Le serveur des routes `/`', () => {
it("affiche prénom et nom de l'utilisateur courant s'il existe", () => {
serveur.middleware().reinitialise({
utilisateurCourant: new Utilisateur({
jwtSessionFCPlus: 'abcdef',
prenom: 'Sandra',
nomUsage: 'Nicouette',
}),
Expand Down
Loading