2023-07-05 19:06:21 +02:00
|
|
|
import { stub } from "../support/mock";
|
2023-07-04 08:50:43 +02:00
|
|
|
|
2023-07-04 14:52:33 +02:00
|
|
|
describe("login", () => {
|
2023-07-04 13:25:40 +02:00
|
|
|
beforeEach(() => {
|
2024-08-06 09:34:45 +02:00
|
|
|
stub("zitadel.session.v2.SessionService", "CreateSession", {
|
2023-07-04 13:25:40 +02:00
|
|
|
data: {
|
|
|
|
|
details: {
|
|
|
|
|
sequence: 859,
|
2024-04-04 11:42:15 +02:00
|
|
|
changeDate: new Date("2024-04-04T09:40:55.577Z"),
|
2023-07-04 13:25:40 +02:00
|
|
|
resourceOwner: "220516472055706145",
|
|
|
|
|
},
|
|
|
|
|
sessionId: "221394658884845598",
|
|
|
|
|
sessionToken:
|
|
|
|
|
"SDMc7DlYXPgwRJ-Tb5NlLqynysHjEae3csWsKzoZWLplRji0AYY3HgAkrUEBqtLCvOayLJPMd0ax4Q",
|
|
|
|
|
challenges: undefined,
|
2023-07-04 10:00:42 +02:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2024-08-06 09:34:45 +02:00
|
|
|
stub("zitadel.session.v2.SessionService", "GetSession", {
|
2023-07-04 13:25:40 +02:00
|
|
|
data: {
|
|
|
|
|
session: {
|
|
|
|
|
id: "221394658884845598",
|
2024-04-04 11:42:15 +02:00
|
|
|
creationDate: new Date("2024-04-04T09:40:55.577Z"),
|
2024-04-04 11:46:46 +02:00
|
|
|
changeDate: new Date("2024-04-04T09:40:55.577Z"),
|
2023-07-04 13:25:40 +02:00
|
|
|
sequence: 859,
|
|
|
|
|
factors: {
|
|
|
|
|
user: {
|
2024-04-04 11:22:20 +02:00
|
|
|
id: "221394658884845598",
|
2023-07-04 13:25:40 +02:00
|
|
|
loginName: "john@zitadel.com",
|
|
|
|
|
},
|
|
|
|
|
password: undefined,
|
2023-08-31 10:13:27 +02:00
|
|
|
webAuthN: undefined,
|
2023-07-04 13:25:40 +02:00
|
|
|
intent: undefined,
|
2023-07-04 10:09:30 +02:00
|
|
|
},
|
2023-07-04 13:25:40 +02:00
|
|
|
metadata: {},
|
2023-07-04 09:34:07 +02:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2024-08-06 09:34:45 +02:00
|
|
|
stub("zitadel.settings.v2.SettingsService", "GetLoginSettings", {
|
2023-07-05 14:16:04 +02:00
|
|
|
data: {
|
|
|
|
|
settings: {
|
|
|
|
|
passkeysType: 1,
|
2023-07-04 13:25:40 +02:00
|
|
|
},
|
2023-07-05 14:16:04 +02:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
describe("password login", () => {
|
|
|
|
|
beforeEach(() => {
|
2024-08-06 09:34:45 +02:00
|
|
|
stub("zitadel.user.v2.UserService", "ListUsers", {
|
2024-04-04 08:57:54 +02:00
|
|
|
data: {
|
2024-04-04 09:32:29 +02:00
|
|
|
details: {
|
|
|
|
|
totalResult: 1,
|
|
|
|
|
},
|
2024-04-04 08:57:54 +02:00
|
|
|
result: [
|
|
|
|
|
{
|
2024-04-04 09:32:29 +02:00
|
|
|
userId: "221394658884845598",
|
2024-04-04 08:57:54 +02:00
|
|
|
state: 1,
|
2024-04-04 09:32:29 +02:00
|
|
|
username: "john@zitadel.com",
|
|
|
|
|
loginNames: ["john@zitadel.com"],
|
|
|
|
|
preferredLoginName: "john@zitadel.com",
|
2024-04-04 08:57:54 +02:00
|
|
|
human: {
|
2024-04-04 09:32:29 +02:00
|
|
|
userId: "221394658884845598",
|
2024-04-04 08:57:54 +02:00
|
|
|
state: 1,
|
2024-04-04 09:32:29 +02:00
|
|
|
username: "john@zitadel.com",
|
|
|
|
|
loginNames: ["john@zitadel.com"],
|
|
|
|
|
preferredLoginName: "john@zitadel.com",
|
2024-04-04 08:57:54 +02:00
|
|
|
profile: {
|
2024-04-04 09:32:29 +02:00
|
|
|
givenName: "John",
|
|
|
|
|
familyName: "Doe",
|
2024-04-04 08:57:54 +02:00
|
|
|
avatarUrl: "https://zitadel.com/avatar.jpg",
|
|
|
|
|
},
|
|
|
|
|
email: {
|
2024-04-04 09:32:29 +02:00
|
|
|
email: "john@zitadel.com",
|
2024-04-04 08:57:54 +02:00
|
|
|
isVerified: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
});
|
2024-08-06 09:34:45 +02:00
|
|
|
stub("zitadel.user.v2.UserService", "ListAuthenticationMethodTypes", {
|
2024-04-04 09:59:28 +02:00
|
|
|
data: {
|
|
|
|
|
authMethodTypes: [1], // 1 for password authentication
|
|
|
|
|
},
|
|
|
|
|
});
|
2023-07-05 14:16:04 +02:00
|
|
|
});
|
|
|
|
|
it("should redirect a user with password authentication to /password", () => {
|
2023-08-31 10:04:05 +02:00
|
|
|
cy.visit("/loginname?loginName=john%40zitadel.com&submit=true");
|
2023-07-05 14:16:04 +02:00
|
|
|
cy.location("pathname", { timeout: 10_000 }).should("eq", "/password");
|
|
|
|
|
});
|
2023-07-05 19:06:21 +02:00
|
|
|
describe("with passkey prompt", () => {
|
|
|
|
|
beforeEach(() => {
|
2024-08-06 09:34:45 +02:00
|
|
|
stub("zitadel.session.v2.SessionService", "SetSession", {
|
2023-07-05 19:06:21 +02:00
|
|
|
data: {
|
|
|
|
|
details: {
|
|
|
|
|
sequence: 859,
|
|
|
|
|
changeDate: "2023-07-04T07:58:20.126Z",
|
|
|
|
|
resourceOwner: "220516472055706145",
|
|
|
|
|
},
|
|
|
|
|
sessionToken:
|
2023-07-05 19:08:38 +02:00
|
|
|
"SDMc7DlYXPgwRJ-Tb5NlLqynysHjEae3csWsKzoZWLplRji0AYY3HgAkrUEBqtLCvOayLJPMd0ax4Q",
|
2023-07-05 19:06:21 +02:00
|
|
|
challenges: undefined,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
it("should prompt a user to setup passwordless authentication if passkey is allowed in the login settings", () => {
|
|
|
|
|
cy.visit("/loginname?loginName=john%40zitadel.com&submit=true");
|
|
|
|
|
cy.location("pathname", { timeout: 10_000 }).should("eq", "/password");
|
|
|
|
|
cy.get('input[type="password"]').focus().type("MyStrongPassword!1");
|
|
|
|
|
cy.get('button[type="submit"]').click();
|
2023-07-05 19:08:38 +02:00
|
|
|
cy.location("pathname", { timeout: 10_000 }).should(
|
|
|
|
|
"eq",
|
2024-05-13 16:17:12 -04:00
|
|
|
"/passkey/add",
|
2023-07-05 19:08:38 +02:00
|
|
|
);
|
2023-07-05 19:06:21 +02:00
|
|
|
});
|
|
|
|
|
});
|
2023-07-05 14:16:04 +02:00
|
|
|
});
|
|
|
|
|
describe("passkey login", () => {
|
|
|
|
|
beforeEach(() => {
|
2024-08-06 09:34:45 +02:00
|
|
|
stub("zitadel.user.v2.UserService", "ListUsers", {
|
2024-04-04 09:59:28 +02:00
|
|
|
data: {
|
|
|
|
|
details: {
|
|
|
|
|
totalResult: 1,
|
|
|
|
|
},
|
|
|
|
|
result: [
|
|
|
|
|
{
|
|
|
|
|
userId: "221394658884845598",
|
|
|
|
|
state: 1,
|
|
|
|
|
username: "john@zitadel.com",
|
|
|
|
|
loginNames: ["john@zitadel.com"],
|
|
|
|
|
preferredLoginName: "john@zitadel.com",
|
|
|
|
|
human: {
|
|
|
|
|
userId: "221394658884845598",
|
|
|
|
|
state: 1,
|
|
|
|
|
username: "john@zitadel.com",
|
|
|
|
|
loginNames: ["john@zitadel.com"],
|
|
|
|
|
preferredLoginName: "john@zitadel.com",
|
|
|
|
|
profile: {
|
|
|
|
|
givenName: "John",
|
|
|
|
|
familyName: "Doe",
|
|
|
|
|
avatarUrl: "https://zitadel.com/avatar.jpg",
|
|
|
|
|
},
|
|
|
|
|
email: {
|
|
|
|
|
email: "john@zitadel.com",
|
|
|
|
|
isVerified: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
});
|
2024-08-06 09:34:45 +02:00
|
|
|
stub("zitadel.user.v2.UserService", "ListAuthenticationMethodTypes", {
|
2023-09-21 10:27:49 +02:00
|
|
|
data: {
|
|
|
|
|
authMethodTypes: [2], // 2 for passwordless authentication
|
|
|
|
|
},
|
|
|
|
|
});
|
2023-07-05 14:16:04 +02:00
|
|
|
});
|
2024-09-16 12:04:43 +02:00
|
|
|
it("should redirect a user with passwordless authentication to /passkey", () => {
|
2023-08-31 10:04:05 +02:00
|
|
|
cy.visit("/loginname?loginName=john%40zitadel.com&submit=true");
|
2024-09-16 12:04:43 +02:00
|
|
|
cy.location("pathname", { timeout: 10_000 }).should("eq", "/passkey");
|
2023-07-05 14:16:04 +02:00
|
|
|
});
|
2023-07-04 08:50:43 +02:00
|
|
|
});
|
2023-07-04 14:13:39 +02:00
|
|
|
});
|