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

145 lines
4.8 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 11:06:11 +02:00
removeStub("zitadel.session.v2alpha.SessionService", "CreateSession");
addStub("zitadel.session.v2alpha.SessionService", "CreateSession", {
2023-07-04 10:00:42 +02:00
details: {
sequence: 859,
2023-07-04 11:06:11 +02:00
changeDate: "2023-07-04T07:58:20.126Z",
2023-07-04 10:00:42 +02:00
resourceOwner: "220516472055706145",
},
sessionId: "221394658884845598",
sessionToken:
"SDMc7DlYXPgwRJ-Tb5NlLqynysHjEae3csWsKzoZWLplRji0AYY3HgAkrUEBqtLCvOayLJPMd0ax4Q",
challenges: undefined,
});
2023-07-04 11:06:11 +02:00
removeStub("zitadel.session.v2alpha.SessionService", "GetSession");
addStub("zitadel.session.v2alpha.SessionService", "GetSession", {
2023-07-04 10:00:42 +02:00
session: {
id: "221394658884845598",
2023-07-04 11:06:11 +02:00
creationDate: "2023-07-04T07:58:20.026Z",
changeDate: "2023-07-04T07:58:20.126Z",
2023-07-04 10:00:42 +02:00
sequence: 859,
factors: {
2023-07-04 10:09:30 +02:00
user: {
2023-07-04 10:37:54 +02:00
id: "123",
loginName: "zitadel-admin@zitadel.localhost",
2023-07-04 10:09:30 +02:00
},
2023-07-04 10:00:42 +02:00
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 10:37:54 +02:00
cy.visit(
"/loginname?loginName=zitadel-admin%40zitadel.localhost&submit=true"
);
2023-07-04 09:34:07 +02:00
cy.location("pathname", { timeout: 10_000 }).should(
"eq",
2023-07-04 10:37:54 +02:00
"/password?loginName=zitadel-admin%40zitadel.localhost&promptPasswordless=true"
2023-07-04 09:34:07 +02:00
);
2023-07-04 08:50:43 +02:00
});
it("should redirect a user with passwordless authentication to /passkey/login", () => {
2023-07-04 11:06:11 +02:00
removeStub("zitadel.session.v2alpha.SessionService", "CreateSession");
addStub("zitadel.session.v2alpha.SessionService", "CreateSession", {
2023-07-04 10:00:42 +02:00
details: {
sequence: 859,
2023-07-04 11:06:11 +02:00
changeDate: "2023-07-04T07:58:20.126Z",
2023-07-04 10:00:42 +02:00
resourceOwner: "220516472055706145",
},
sessionId: "221394658884845598",
sessionToken:
"SDMc7DlYXPgwRJ-Tb5NlLqynysHjEae3csWsKzoZWLplRji0AYY3HgAkrUEBqtLCvOayLJPMd0ax4Q",
challenges: undefined,
});
2023-07-04 11:06:11 +02:00
removeStub("zitadel.session.v2alpha.SessionService", "GetSession");
addStub("zitadel.session.v2alpha.SessionService", "GetSession", {
2023-07-04 10:00:42 +02:00
session: {
id: "221394658884845598",
2023-07-04 11:06:11 +02:00
creationDate: "2023-07-04T07:58:20.026Z",
changeDate: "2023-07-04T07:58:20.126Z",
2023-07-04 10:00:42 +02:00
sequence: 859,
factors: {
2023-07-04 10:09:30 +02:00
user: {
2023-07-04 10:37:54 +02:00
id: "123",
2023-07-04 10:09:30 +02:00
loginName: "johndoe@zitadel.com",
},
2023-07-04 10:00:42 +02:00
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",
// });