Files
zitadel/acceptance/tests/username-password-totp.spec.ts

71 lines
2.7 KiB
TypeScript
Raw Normal View History

import {faker} from "@faker-js/faker";
import {test as base} from "@playwright/test";
2024-11-28 09:57:20 +01:00
import dotenv from "dotenv";
import path from "path";
import {code} from "./code";
import {codeScreenExpect} from "./code-screen";
import {loginScreenExpect, loginWithPassword, loginWithPasswordAndTOTP} from "./login";
import {PasswordUserWithTOTP} from "./user";
2024-11-18 10:36:13 +01:00
2024-11-28 09:57:20 +01:00
// Read from ".env" file.
dotenv.config({path: path.resolve(__dirname, ".env.local")});
2024-11-28 09:57:20 +01:00
const test = base.extend<{ user: PasswordUserWithTOTP; sink: any }>({
user: async ({page}, use) => {
const user = new PasswordUserWithTOTP({
email: faker.internet.email(),
isEmailVerified: true,
firstName: faker.person.firstName(),
lastName: faker.person.lastName(),
organization: "",
phone: faker.phone.number({style: "international"}),
isPhoneVerified: true,
password: "Password1!",
passwordChangeRequired: false,
});
2024-11-28 09:57:20 +01:00
await user.ensure(page);
await use(user);
await user.cleanup();
},
2024-11-28 09:57:20 +01:00
});
test("username, password and totp login", async ({user, page}) => {
// Given totp is enabled on the organization of the user
// Given the user has only totp configured as second factor
// User enters username
// User enters password
// Screen for entering the code is shown directly
// User enters the code into the ui
// User is redirected to the app (default redirect url)
await loginWithPasswordAndTOTP(page, user.getUsername(), user.getPassword(), user.getSecret());
await loginScreenExpect(page, user.getFullName());
2024-11-18 10:36:13 +01:00
});
test("username, password and totp otp login, wrong code", async ({user, page}) => {
// Given totp is enabled on the organization of the user
// Given the user has only totp configured as second factor
// User enters username
// User enters password
// Screen for entering the code is shown directly
// User enters a wrond code
// Error message - "Invalid code" is shown
const c = "wrongcode";
await loginWithPassword(page, user.getUsername(), user.getPassword());
await code(page, c);
await codeScreenExpect(page, c);
2024-11-18 10:36:13 +01:00
});
test("username, password and totp login, multiple mfa options", async ({page}) => {
// Given totp and email otp is enabled on the organization of the user
// Given the user has totp and email otp configured as second factor
// User enters username
// User enters password
// Screen for entering the code is shown directly
// Button to switch to email otp is shown
// User clicks button to use email otp instead
// User receives an email with a verification code
// User enters code in ui
// User is redirected to the app (default redirect url)
2024-11-18 10:36:13 +01:00
});