Skip to content

Commit

Permalink
Merge pull request #617 from numerique-gouv/fix-login-hint
Browse files Browse the repository at this point in the history
Fix login hint
  • Loading branch information
rdubigny authored Jul 19, 2024
2 parents fc6f852 + cf65c90 commit 48274c5
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/end-to-end.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion cypress/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down
20 changes: 20 additions & 0 deletions cypress/e2e/check_email_deliverability.cy.js
Original file line number Diff line number Diff line change
@@ -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", "[email protected]");
cy.contains("Adresse email invalide.");

cy.get('[name="login"]').type("{selectall}{del}[email protected]");
cy.get('[action="/users/start-sign-in"] [type="submit"]').click();

cy.get('[name="login"]').should("have.value", "[email protected]");
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");
});
});
1 change: 1 addition & 0 deletions cypress/env/check_email_deliverability.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DO_NOT_CHECK_EMAIL_DELIVERABILITY=False
18 changes: 18 additions & 0 deletions cypress/fixtures/check_email_deliverability.sql
Original file line number Diff line number Diff line change
@@ -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');
1 change: 0 additions & 1 deletion src/controllers/interaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
9 changes: 5 additions & 4 deletions src/controllers/user/signin-signup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 48274c5

Please sign in to comment.