diff --git a/.github/workflows/end-to-end.yml b/.github/workflows/end-to-end.yml index 9223527c..e582015c 100644 --- a/.github/workflows/end-to-end.yml +++ b/.github/workflows/end-to-end.yml @@ -24,7 +24,7 @@ env: DO_NOT_USE_ANNUAIRE_EMAILS: "True" DO_NOT_AUTHENTICATE_BROWSER: "True" SESSION_COOKIE_SECRET: secret - DEBOUNCE_API_KEY: + DEBOUNCE_API_KEY: ${{ secrets.DEBOUNCE_API_KEY }} SENTRY_DSN: INSEE_CONSUMER_KEY: ${{ secrets.INSEE_CONSUMER_KEY }} INSEE_CONSUMER_SECRET: ${{ secrets.INSEE_CONSUMER_SECRET }} @@ -62,6 +62,7 @@ jobs: - set_info_after_account_provisioning - signin_with_totp - reauthenticate_on_admin_page + - check_email_deliverability runs-on: ubuntu-22.04 services: moncomptepro-standard-client: diff --git a/cypress/README.md b/cypress/README.md index 4cd79749..1a2c75fa 100644 --- a/cypress/README.md +++ b/cypress/README.md @@ -12,7 +12,7 @@ The script will error out if it doesn’t find the necessary env vars. Ask a tea ### Setup env vars -You will need to set `BREVO_API_KEY`, `ZAMMAD_URL` and `ZAMMAD_TOKEN`. +You will need to set `BREVO_API_KEY`, `DEBOUNCE_API_KEY`, `ZAMMAD_URL` and `ZAMMAD_TOKEN`. Ask a teammate for them and put the values in your `.env`. diff --git a/cypress/e2e/check_email_deliverability.cy.js b/cypress/e2e/check_email_deliverability.cy.js new file mode 100644 index 00000000..0c2ec97b --- /dev/null +++ b/cypress/e2e/check_email_deliverability.cy.js @@ -0,0 +1,20 @@ +describe("should suggest valid email address", () => { + it("should sign-in", function () { + cy.visit(`http://localhost:4001`); + cy.get("button.moncomptepro-button").click(); + + cy.get('[name="login"]').should("have.value", "unused1@yopmail.com"); + cy.contains("Adresse email invalide."); + + cy.get('[name="login"]').type("{selectall}{del}unused2@yopmail.com"); + cy.get('[action="/users/start-sign-in"] [type="submit"]').click(); + + cy.get('[name="login"]').should("have.value", "unused2@yopmail.com"); + cy.contains("Adresse email invalide."); + + cy.get("#did-you-mean-link").click(); + cy.get('[action="/users/start-sign-in"] [type="submit"]').click(); + + cy.contains("Choisir votre mot de passe"); + }); +}); diff --git a/cypress/env/check_email_deliverability.conf b/cypress/env/check_email_deliverability.conf new file mode 100644 index 00000000..ca6eab46 --- /dev/null +++ b/cypress/env/check_email_deliverability.conf @@ -0,0 +1 @@ +DO_NOT_CHECK_EMAIL_DELIVERABILITY=False diff --git a/cypress/fixtures/check_email_deliverability.sql b/cypress/fixtures/check_email_deliverability.sql new file mode 100644 index 00000000..3ab1edfb --- /dev/null +++ b/cypress/fixtures/check_email_deliverability.sql @@ -0,0 +1,18 @@ +INSERT INTO oidc_clients + (client_name, client_id, client_secret, redirect_uris, + post_logout_redirect_uris, scope, client_uri, client_description, + userinfo_signed_response_alg, id_token_signed_response_alg, + authorization_signed_response_alg, introspection_signed_response_alg) +VALUES + ( + 'AgentConnect', + 'agentconnect_client_id', + 'agentconnect_client_secret', + ARRAY [ + 'http://localhost:4001/login-callback' + ], + ARRAY []::varchar[], + 'openid uid given_name usual_name email phone siret is_service_public is_public_service', + 'http://localhost:4001/', + 'Dispositif d’identification des agents de la fonction publique.', + 'ES256', 'ES256', 'ES256', 'ES256'); diff --git a/src/controllers/interaction.ts b/src/controllers/interaction.ts index 40e8a66c..e7e74296 100644 --- a/src/controllers/interaction.ts +++ b/src/controllers/interaction.ts @@ -41,7 +41,6 @@ export const interactionStartControllerFactory = if (prompt.name === "login" || prompt.name === "choose_organization") { if (login_hint) { - setEmailInUnauthenticatedSession(req, login_hint); req.body.login = login_hint; return postStartSignInController(req, res, next); } diff --git a/src/controllers/user/signin-signup.ts b/src/controllers/user/signin-signup.ts index 75758c12..d60cbd33 100644 --- a/src/controllers/user/signin-signup.ts +++ b/src/controllers/user/signin-signup.ts @@ -22,6 +22,7 @@ import * as Sentry from "@sentry/node"; import { DISPLAY_TEST_ENV_WARNING } from "../../config/env"; import { getEmailFromUnauthenticatedSession, + setEmailInUnauthenticatedSession, setPartialUserFromUnauthenticatedSession, updatePartialUserFromUnauthenticatedSession, } from "../../managers/session/unauthenticated"; @@ -95,15 +96,15 @@ export const postStartSignInController = async ( ? `&did_you_mean=${error.didYouMean}` : ""; + setEmailInUnauthenticatedSession(req, req.body.login); return res.redirect( - `/users/start-sign-in?notification=invalid_email&login_hint=${req.body.login}${didYouMeanQueryParam}`, + `/users/start-sign-in?notification=invalid_email${didYouMeanQueryParam}`, ); } if (error instanceof ZodError) { - return res.redirect( - `/users/start-sign-in?notification=invalid_email&login_hint=${req.body.login}`, - ); + setEmailInUnauthenticatedSession(req, req.body.login); + return res.redirect(`/users/start-sign-in?notification=invalid_email`); } next(error);