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

137 lines
4.6 KiB
TypeScript
Raw Normal View History

2023-07-04 08:50:43 +02:00
import { addStub, removeStub } from "../support/mock";
describe("/passkey/login", () => {
it("should redirect a user with password authentication to /password", () => {
2023-07-04 10:00:42 +02:00
removeStub("zitadel.user.v2alpha.SessionService", "CreateSession");
addStub("zitadel.user.v2alpha.SessionService", "CreateSession", {
details: {
sequence: 859,
changeDate: new Date("2023-07-04T07:58:20.126Z"),
resourceOwner: "220516472055706145",
},
sessionId: "221394658884845598",
sessionToken:
"SDMc7DlYXPgwRJ-Tb5NlLqynysHjEae3csWsKzoZWLplRji0AYY3HgAkrUEBqtLCvOayLJPMd0ax4Q",
challenges: undefined,
});
removeStub("zitadel.user.v2alpha.SessionService", "GetSession");
addStub("zitadel.user.v2alpha.SessionService", "GetSession", {
session: {
id: "221394658884845598",
creationDate: new Date("2023-07-04T07:58:20.026Z"),
changeDate: new Date("2023-07-04T07:58:20.126Z"),
sequence: 859,
factors: {
user: [Object],
password: undefined,
passkey: undefined,
intent: undefined,
2023-07-04 09:34:07 +02:00
},
2023-07-04 10:00:42 +02:00
metadata: {},
domain: "localhost",
2023-07-04 09:34:07 +02:00
},
});
removeStub(
2023-07-04 09:40:34 +02:00
"zitadel.user.v2alpha.UserService",
2023-07-04 09:34:07 +02:00
"ListAuthenticationMethodTypes"
);
addStub(
2023-07-04 09:40:34 +02:00
"zitadel.user.v2alpha.UserService",
2023-07-04 09:34:07 +02:00
"ListAuthenticationMethodTypes",
{
authMethodTypes: [1], // 1 for password authentication
}
);
2023-07-04 09:35:24 +02:00
cy.visit("/loginname?loginName=johndoe%40zitadel.com&submit=true");
2023-07-04 09:34:07 +02:00
cy.location("pathname", { timeout: 10_000 }).should(
"eq",
"/password?loginName=johndoe%40zitadel.com"
);
2023-07-04 08:50:43 +02:00
});
it("should redirect a user with passwordless authentication to /passkey/login", () => {
2023-07-04 10:00:42 +02:00
removeStub("zitadel.user.v2alpha.SessionService", "CreateSession");
addStub("zitadel.user.v2alpha.SessionService", "CreateSession", {
details: {
sequence: 859,
changeDate: new Date("2023-07-04T07:58:20.126Z"),
resourceOwner: "220516472055706145",
},
sessionId: "221394658884845598",
sessionToken:
"SDMc7DlYXPgwRJ-Tb5NlLqynysHjEae3csWsKzoZWLplRji0AYY3HgAkrUEBqtLCvOayLJPMd0ax4Q",
challenges: undefined,
});
removeStub("zitadel.user.v2alpha.SessionService", "GetSession");
addStub("zitadel.user.v2alpha.SessionService", "GetSession", {
session: {
id: "221394658884845598",
creationDate: new Date("2023-07-04T07:58:20.026Z"),
changeDate: new Date("2023-07-04T07:58:20.126Z"),
sequence: 859,
factors: {
user: [Object],
password: undefined,
passkey: undefined,
intent: undefined,
2023-07-04 09:34:07 +02:00
},
2023-07-04 10:00:42 +02:00
metadata: {},
domain: "localhost",
2023-07-04 09:34:07 +02:00
},
});
removeStub(
2023-07-04 09:40:34 +02:00
"zitadel.user.v2alpha.UserService",
2023-07-04 09:34:07 +02:00
"ListAuthenticationMethodTypes"
);
addStub(
2023-07-04 09:40:34 +02:00
"zitadel.user.v2alpha.UserService",
2023-07-04 09:34:07 +02:00
"ListAuthenticationMethodTypes",
{
authMethodTypes: [2], // 2 for passwordless authentication
}
);
2023-07-04 09:35:24 +02:00
cy.visit("/loginname?loginName=johndoe%40zitadel.com&submit=true");
2023-07-04 09:34:07 +02:00
cy.location("pathname", { timeout: 10_000 }).should(
"eq",
"/passkey/login?loginName=zitadel-admin%40zitadel.localhost"
);
2023-07-04 08:50:43 +02:00
});
2023-07-04 09:34:07 +02:00
// it("should prompt a user to setup passwordless authentication if passkey is allowed in the login settings", () => {
// removeStub("zitadel.user.v2alpha.SessionService", "SetSession");
// addStub("zitadel.user.v2alpha.SessionService", "SetSession");
// cy.visit("/passkey/login?loginName=zitadel-admin%40zitadel.localhost");
// cy.location("pathname", { timeout: 10_000 }).should("eq", "/accounts");
// });
// it("redirects after successful login", () => {
// removeStub("zitadel.user.v2alpha.SessionService", "SetSession");
// addStub("zitadel.user.v2alpha.SessionService", "SetSession");
// cy.visit("/passkey/login?loginName=zitadel-admin%40zitadel.localhost");
// cy.location("pathname", { timeout: 10_000 }).should("eq", "/accounts");
// });
2023-07-04 08:50:43 +02:00
});
2023-07-04 10:00:42 +02:00
// removeStub("zitadel.user.v2alpha.SessionService", "SetSession");
// addStub("zitadel.user.v2alpha.SessionService", "SetSession", {
// id: "221390781972217886",
// creationDate: new Date("2023-07-04T07:19:49.178Z"),
// changeDate: new Date("2023-07-04T07:19:54.617Z"),
// sequence: 854,
// factors: {
// user: {
// displayName: "John Doe",
// id: "221256020561756190",
// loginName: "johndoe@zitadel.com",
// verifiedAt: "2023-07-04T07:19:49.168Z",
// sessionId: "221390781972217886",
// },
// },
// metadata: {},
// domain: "localhost",
// });