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

refactor: factorise login steps in e2e tests #691

Merged
merged 2 commits into from
Sep 16, 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
14 changes: 2 additions & 12 deletions cypress/e2e/activate_totp/index.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,9 @@ describe("add 2fa authentication", () => {
});

it("should add 2fa authentication on account user", function () {
cy.visit(`/users/start-sign-in`);
cy.visit("/connection-and-account");

cy.get('[name="login"]').type(
"64d9024b-d389-4b9d-948d-a504082c14fa@mailslurp.com",
);
cy.get('[type="submit"]').click();

cy.get('[name="password"]').type("password123");
cy.get('[action="/users/sign-in"] [type="submit"]')
.contains("S’identifier")
.click();

cy.contains("Connexion et compte").click();
cy.login("64d9024b-d389-4b9d-948d-a504082c14fa@mailslurp.com");

cy.contains("Application FreeOTP Authenticator");

Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/check_email_deliverability/index.cy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe("should suggest valid email address", () => {
it("should sign-in", function () {
cy.visit(`http://localhost:4001`);
cy.visit("http://localhost:4001");
cy.get("button.moncomptepro-button").click();

cy.get('[name="login"]').should("have.value", "unused1@yopmail.com");
Expand Down
15 changes: 2 additions & 13 deletions cypress/e2e/delete_account/index.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,9 @@ describe("delete account", () => {
});

it("should delete account", function () {
// Visit the signup page
cy.visit(`/users/start-sign-in`);
cy.visit("/connection-and-account");

cy.get('[name="login"]').type(
"4cec922b-ecbe-4a46-8511-fc9478c1efd0@mailslurp.com",
);
cy.get('[type="submit"]').click();

cy.get('[name="password"]').type("password123");
cy.get('[action="/users/sign-in"] [type="submit"]')
.contains("S’identifier")
.click();

cy.contains("Connexion et compte").click();
cy.login("4cec922b-ecbe-4a46-8511-fc9478c1efd0@mailslurp.com");

cy.contains("Suppression");

Expand Down
72 changes: 8 additions & 64 deletions cypress/e2e/delete_totp/index.cy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { generateToken } from "@sunknudsen/totp";

describe("delete TOTP connexion", () => {
before(() => {
cy.mailslurp().then((mailslurp) =>
Expand All @@ -15,29 +13,9 @@ describe("delete TOTP connexion", () => {
});

it("should delete TOTP application", function () {
// Visit the signup page
cy.visit(`/users/start-sign-in`);

cy.get('[name="login"]').type(
"eab4ab97-875d-4ec7-bdcc-04323948ee63@mailslurp.com",
);
cy.get('[type="submit"]').click();

cy.get('[name="password"]').type("password123");
cy.get('[action="/users/sign-in"] [type="submit"]')
.contains("S’identifier")
.click();
cy.visit("/connection-and-account");

// redirect to the TOTP login page
cy.contains("Valider en deux étapes");

const totp = generateToken("din5ncvbluqpx7xfzqcybmibmtjocnsf", Date.now());
cy.get("[name=totpToken]").type(totp);
cy.get(
'[action="/users/2fa-sign-in-with-authenticator-app"] [type="submit"]',
).click();

cy.contains("Connexion et compte").click();
cy.mfaLogin("eab4ab97-875d-4ec7-bdcc-04323948ee63@mailslurp.com");

cy.contains("Application FreeOTP Authenticator");

Expand All @@ -63,44 +41,17 @@ describe("delete TOTP connexion", () => {
});

it("should not be ask to sign with TOTP", function () {
cy.visit(`http://localhost:4000`);
cy.visit("http://localhost:4000");
cy.get("button.moncomptepro-button").click();
cy.get('[name="login"]').type(
"eab4ab97-875d-4ec7-bdcc-04323948ee63@mailslurp.com",
);
cy.get('[type="submit"]').click();
cy.get('[name="password"]').type("password123");
cy.get('[action="/users/sign-in"] [type="submit"]')
.contains("S’identifier")
.click();
cy.login("eab4ab97-875d-4ec7-bdcc-04323948ee63@mailslurp.com");

cy.contains('"amr": [\n "pwd"\n ],');
});

it("should disable TOTP", function () {
// Visit the signup page
cy.visit(`/users/start-sign-in`);
cy.visit("/connection-and-account");

cy.get('[name="login"]').type(
"c9fabb94-9274-4ece-a3d0-54b1987c8588@mailslurp.com",
);
cy.get('[type="submit"]').click();

cy.get('[name="password"]').type("password123");
cy.get('[action="/users/sign-in"] [type="submit"]')
.contains("S’identifier")
.click();

// redirect to the TOTP login page
cy.contains("Valider en deux étapes");

const totp = generateToken("din5ncvbluqpx7xfzqcybmibmtjocnsf", Date.now());
cy.get("[name=totpToken]").type(totp);
cy.get(
'[action="/users/2fa-sign-in-with-authenticator-app"] [type="submit"]',
).click();

cy.contains("Connexion et compte").click();
cy.mfaLogin("c9fabb94-9274-4ece-a3d0-54b1987c8588@mailslurp.com");

cy.contains("Validation en deux étapes");

Expand All @@ -124,16 +75,9 @@ describe("delete TOTP connexion", () => {
});

it("should not be ask to sign with TOTP", function () {
cy.visit(`http://localhost:4000`);
cy.visit("http://localhost:4000");
cy.get("button.moncomptepro-button").click();
cy.get('[name="login"]').type(
"c9fabb94-9274-4ece-a3d0-54b1987c8588@mailslurp.com",
);
cy.get('[type="submit"]').click();
cy.get('[name="password"]').type("password123");
cy.get('[action="/users/sign-in"] [type="submit"]')
.contains("S’identifier")
.click();
cy.login("c9fabb94-9274-4ece-a3d0-54b1987c8588@mailslurp.com");

cy.contains('"amr": [\n "pwd"\n ],');
});
Expand Down
12 changes: 4 additions & 8 deletions cypress/e2e/join_and_moderation/index.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@ describe("join and moderation", () => {
);
});

beforeEach(() => {
cy.login(
"86983334-028f-48b5-881d-8b05d738bec5@mailslurp.net",
"password123",
);
});

it("will be moderated", function () {
cy.visit(`/`);
cy.visit("/");

cy.login("86983334-028f-48b5-881d-8b05d738bec5@mailslurp.net");

cy.get('[name="siret"]').type("66204244933106");
cy.get('[type="submit"]').click();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@ describe("join organizations", () => {
});

it("join collectivité territoriale with official contact domain", function () {
cy.login(
"76450610-4dcc-4664-b9ab-1cea869b62b1@mailslurp.com",
"password123",
);
cy.visit("/users/join-organization");
cy.login("76450610-4dcc-4664-b9ab-1cea869b62b1@mailslurp.com");

cy.visit(`/users/join-organization`);
cy.get('[name="siret"]').type("21740056300011");
cy.get('[type="submit"]').click();

Expand Down
14 changes: 5 additions & 9 deletions cypress/e2e/join_must_confirm/index.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

describe("join organizations", () => {
it("join big company with free email provider", function () {
cy.login("unused1@yopmail.com", "password123");
cy.visit("/users/start-sign-in");

cy.visit(`/users/join-organization`);
cy.login("unused1@yopmail.com");

cy.visit("/users/join-organization");
cy.get('[name="siret"]').type("54205118000066");
cy.get('[type="submit"]').click();

Expand All @@ -16,13 +18,7 @@ describe("join organizations", () => {
.contains("Corriger l’email")
.click();

cy.get('[name="login"]').type("unused2@yopmail.com");
cy.get('[type="submit"]').click();

cy.get('[name="password"]').type("password123");
cy.get('[action="/users/sign-in"] [type="submit"]')
.contains("S’identifier")
.click();
cy.login("unused2@yopmail.com");

cy.get('[name="siret"]').type("54205118000066");
cy.get('[type="submit"]').click();
Expand Down
10 changes: 2 additions & 8 deletions cypress/e2e/join_org_with_trackdechets_domain/index.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,10 @@ describe("join organizations", () => {
}),
);
});
beforeEach(() => {
cy.login(
"0c5b976c-b6b0-406e-a7ed-08ddae8d2d81@mailslurp.com",
"password123",
);
});

it("join suggested organisation", function () {
// Visit the signup page
cy.visit(`/`);
cy.visit("/");
cy.login("0c5b976c-b6b0-406e-a7ed-08ddae8d2d81@mailslurp.com");

// The user gets this suggestion because it as mailslurp.com as trackdechets domain
cy.get(".fr-grid-row .fr-col-12:first-child .fr-tile__link").contains(
Expand Down
15 changes: 5 additions & 10 deletions cypress/e2e/join_org_with_verified_domain/index.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,10 @@ describe("join organizations", () => {
]),
);
});
beforeEach(() => {
cy.login(
"c6c64542-5601-43e0-b320-b20da72f6edc@mailslurp.com",
"password123",
);
});

it("join suggested organisation", function () {
// Visit the signup page
cy.visit(`/`);
cy.visit("/");
cy.login("c6c64542-5601-43e0-b320-b20da72f6edc@mailslurp.com");

// The user gets this suggestion because it as mailslurp.com as verified domain
cy.get(".fr-grid-row .fr-col-12:first-child .fr-tile__link").contains(
Expand All @@ -44,8 +38,9 @@ describe("join organizations", () => {
});

it("join another organisation", function () {
// Visit the join organization page
cy.visit(`/users/join-organization`);
cy.visit("/users/join-organization");
cy.login("c6c64542-5601-43e0-b320-b20da72f6edc@mailslurp.com");

cy.get('[name="siret"]').type("13002526500013");
cy.get('[type="submit"]').click();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@ describe("join organizations", () => {
});

it("join collectivité territoriale with code send to official contact email", function () {
cy.login(
"c348a2c3-bf54-4f15-bb12-a2d7047c832f@mailslurp.com",
"password123",
);
cy.visit("/users/join-organization");
cy.login("c348a2c3-bf54-4f15-bb12-a2d7047c832f@mailslurp.com");

cy.visit(`/users/join-organization`);
cy.get('[name="siret"]').type("21340126800130");
cy.get('[type="submit"]').click();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@ describe("join organizations", () => {
});

it("join collectivité territoriale with code send to official contact email", function () {
cy.login(
"10efdabd-deb0-4d19-a521-6772ca27acf8@mailslurp.com",
"password123",
);
cy.visit("/users/join-organization");
cy.login("10efdabd-deb0-4d19-a521-6772ca27acf8@mailslurp.com");

cy.visit(`/users/join-organization`);
cy.get('[name="siret"]').type("19750663700010");
cy.get('[type="submit"]').click();

Expand Down
14 changes: 4 additions & 10 deletions cypress/e2e/join_with_official_contact_email/index.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,19 @@ describe("join organizations", () => {
});

it("join collectivité territoriale with official contact email", function () {
cy.login(
"435f6a4d-df7d-4840-be7b-bc4851b64e91@mailslurp.com",
"password123",
);
cy.visit("/users/join-organization");
cy.login("435f6a4d-df7d-4840-be7b-bc4851b64e91@mailslurp.com");

cy.visit(`/users/join-organization`);
cy.get('[name="siret"]').type("21340126800130");
cy.get('[type="submit"]').click();

cy.contains("Votre compte est créé");
});

it("join primary school with official contact email", function () {
cy.login(
"435f6a4d-df7d-4840-be7b-bc4851b64e91@mailslurp.com",
"password123",
);
cy.visit("/users/join-organization");
cy.login("435f6a4d-df7d-4840-be7b-bc4851b64e91@mailslurp.com");

cy.visit(`/users/join-organization`);
cy.get('[name="siret"]').type("21340126800049");
cy.get('[type="submit"]').click();

Expand Down
27 changes: 3 additions & 24 deletions cypress/e2e/reauthenticate_on_admin_page/index.cy.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,16 @@
import { generateToken } from "@sunknudsen/totp";

const login = (cy) => {
cy.get('[name="login"]').type("unused1@yopmail.com");
cy.get('[type="submit"]').click();

cy.get('[name="password"]').type("password123");
cy.get('[action="/users/sign-in"] [type="submit"]')
.contains("S’identifier")
.click();
};

const tfaAuth = (cy) => {
const totp = generateToken("din5ncvbluqpx7xfzqcybmibmtjocnsf", Date.now());
cy.get("[name=totpToken]").type(totp);
cy.get(
'[action="/users/2fa-sign-in-with-authenticator-app"] [type="submit"]',
).click();
};

describe("force recent connexion + 2FA on admin pages", () => {
it("should be redirected after long connexion", function () {
cy.visit("/");

login(cy);
cy.login("unused1@yopmail.com");

cy.contains("Votre compte est créé");

cy.visit("/connection-and-account");

cy.contains("merci de valider votre deuxième étape de connexion");

tfaAuth(cy);
cy.fillTotpFields();

cy.contains("Connexion et compte");

Expand All @@ -45,8 +25,7 @@ describe("force recent connexion + 2FA on admin pages", () => {

cy.contains("merci de vous identifier à nouveau");

login(cy);
tfaAuth(cy);
cy.mfaLogin("unused1@yopmail.com");

cy.contains("Connexion et compte");
});
Expand Down
Loading