Files
zitadel/apps/login/cypress/integration/verify.cy.ts

80 lines
2.6 KiB
TypeScript
Raw Normal View History

2024-09-12 09:11:35 +02:00
import { timestampFromDate } from "@zitadel/client";
2023-07-05 19:06:21 +02:00
import { stub } from "../support/mock";
2023-06-15 22:42:13 +02:00
describe("/verify", () => {
2024-09-12 08:42:48 +02:00
it("if no MFA required, redirects to loginname after successful email verification", () => {
2024-08-06 09:34:45 +02:00
stub("zitadel.user.v2.UserService", "VerifyEmail");
2024-09-12 09:11:35 +02:00
stub("zitadel.session.v2.SessionService", "GetSession", {
data: {
session: {
id: "221394658884845598",
creationDate: new Date("2024-04-04T09:40:55.577Z"),
changeDate: new Date("2024-04-04T09:40:55.577Z"),
sequence: 859,
factors: {
user: {
id: "221394658884845598",
loginName: "john@zitadel.com",
},
otpEmail: {
// set a factor
verifiedAt: timestampFromDate(
new Date("2024-04-04T09:40:55.577Z"),
),
},
password: undefined,
webAuthN: undefined,
intent: undefined,
},
metadata: {},
},
},
});
cy.visit("/verify?userId=123&code=abc&submit=true");
2023-07-03 18:36:46 +02:00
cy.location("pathname", { timeout: 10_000 }).should("eq", "/loginname");
2023-06-15 22:42:13 +02:00
});
2024-09-12 09:11:35 +02:00
it("if MFA is required and no mfa factor is found, redirects to mfa/set after successful email verification", () => {
2024-09-12 08:42:48 +02:00
stub("zitadel.settings.v2.SettingsService", "GetLoginSettings", {
data: {
settings: {
forceMfa: true,
},
},
});
stub("zitadel.user.v2.UserService", "VerifyEmail");
2024-09-12 09:11:35 +02:00
stub("zitadel.session.v2.SessionService", "GetSession", {
data: {
session: {
id: "221394658884845598",
creationDate: new Date("2024-04-04T09:40:55.577Z"),
changeDate: new Date("2024-04-04T09:40:55.577Z"),
sequence: 859,
factors: {
user: {
id: "221394658884845598",
loginName: "john@zitadel.com",
},
otpEmail: undefined,
password: undefined,
webAuthN: undefined,
intent: undefined,
},
metadata: {},
},
},
});
2024-09-12 08:42:48 +02:00
cy.visit("/verify?userId=123&code=abc&submit=true");
cy.location("pathname", { timeout: 10_000 }).should("eq", "/mfa/set");
});
2023-06-15 22:42:13 +02:00
it("shows an error if validation failed", () => {
2024-08-06 09:34:45 +02:00
stub("zitadel.user.v2.UserService", "VerifyEmail", {
2023-06-15 22:42:13 +02:00
code: 3,
error: "error validating code",
});
// TODO: Avoid uncaught exception in application
cy.once("uncaught:exception", () => false);
cy.visit("/verify?userId=123&code=abc&submit=true");
2024-09-04 15:06:16 +02:00
cy.contains("Could not verify email");
2023-06-15 22:42:13 +02:00
});
});