mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-13 21:40:45 +00:00
lint
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import {test} from "@playwright/test";
|
import { test } from "@playwright/test";
|
||||||
import {loginScreenExpect, loginWithPassword} from "./login";
|
import { loginScreenExpect, loginWithPassword } from "./login";
|
||||||
|
|
||||||
test("admin login", async ({page}) => {
|
test("admin login", async ({ page }) => {
|
||||||
await loginWithPassword(page, "zitadel-admin@zitadel.localhost", "Password1.")
|
await loginWithPassword(page, "zitadel-admin@zitadel.localhost", "Password1.");
|
||||||
await loginScreenExpect(page, "ZITADEL Admin");
|
await loginScreenExpect(page, "ZITADEL Admin");
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,30 +1,28 @@
|
|||||||
import {expect, Page} from "@playwright/test";
|
import { expect, Page } from "@playwright/test";
|
||||||
import {loginname} from "./loginname";
|
import { loginname } from "./loginname";
|
||||||
import {password} from "./password";
|
import { password } from "./password";
|
||||||
|
|
||||||
export async function startLogin(page: Page) {
|
export async function startLogin(page: Page) {
|
||||||
await page.goto("/loginname");
|
await page.goto("/loginname");
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function loginWithPassword(page: Page, username: string, pw: string) {
|
export async function loginWithPassword(page: Page, username: string, pw: string) {
|
||||||
await startLogin(page);
|
await startLogin(page);
|
||||||
await loginname(page, username);
|
await loginname(page, username);
|
||||||
await password(page, pw);
|
await password(page, pw);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function loginWithPasskey(page: Page, authenticatorId: string, username: string) {
|
export async function loginWithPasskey(page: Page, authenticatorId: string, username: string) {
|
||||||
await startLogin(page);
|
await startLogin(page);
|
||||||
await loginname(page, username);
|
await loginname(page, username);
|
||||||
// await passkey(page, authenticatorId);
|
// await passkey(page, authenticatorId);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function loginScreenExpect(page: Page, fullName: string) {
|
export async function loginScreenExpect(page: Page, fullName: string) {
|
||||||
await expect(page).toHaveURL(/signedin.*/)
|
await expect(page).toHaveURL(/signedin.*/);
|
||||||
await expect(page.getByRole('heading')).toContainText(fullName);
|
await expect(page.getByRole("heading")).toContainText(fullName);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function loginWithOTP(page: Page, username: string, password: string) {
|
export async function loginWithOTP(page: Page, username: string, password: string) {
|
||||||
await loginWithPassword(page, username, password);
|
await loginWithPassword(page, username, password);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import {expect, Page} from "@playwright/test";
|
import { expect, Page } from "@playwright/test";
|
||||||
|
|
||||||
const usernameUserInput = "username-text-input"
|
const usernameUserInput = "username-text-input";
|
||||||
|
|
||||||
export async function loginnameScreen(page: Page, username: string) {
|
export async function loginnameScreen(page: Page, username: string) {
|
||||||
await page.getByTestId(usernameUserInput).pressSequentially(username);
|
await page.getByTestId(usernameUserInput).pressSequentially(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function loginnameScreenExpect(page: Page, username: string) {
|
export async function loginnameScreenExpect(page: Page, username: string) {
|
||||||
await expect(page.getByTestId(usernameUserInput)).toHaveValue(username);
|
await expect(page.getByTestId(usernameUserInput)).toHaveValue(username);
|
||||||
await expect(page.getByTestId('error').locator('div')).toContainText("Could not find user")
|
await expect(page.getByTestId("error").locator("div")).toContainText("Could not find user");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import {Page} from "@playwright/test";
|
import { Page } from "@playwright/test";
|
||||||
import {loginnameScreen} from "./loginname-screen";
|
import { loginnameScreen } from "./loginname-screen";
|
||||||
|
|
||||||
export async function loginname(page: Page, username: string) {
|
export async function loginname(page: Page, username: string) {
|
||||||
await loginnameScreen(page, username)
|
await loginnameScreen(page, username);
|
||||||
await page.getByTestId("submit-button").click()
|
await page.getByTestId("submit-button").click();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,29 +3,29 @@ import * as http from "node:http";
|
|||||||
let messages = new Map<string, any>();
|
let messages = new Map<string, any>();
|
||||||
|
|
||||||
export function startSink() {
|
export function startSink() {
|
||||||
const hostname = "127.0.0.1"
|
const hostname = "127.0.0.1";
|
||||||
const port = 3030
|
const port = 3030;
|
||||||
|
|
||||||
const server = http.createServer((req, res) => {
|
const server = http.createServer((req, res) => {
|
||||||
console.log("Sink received message: ")
|
console.log("Sink received message: ");
|
||||||
let body = '';
|
let body = "";
|
||||||
req.on('data', (chunk) => {
|
req.on("data", (chunk) => {
|
||||||
body += chunk;
|
body += chunk;
|
||||||
});
|
|
||||||
|
|
||||||
req.on('end', () => {
|
|
||||||
console.log(body);
|
|
||||||
const data = JSON.parse(body)
|
|
||||||
messages.set(data.contextInfo.recipientEmailAddress, data.args.code)
|
|
||||||
res.statusCode = 200;
|
|
||||||
res.setHeader('Content-Type', 'text/plain');
|
|
||||||
res.write('OK');
|
|
||||||
res.end();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
server.listen(port, hostname, () => {
|
req.on("end", () => {
|
||||||
console.log(`Sink running at http://${hostname}:${port}/`);
|
console.log(body);
|
||||||
|
const data = JSON.parse(body);
|
||||||
|
messages.set(data.contextInfo.recipientEmailAddress, data.args.code);
|
||||||
|
res.statusCode = 200;
|
||||||
|
res.setHeader("Content-Type", "text/plain");
|
||||||
|
res.write("OK");
|
||||||
|
res.end();
|
||||||
});
|
});
|
||||||
return server
|
});
|
||||||
}
|
|
||||||
|
server.listen(port, hostname, () => {
|
||||||
|
console.log(`Sink running at http://${hostname}:${port}/`);
|
||||||
|
});
|
||||||
|
return server;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,109 +1,109 @@
|
|||||||
import {expect, Page} from "@playwright/test";
|
import { expect, Page } from "@playwright/test";
|
||||||
import {CDPSession} from "playwright-core";
|
import { CDPSession } from "playwright-core";
|
||||||
|
|
||||||
interface session {
|
interface session {
|
||||||
client: CDPSession
|
client: CDPSession;
|
||||||
authenticatorId: string
|
authenticatorId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function client(page: Page): Promise<session> {
|
async function client(page: Page): Promise<session> {
|
||||||
const cdpSession = await page.context().newCDPSession(page);
|
const cdpSession = await page.context().newCDPSession(page);
|
||||||
await cdpSession.send('WebAuthn.enable', {enableUI: false});
|
await cdpSession.send("WebAuthn.enable", { enableUI: false });
|
||||||
const result = await cdpSession.send('WebAuthn.addVirtualAuthenticator', {
|
const result = await cdpSession.send("WebAuthn.addVirtualAuthenticator", {
|
||||||
options: {
|
options: {
|
||||||
protocol: 'ctap2',
|
protocol: "ctap2",
|
||||||
transport: 'internal',
|
transport: "internal",
|
||||||
hasResidentKey: true,
|
hasResidentKey: true,
|
||||||
hasUserVerification: true,
|
hasUserVerification: true,
|
||||||
isUserVerified: true,
|
isUserVerified: true,
|
||||||
automaticPresenceSimulation: true,
|
automaticPresenceSimulation: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
return {client: cdpSession, authenticatorId: result.authenticatorId};
|
return { client: cdpSession, authenticatorId: result.authenticatorId };
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function passkeyRegister(page: Page): Promise<string> {
|
export async function passkeyRegister(page: Page): Promise<string> {
|
||||||
const session = await client(page)
|
const session = await client(page);
|
||||||
|
|
||||||
await passkeyNotExisting(session.client, session.authenticatorId);
|
await passkeyNotExisting(session.client, session.authenticatorId);
|
||||||
await simulateSuccessfulPasskeyRegister(
|
await simulateSuccessfulPasskeyRegister(session.client, session.authenticatorId, () =>
|
||||||
session.client,
|
page.getByTestId("submit-button").click(),
|
||||||
session.authenticatorId,
|
);
|
||||||
() =>
|
await passkeyRegistered(session.client, session.authenticatorId);
|
||||||
page.getByTestId("submit-button").click()
|
|
||||||
);
|
|
||||||
await passkeyRegistered(session.client, session.authenticatorId);
|
|
||||||
|
|
||||||
return session.authenticatorId
|
return session.authenticatorId;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function passkey(page: Page, authenticatorId: string) {
|
export async function passkey(page: Page, authenticatorId: string) {
|
||||||
const cdpSession = await page.context().newCDPSession(page);
|
const cdpSession = await page.context().newCDPSession(page);
|
||||||
await cdpSession.send('WebAuthn.enable', {enableUI: false});
|
await cdpSession.send("WebAuthn.enable", { enableUI: false });
|
||||||
|
|
||||||
const signCount = await passkeyExisting(cdpSession, authenticatorId);
|
const signCount = await passkeyExisting(cdpSession, authenticatorId);
|
||||||
|
|
||||||
await simulateSuccessfulPasskeyInput(
|
await simulateSuccessfulPasskeyInput(cdpSession, authenticatorId, () => page.getByTestId("submit-button").click());
|
||||||
cdpSession,
|
|
||||||
authenticatorId,
|
|
||||||
() =>
|
|
||||||
page.getByTestId("submit-button").click()
|
|
||||||
);
|
|
||||||
|
|
||||||
await passkeyUsed(cdpSession, authenticatorId, signCount);
|
await passkeyUsed(cdpSession, authenticatorId, signCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function passkeyNotExisting(client: CDPSession, authenticatorId: string) {
|
async function passkeyNotExisting(client: CDPSession, authenticatorId: string) {
|
||||||
const result = await client.send('WebAuthn.getCredentials', {authenticatorId});
|
const result = await client.send("WebAuthn.getCredentials", { authenticatorId });
|
||||||
expect(result.credentials).toHaveLength(0);
|
expect(result.credentials).toHaveLength(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function passkeyRegistered(client: CDPSession, authenticatorId: string) {
|
async function passkeyRegistered(client: CDPSession, authenticatorId: string) {
|
||||||
const result = await client.send('WebAuthn.getCredentials', {authenticatorId});
|
const result = await client.send("WebAuthn.getCredentials", { authenticatorId });
|
||||||
expect(result.credentials).toHaveLength(1);
|
expect(result.credentials).toHaveLength(1);
|
||||||
await passkeyUsed(client, authenticatorId, 0);
|
await passkeyUsed(client, authenticatorId, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function passkeyExisting(client: CDPSession, authenticatorId: string): Promise<number> {
|
async function passkeyExisting(client: CDPSession, authenticatorId: string): Promise<number> {
|
||||||
const result = await client.send('WebAuthn.getCredentials', {authenticatorId});
|
const result = await client.send("WebAuthn.getCredentials", { authenticatorId });
|
||||||
expect(result.credentials).toHaveLength(1);
|
expect(result.credentials).toHaveLength(1);
|
||||||
return result.credentials[0].signCount
|
return result.credentials[0].signCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function passkeyUsed(client: CDPSession, authenticatorId: string, signCount: number) {
|
async function passkeyUsed(client: CDPSession, authenticatorId: string, signCount: number) {
|
||||||
const result = await client.send('WebAuthn.getCredentials', {authenticatorId});
|
const result = await client.send("WebAuthn.getCredentials", { authenticatorId });
|
||||||
expect(result.credentials).toHaveLength(1);
|
expect(result.credentials).toHaveLength(1);
|
||||||
expect(result.credentials[0].signCount).toBeGreaterThan(signCount);
|
expect(result.credentials[0].signCount).toBeGreaterThan(signCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function simulateSuccessfulPasskeyRegister(client: CDPSession, authenticatorId: string, operationTrigger: () => Promise<void>) {
|
async function simulateSuccessfulPasskeyRegister(
|
||||||
// initialize event listeners to wait for a successful passkey input event
|
client: CDPSession,
|
||||||
const operationCompleted = new Promise<void>(resolve => {
|
authenticatorId: string,
|
||||||
client.on('WebAuthn.credentialAdded', () => {
|
operationTrigger: () => Promise<void>,
|
||||||
console.log('Credential Added!');
|
) {
|
||||||
resolve()
|
// initialize event listeners to wait for a successful passkey input event
|
||||||
});
|
const operationCompleted = new Promise<void>((resolve) => {
|
||||||
|
client.on("WebAuthn.credentialAdded", () => {
|
||||||
|
console.log("Credential Added!");
|
||||||
|
resolve();
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// perform a user action that triggers passkey prompt
|
// perform a user action that triggers passkey prompt
|
||||||
await operationTrigger();
|
await operationTrigger();
|
||||||
|
|
||||||
// wait to receive the event that the passkey was successfully registered or verified
|
// wait to receive the event that the passkey was successfully registered or verified
|
||||||
await operationCompleted;
|
await operationCompleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function simulateSuccessfulPasskeyInput(client: CDPSession, authenticatorId: string, operationTrigger: () => Promise<void>) {
|
async function simulateSuccessfulPasskeyInput(
|
||||||
// initialize event listeners to wait for a successful passkey input event
|
client: CDPSession,
|
||||||
const operationCompleted = new Promise<void>(resolve => {
|
authenticatorId: string,
|
||||||
client.on('WebAuthn.credentialAsserted', () => {
|
operationTrigger: () => Promise<void>,
|
||||||
console.log('Credential Asserted!');
|
) {
|
||||||
resolve()
|
// initialize event listeners to wait for a successful passkey input event
|
||||||
});
|
const operationCompleted = new Promise<void>((resolve) => {
|
||||||
|
client.on("WebAuthn.credentialAsserted", () => {
|
||||||
|
console.log("Credential Asserted!");
|
||||||
|
resolve();
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// perform a user action that triggers passkey prompt
|
// perform a user action that triggers passkey prompt
|
||||||
await operationTrigger();
|
await operationTrigger();
|
||||||
|
|
||||||
// wait to receive the event that the passkey was successfully registered or verified
|
// wait to receive the event that the passkey was successfully registered or verified
|
||||||
await operationCompleted;
|
await operationCompleted;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,47 +1,57 @@
|
|||||||
import {expect, Page} from "@playwright/test";
|
import { expect, Page } from "@playwright/test";
|
||||||
|
|
||||||
const passwordField = 'password-text-input'
|
const passwordField = "password-text-input";
|
||||||
const passwordConfirmField = 'password-confirm-text-input'
|
const passwordConfirmField = "password-confirm-text-input";
|
||||||
const lengthCheck = "length-check"
|
const lengthCheck = "length-check";
|
||||||
const symbolCheck = "symbol-check"
|
const symbolCheck = "symbol-check";
|
||||||
const numberCheck = "number-check"
|
const numberCheck = "number-check";
|
||||||
const uppercaseCheck = "uppercase-check"
|
const uppercaseCheck = "uppercase-check";
|
||||||
const lowercaseCheck = "lowercase-check"
|
const lowercaseCheck = "lowercase-check";
|
||||||
const equalCheck = "equal-check"
|
const equalCheck = "equal-check";
|
||||||
|
|
||||||
const matchText = "Matches"
|
const matchText = "Matches";
|
||||||
const noMatchText = "Doesn\'t match"
|
const noMatchText = "Doesn't match";
|
||||||
|
|
||||||
export async function changePasswordScreen(page: Page, password1: string, password2: string) {
|
export async function changePasswordScreen(page: Page, password1: string, password2: string) {
|
||||||
await page.getByTestId(passwordField).pressSequentially(password1);
|
await page.getByTestId(passwordField).pressSequentially(password1);
|
||||||
await page.getByTestId(passwordConfirmField).pressSequentially(password2);
|
await page.getByTestId(passwordConfirmField).pressSequentially(password2);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function passwordScreen(page: Page, password: string) {
|
export async function passwordScreen(page: Page, password: string) {
|
||||||
await page.getByTestId(passwordField).pressSequentially(password);
|
await page.getByTestId(passwordField).pressSequentially(password);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function passwordScreenExpect(page: Page, password: string) {
|
export async function passwordScreenExpect(page: Page, password: string) {
|
||||||
await expect(page.getByTestId(passwordField)).toHaveValue(password);
|
await expect(page.getByTestId(passwordField)).toHaveValue(password);
|
||||||
await expect(page.getByTestId('error').locator('div')).toContainText("Could not verify password");
|
await expect(page.getByTestId("error").locator("div")).toContainText("Could not verify password");
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function changePasswordScreenExpect(page: Page, password1: string, password2: string, length: boolean, symbol: boolean, number: boolean, uppercase: boolean, lowercase: boolean, equals: boolean) {
|
export async function changePasswordScreenExpect(
|
||||||
await expect(page.getByTestId(passwordField)).toHaveValue(password1);
|
page: Page,
|
||||||
await expect(page.getByTestId(passwordConfirmField)).toHaveValue(password2);
|
password1: string,
|
||||||
|
password2: string,
|
||||||
|
length: boolean,
|
||||||
|
symbol: boolean,
|
||||||
|
number: boolean,
|
||||||
|
uppercase: boolean,
|
||||||
|
lowercase: boolean,
|
||||||
|
equals: boolean,
|
||||||
|
) {
|
||||||
|
await expect(page.getByTestId(passwordField)).toHaveValue(password1);
|
||||||
|
await expect(page.getByTestId(passwordConfirmField)).toHaveValue(password2);
|
||||||
|
|
||||||
await checkContent(page, lengthCheck, length);
|
await checkContent(page, lengthCheck, length);
|
||||||
await checkContent(page, symbolCheck, symbol);
|
await checkContent(page, symbolCheck, symbol);
|
||||||
await checkContent(page, numberCheck, number);
|
await checkContent(page, numberCheck, number);
|
||||||
await checkContent(page, uppercaseCheck, uppercase);
|
await checkContent(page, uppercaseCheck, uppercase);
|
||||||
await checkContent(page, lowercaseCheck, lowercase);
|
await checkContent(page, lowercaseCheck, lowercase);
|
||||||
await checkContent(page, equalCheck, equals);
|
await checkContent(page, equalCheck, equals);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkContent(page: Page, testid: string, match: boolean) {
|
async function checkContent(page: Page, testid: string, match: boolean) {
|
||||||
if (match) {
|
if (match) {
|
||||||
await expect(page.getByTestId(testid)).toContainText(matchText);
|
await expect(page.getByTestId(testid)).toContainText(matchText);
|
||||||
} else {
|
} else {
|
||||||
await expect(page.getByTestId(testid)).toContainText(noMatchText);
|
await expect(page.getByTestId(testid)).toContainText(noMatchText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,19 @@
|
|||||||
import {Page} from "@playwright/test";
|
import { Page } from "@playwright/test";
|
||||||
import {changePasswordScreen, passwordScreen} from "./password-screen";
|
import { changePasswordScreen, passwordScreen } from "./password-screen";
|
||||||
|
|
||||||
const passwordSubmitButton = "submit-button"
|
|
||||||
|
|
||||||
|
const passwordSubmitButton = "submit-button";
|
||||||
|
|
||||||
export async function startChangePassword(page: Page, loginname: string) {
|
export async function startChangePassword(page: Page, loginname: string) {
|
||||||
await page.goto('password/change?' + new URLSearchParams({loginName: loginname}));
|
await page.goto("password/change?" + new URLSearchParams({ loginName: loginname }));
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function changePassword(page: Page, loginname: string, password: string) {
|
export async function changePassword(page: Page, loginname: string, password: string) {
|
||||||
await startChangePassword(page, loginname);
|
await startChangePassword(page, loginname);
|
||||||
await changePasswordScreen(page, password, password)
|
await changePasswordScreen(page, password, password);
|
||||||
await page.getByTestId(passwordSubmitButton).click();
|
await page.getByTestId(passwordSubmitButton).click();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function password(page: Page, password: string) {
|
export async function password(page: Page, password: string) {
|
||||||
await passwordScreen(page, password)
|
await passwordScreen(page, password);
|
||||||
await page.getByTestId(passwordSubmitButton).click()
|
await page.getByTestId(passwordSubmitButton).click();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,27 @@
|
|||||||
import {Page} from "@playwright/test";
|
import { Page } from "@playwright/test";
|
||||||
|
|
||||||
const passwordField = 'password-text-input'
|
const passwordField = "password-text-input";
|
||||||
const passwordConfirmField = 'password-confirm-text-input'
|
const passwordConfirmField = "password-confirm-text-input";
|
||||||
|
|
||||||
export async function registerUserScreenPassword(page: Page, firstname: string, lastname: string, email: string) {
|
export async function registerUserScreenPassword(page: Page, firstname: string, lastname: string, email: string) {
|
||||||
await registerUserScreen(page, firstname, lastname, email)
|
await registerUserScreen(page, firstname, lastname, email);
|
||||||
await page.getByTestId('Password-radio').click();
|
await page.getByTestId("Password-radio").click();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function registerUserScreenPasskey(page: Page, firstname: string, lastname: string, email: string) {
|
export async function registerUserScreenPasskey(page: Page, firstname: string, lastname: string, email: string) {
|
||||||
await registerUserScreen(page, firstname, lastname, email)
|
await registerUserScreen(page, firstname, lastname, email);
|
||||||
await page.getByTestId('Passkeys-radio').click();
|
await page.getByTestId("Passkeys-radio").click();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function registerPasswordScreen(page: Page, password1: string, password2: string) {
|
export async function registerPasswordScreen(page: Page, password1: string, password2: string) {
|
||||||
await page.getByTestId(passwordField).pressSequentially(password1);
|
await page.getByTestId(passwordField).pressSequentially(password1);
|
||||||
await page.getByTestId(passwordConfirmField).pressSequentially(password2);
|
await page.getByTestId(passwordConfirmField).pressSequentially(password2);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function registerUserScreen(page: Page, firstname: string, lastname: string, email: string) {
|
export async function registerUserScreen(page: Page, firstname: string, lastname: string, email: string) {
|
||||||
await page.getByTestId('firstname-text-input').pressSequentially(firstname);
|
await page.getByTestId("firstname-text-input").pressSequentially(firstname);
|
||||||
await page.getByTestId('lastname-text-input').pressSequentially(lastname);
|
await page.getByTestId("lastname-text-input").pressSequentially(lastname);
|
||||||
await page.getByTestId('email-text-input').pressSequentially(email);
|
await page.getByTestId("email-text-input").pressSequentially(email);
|
||||||
await page.getByTestId('privacy-policy-checkbox').check();
|
await page.getByTestId("privacy-policy-checkbox").check();
|
||||||
await page.getByTestId('tos-checkbox').check();
|
await page.getByTestId("tos-checkbox").check();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,30 +1,30 @@
|
|||||||
import {test} from "@playwright/test";
|
import { test } from "@playwright/test";
|
||||||
import {registerWithPasskey, registerWithPassword} from './register';
|
import dotenv from "dotenv";
|
||||||
import {loginScreenExpect} from "./login";
|
import path from "path";
|
||||||
import {removeUserByUsername} from './zitadel';
|
import { loginScreenExpect } from "./login";
|
||||||
import path from 'path';
|
import { registerWithPasskey, registerWithPassword } from "./register";
|
||||||
import dotenv from 'dotenv';
|
import { removeUserByUsername } from "./zitadel";
|
||||||
|
|
||||||
// Read from ".env" file.
|
// Read from ".env" file.
|
||||||
dotenv.config({path: path.resolve(__dirname, '.env.local')});
|
dotenv.config({ path: path.resolve(__dirname, ".env.local") });
|
||||||
|
|
||||||
test("register with password", async ({page}) => {
|
test("register with password", async ({ page }) => {
|
||||||
const username = "register-password@example.com"
|
const username = "register-password@example.com";
|
||||||
const password = "Password1!"
|
const password = "Password1!";
|
||||||
const firstname = "firstname"
|
const firstname = "firstname";
|
||||||
const lastname = "lastname"
|
const lastname = "lastname";
|
||||||
|
|
||||||
await removeUserByUsername(username)
|
await removeUserByUsername(username);
|
||||||
await registerWithPassword(page, firstname, lastname, username, password, password)
|
await registerWithPassword(page, firstname, lastname, username, password, password);
|
||||||
await loginScreenExpect(page, firstname + " " + lastname);
|
await loginScreenExpect(page, firstname + " " + lastname);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("register with passkey", async ({page}) => {
|
test("register with passkey", async ({ page }) => {
|
||||||
const username = "register-passkey@example.com"
|
const username = "register-passkey@example.com";
|
||||||
const firstname = "firstname"
|
const firstname = "firstname";
|
||||||
const lastname = "lastname"
|
const lastname = "lastname";
|
||||||
|
|
||||||
await removeUserByUsername(username)
|
await removeUserByUsername(username);
|
||||||
await registerWithPasskey(page, firstname, lastname, username)
|
await registerWithPasskey(page, firstname, lastname, username);
|
||||||
await loginScreenExpect(page, firstname + " " + lastname);
|
await loginScreenExpect(page, firstname + " " + lastname);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,18 +1,25 @@
|
|||||||
import {Page} from "@playwright/test";
|
import { Page } from "@playwright/test";
|
||||||
import {passkeyRegister} from './passkey';
|
import { passkeyRegister } from "./passkey";
|
||||||
import {registerPasswordScreen, registerUserScreenPasskey, registerUserScreenPassword} from './register-screen';
|
import { registerPasswordScreen, registerUserScreenPasskey, registerUserScreenPassword } from "./register-screen";
|
||||||
|
|
||||||
export async function registerWithPassword(page: Page, firstname: string, lastname: string, email: string, password1: string, password2: string) {
|
export async function registerWithPassword(
|
||||||
await page.goto('/register');
|
page: Page,
|
||||||
await registerUserScreenPassword(page, firstname, lastname, email)
|
firstname: string,
|
||||||
await page.getByTestId('submit-button').click();
|
lastname: string,
|
||||||
await registerPasswordScreen(page, password1, password2)
|
email: string,
|
||||||
await page.getByTestId('submit-button').click();
|
password1: string,
|
||||||
|
password2: string,
|
||||||
|
) {
|
||||||
|
await page.goto("/register");
|
||||||
|
await registerUserScreenPassword(page, firstname, lastname, email);
|
||||||
|
await page.getByTestId("submit-button").click();
|
||||||
|
await registerPasswordScreen(page, password1, password2);
|
||||||
|
await page.getByTestId("submit-button").click();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function registerWithPasskey(page: Page, firstname: string, lastname: string, email: string): Promise<string> {
|
export async function registerWithPasskey(page: Page, firstname: string, lastname: string, email: string): Promise<string> {
|
||||||
await page.goto('/register');
|
await page.goto("/register");
|
||||||
await registerUserScreenPasskey(page, firstname, lastname, email)
|
await registerUserScreenPasskey(page, firstname, lastname, email);
|
||||||
await page.getByTestId('submit-button').click();
|
await page.getByTestId("submit-button").click();
|
||||||
return await passkeyRegister(page)
|
return await passkeyRegister(page);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,196 +1,195 @@
|
|||||||
|
import { Page } from "@playwright/test";
|
||||||
import fetch from "node-fetch";
|
import fetch from "node-fetch";
|
||||||
import {Page} from "@playwright/test";
|
import { registerWithPasskey } from "./register";
|
||||||
import {registerWithPasskey} from "./register";
|
import { getUserByUsername, removeUser } from "./zitadel";
|
||||||
import {getUserByUsername, removeUser} from './zitadel';
|
|
||||||
|
|
||||||
export interface userProps {
|
export interface userProps {
|
||||||
email: string;
|
email: string;
|
||||||
firstName: string;
|
firstName: string;
|
||||||
lastName: string;
|
lastName: string;
|
||||||
organization: string;
|
organization: string;
|
||||||
password: string;
|
password: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
class User {
|
class User {
|
||||||
private readonly props: userProps;
|
private readonly props: userProps;
|
||||||
private user: string;
|
private user: string;
|
||||||
|
|
||||||
constructor(userProps: userProps) {
|
constructor(userProps: userProps) {
|
||||||
this.props = userProps;
|
this.props = userProps;
|
||||||
|
}
|
||||||
|
|
||||||
|
async ensure(page: Page) {
|
||||||
|
await this.remove();
|
||||||
|
|
||||||
|
const body = {
|
||||||
|
username: this.props.email,
|
||||||
|
organization: {
|
||||||
|
orgId: this.props.organization,
|
||||||
|
},
|
||||||
|
profile: {
|
||||||
|
givenName: this.props.firstName,
|
||||||
|
familyName: this.props.lastName,
|
||||||
|
},
|
||||||
|
email: {
|
||||||
|
email: this.props.email,
|
||||||
|
isVerified: true,
|
||||||
|
},
|
||||||
|
password: {
|
||||||
|
password: this.props.password!,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await fetch(process.env.ZITADEL_API_URL! + "/v2/users/human", {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify(body),
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: "Bearer " + process.env.ZITADEL_SERVICE_USER_TOKEN!,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (response.statusCode >= 400 && response.statusCode != 409) {
|
||||||
|
const error = "HTTP Error: " + response.statusCode + " - " + response.statusMessage;
|
||||||
|
console.error(error);
|
||||||
|
throw new Error(error);
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
async ensure(page: Page) {
|
async remove() {
|
||||||
await this.remove()
|
const resp = await getUserByUsername(this.getUsername());
|
||||||
|
if (!resp || !resp.result || !resp.result[0]) {
|
||||||
const body = {
|
return;
|
||||||
username: this.props.email,
|
|
||||||
organization: {
|
|
||||||
orgId: this.props.organization
|
|
||||||
},
|
|
||||||
profile: {
|
|
||||||
givenName: this.props.firstName,
|
|
||||||
familyName: this.props.lastName,
|
|
||||||
},
|
|
||||||
email: {
|
|
||||||
email: this.props.email,
|
|
||||||
isVerified: true,
|
|
||||||
},
|
|
||||||
password: {
|
|
||||||
password: this.props.password!,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await fetch(process.env.ZITADEL_API_URL! + "/v2/users/human", {
|
|
||||||
method: 'POST',
|
|
||||||
body: JSON.stringify(body),
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'Authorization': "Bearer " + process.env.ZITADEL_SERVICE_USER_TOKEN!
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (response.statusCode >= 400 && response.statusCode != 409) {
|
|
||||||
const error = 'HTTP Error: ' + response.statusCode + ' - ' + response.statusMessage;
|
|
||||||
console.error(error);
|
|
||||||
throw new Error(error);
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
await removeUser(resp.result[0].userId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
async remove() {
|
public setUserId(userId: string) {
|
||||||
const resp = await getUserByUsername(this.getUsername())
|
this.user = userId;
|
||||||
if (!resp || !resp.result || !resp.result[0]) {
|
}
|
||||||
return
|
|
||||||
}
|
|
||||||
await removeUser(resp.result[0].userId)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
public setUserId(userId: string) {
|
public getUserId() {
|
||||||
this.user = userId
|
return this.user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getUserId() {
|
public getUsername() {
|
||||||
return this.user;
|
return this.props.email;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getUsername() {
|
public getPassword() {
|
||||||
return this.props.email;
|
return this.props.password;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getPassword() {
|
public getFirstname() {
|
||||||
return this.props.password;
|
return this.props.firstName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getFirstname() {
|
public getLastname() {
|
||||||
return this.props.firstName
|
return this.props.lastName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getLastname() {
|
public getFullName() {
|
||||||
return this.props.lastName
|
return this.props.firstName + " " + this.props.lastName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getFullName() {
|
|
||||||
return this.props.firstName + " " + this.props.lastName
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class PasswordUser extends User {
|
export class PasswordUser extends User {}
|
||||||
}
|
|
||||||
|
|
||||||
export enum OtpType {
|
export enum OtpType {
|
||||||
sms = "sms",
|
sms = "sms",
|
||||||
email = "email",
|
email = "email",
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface otpUserProps {
|
export interface otpUserProps {
|
||||||
email: string;
|
email: string;
|
||||||
firstName: string;
|
firstName: string;
|
||||||
lastName: string;
|
lastName: string;
|
||||||
organization: string;
|
organization: string;
|
||||||
password: string,
|
password: string;
|
||||||
type: OtpType,
|
type: OtpType;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class PasswordUserWithOTP extends User {
|
export class PasswordUserWithOTP extends User {
|
||||||
private type: OtpType
|
private type: OtpType;
|
||||||
private code: string
|
private code: string;
|
||||||
|
|
||||||
constructor(props: otpUserProps) {
|
constructor(props: otpUserProps) {
|
||||||
super({
|
super({
|
||||||
email: props.email,
|
email: props.email,
|
||||||
firstName: props.firstName,
|
firstName: props.firstName,
|
||||||
lastName: props.lastName,
|
lastName: props.lastName,
|
||||||
organization: props.organization,
|
organization: props.organization,
|
||||||
password: props.password,
|
password: props.password,
|
||||||
})
|
});
|
||||||
this.type = props.type
|
this.type = props.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
async ensure(page: Page) {
|
||||||
|
await super.ensure(page);
|
||||||
|
|
||||||
|
let url = "otp_";
|
||||||
|
switch (this.type) {
|
||||||
|
case OtpType.sms:
|
||||||
|
url = url + "sms";
|
||||||
|
case OtpType.email:
|
||||||
|
url = url + "email";
|
||||||
}
|
}
|
||||||
|
|
||||||
async ensure(page: Page) {
|
const response = await fetch(process.env.ZITADEL_API_URL! + "/v2/users/" + this.getUserId() + "/" + url, {
|
||||||
await super.ensure(page)
|
method: "POST",
|
||||||
|
headers: {
|
||||||
let url = "otp_"
|
"Content-Type": "application/json",
|
||||||
switch (this.type) {
|
Authorization: "Bearer " + process.env.ZITADEL_SERVICE_USER_TOKEN!,
|
||||||
case OtpType.sms:
|
},
|
||||||
url = url + "sms"
|
});
|
||||||
case OtpType.email:
|
if (response.statusCode >= 400 && response.statusCode != 409) {
|
||||||
url = url + "email"
|
const error = "HTTP Error: " + response.statusCode + " - " + response.statusMessage;
|
||||||
}
|
console.error(error);
|
||||||
|
throw new Error(error);
|
||||||
const response = await fetch(process.env.ZITADEL_API_URL! + "/v2/users/" + this.getUserId() + "/" + url, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'Authorization': "Bearer " + process.env.ZITADEL_SERVICE_USER_TOKEN!
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (response.statusCode >= 400 && response.statusCode != 409) {
|
|
||||||
const error = 'HTTP Error: ' + response.statusCode + ' - ' + response.statusMessage;
|
|
||||||
console.error(error);
|
|
||||||
throw new Error(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: get code from SMS or Email provider
|
|
||||||
this.code = ""
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public getCode() {
|
// TODO: get code from SMS or Email provider
|
||||||
return this.code
|
this.code = "";
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getCode() {
|
||||||
|
return this.code;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface passkeyUserProps {
|
export interface passkeyUserProps {
|
||||||
email: string;
|
email: string;
|
||||||
firstName: string;
|
firstName: string;
|
||||||
lastName: string;
|
lastName: string;
|
||||||
organization: string;
|
organization: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class PasskeyUser extends User {
|
export class PasskeyUser extends User {
|
||||||
private authenticatorId: string
|
private authenticatorId: string;
|
||||||
|
|
||||||
constructor(props: passkeyUserProps) {
|
constructor(props: passkeyUserProps) {
|
||||||
super({
|
super({
|
||||||
email: props.email,
|
email: props.email,
|
||||||
firstName: props.firstName,
|
firstName: props.firstName,
|
||||||
lastName: props.lastName,
|
lastName: props.lastName,
|
||||||
organization: props.organization,
|
organization: props.organization,
|
||||||
password: ""
|
password: "",
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async ensure(page: Page) {
|
public async ensure(page: Page) {
|
||||||
await this.remove()
|
await this.remove();
|
||||||
const authId = await registerWithPasskey(page, this.getFirstname(), this.getLastname(), this.getUsername())
|
const authId = await registerWithPasskey(page, this.getFirstname(), this.getLastname(), this.getUsername());
|
||||||
this.authenticatorId = authId
|
this.authenticatorId = authId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async remove() {
|
public async remove() {
|
||||||
await super.remove()
|
await super.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
public getAuthenticatorId(): string {
|
public getAuthenticatorId(): string {
|
||||||
return this.authenticatorId
|
return this.authenticatorId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,26 @@
|
|||||||
import {test as base} from "@playwright/test";
|
import { test as base } from "@playwright/test";
|
||||||
import path from 'path';
|
import dotenv from "dotenv";
|
||||||
import dotenv from 'dotenv';
|
import path from "path";
|
||||||
import {PasskeyUser} from "./user";
|
import { loginScreenExpect, loginWithPasskey } from "./login";
|
||||||
import {loginScreenExpect, loginWithPasskey} from "./login";
|
import { PasskeyUser } from "./user";
|
||||||
|
|
||||||
// Read from ".env" file.
|
// Read from ".env" file.
|
||||||
dotenv.config({path: path.resolve(__dirname, '.env.local')});
|
dotenv.config({ path: path.resolve(__dirname, ".env.local") });
|
||||||
|
|
||||||
const test = base.extend<{ user: PasskeyUser }>({
|
const test = base.extend<{ user: PasskeyUser }>({
|
||||||
user: async ({page}, use) => {
|
user: async ({ page }, use) => {
|
||||||
const user = new PasskeyUser({
|
const user = new PasskeyUser({
|
||||||
email: "passkey@example.com",
|
email: "passkey@example.com",
|
||||||
firstName: "first",
|
firstName: "first",
|
||||||
lastName: "last",
|
lastName: "last",
|
||||||
organization: "",
|
organization: "",
|
||||||
});
|
});
|
||||||
await user.ensure(page);
|
await user.ensure(page);
|
||||||
await use(user);
|
await use(user);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
test("username and passkey login", async ({user, page}) => {
|
test("username and passkey login", async ({ user, page }) => {
|
||||||
await loginWithPasskey(page, user.getAuthenticatorId(), user.getUsername())
|
await loginWithPasskey(page, user.getAuthenticatorId(), user.getUsername());
|
||||||
await loginScreenExpect(page, user.getFullName());
|
await loginScreenExpect(page, user.getFullName());
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,41 +1,41 @@
|
|||||||
import {test as base} from "@playwright/test";
|
import { test as base } from "@playwright/test";
|
||||||
import {PasswordUser} from './user';
|
import dotenv from "dotenv";
|
||||||
import path from 'path';
|
import path from "path";
|
||||||
import dotenv from 'dotenv';
|
import { loginScreenExpect, loginWithPassword } from "./login";
|
||||||
import {loginScreenExpect, loginWithPassword} from "./login";
|
import { changePassword, startChangePassword } from "./password";
|
||||||
import {changePassword, startChangePassword} from "./password";
|
import { changePasswordScreen, changePasswordScreenExpect } from "./password-screen";
|
||||||
import {changePasswordScreen, changePasswordScreenExpect} from "./password-screen";
|
import { PasswordUser } from "./user";
|
||||||
|
|
||||||
// Read from ".env" file.
|
// Read from ".env" file.
|
||||||
dotenv.config({path: path.resolve(__dirname, '.env.local')});
|
dotenv.config({ path: path.resolve(__dirname, ".env.local") });
|
||||||
|
|
||||||
const test = base.extend<{ user: PasswordUser }>({
|
const test = base.extend<{ user: PasswordUser }>({
|
||||||
user: async ({page}, use) => {
|
user: async ({ page }, use) => {
|
||||||
const user = new PasswordUser({
|
const user = new PasswordUser({
|
||||||
email: "password-changed@example.com",
|
email: "password-changed@example.com",
|
||||||
firstName: "first",
|
firstName: "first",
|
||||||
lastName: "last",
|
lastName: "last",
|
||||||
password: "Password1!",
|
password: "Password1!",
|
||||||
organization: "",
|
organization: "",
|
||||||
});
|
});
|
||||||
await user.ensure(page);
|
await user.ensure(page);
|
||||||
await use(user);
|
await use(user);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
test("username and password changed login", async ({user, page}) => {
|
test("username and password changed login", async ({ user, page }) => {
|
||||||
const changedPw = "ChangedPw1!"
|
const changedPw = "ChangedPw1!";
|
||||||
await loginWithPassword(page, user.getUsername(), user.getPassword())
|
await loginWithPassword(page, user.getUsername(), user.getPassword());
|
||||||
await changePassword(page, user.getUsername(), changedPw)
|
await changePassword(page, user.getUsername(), changedPw);
|
||||||
await loginWithPassword(page, user.getUsername(), changedPw)
|
await loginWithPassword(page, user.getUsername(), changedPw);
|
||||||
await loginScreenExpect(page, user.getFullName());
|
await loginScreenExpect(page, user.getFullName());
|
||||||
});
|
});
|
||||||
|
|
||||||
test("password not with desired complexity", async ({user, page}) => {
|
test("password not with desired complexity", async ({ user, page }) => {
|
||||||
const changedPw1 = "change"
|
const changedPw1 = "change";
|
||||||
const changedPw2 = "chang"
|
const changedPw2 = "chang";
|
||||||
await loginWithPassword(page, user.getUsername(), user.getPassword())
|
await loginWithPassword(page, user.getUsername(), user.getPassword());
|
||||||
await startChangePassword(page, user.getUsername());
|
await startChangePassword(page, user.getUsername());
|
||||||
await changePasswordScreen(page, changedPw1, changedPw2)
|
await changePasswordScreen(page, changedPw1, changedPw2);
|
||||||
await changePasswordScreenExpect(page, changedPw1, changedPw2, false, false, false, false, true, false)
|
await changePasswordScreenExpect(page, changedPw1, changedPw2, false, false, false, false, true, false);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,36 +1,32 @@
|
|||||||
import {test as base} from "@playwright/test";
|
import { test as base } from "@playwright/test";
|
||||||
import {OtpType, PasswordUserWithOTP} from './user';
|
import dotenv from "dotenv";
|
||||||
import path from 'path';
|
import path from "path";
|
||||||
import dotenv from 'dotenv';
|
import { loginScreenExpect, loginWithPassword } from "./login";
|
||||||
import {loginScreenExpect, loginWithPassword} from "./login";
|
import { OtpType, PasswordUserWithOTP } from "./user";
|
||||||
import {startSink} from "./otp";
|
|
||||||
|
|
||||||
// Read from ".env" file.
|
// Read from ".env" file.
|
||||||
dotenv.config({path: path.resolve(__dirname, '.env.local')});
|
dotenv.config({ path: path.resolve(__dirname, ".env.local") });
|
||||||
|
|
||||||
const test = base.extend<{ user: PasswordUserWithOTP }>({
|
const test = base.extend<{ user: PasswordUserWithOTP }>({
|
||||||
user: async ({page}, use) => {
|
user: async ({ page }, use) => {
|
||||||
const user = new PasswordUserWithOTP({
|
const user = new PasswordUserWithOTP({
|
||||||
email: "otp_sms@example.com",
|
email: "otp_sms@example.com",
|
||||||
firstName: "first",
|
firstName: "first",
|
||||||
lastName: "last",
|
lastName: "last",
|
||||||
password: "Password1!",
|
password: "Password1!",
|
||||||
organization: "",
|
organization: "",
|
||||||
type: OtpType.sms,
|
type: OtpType.sms,
|
||||||
});
|
});
|
||||||
|
|
||||||
await user.ensure(page);
|
await user.ensure(page);
|
||||||
await use(user);
|
await use(user);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
test("username, password and otp login", async ({user, page}) => {
|
test("username, password and otp login", async ({ user, page }) => {
|
||||||
//const server = startSink()
|
//const server = startSink()
|
||||||
await loginWithPassword(page, user.getUsername(), user.getPassword())
|
await loginWithPassword(page, user.getUsername(), user.getPassword());
|
||||||
|
|
||||||
|
await loginScreenExpect(page, user.getFullName());
|
||||||
await loginScreenExpect(page, user.getFullName());
|
//server.close()
|
||||||
//server.close()
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,50 +1,52 @@
|
|||||||
import fetch from "node-fetch";
|
import fetch from "node-fetch";
|
||||||
|
|
||||||
export async function removeUserByUsername(username: string) {
|
export async function removeUserByUsername(username: string) {
|
||||||
const resp = await getUserByUsername(username)
|
const resp = await getUserByUsername(username);
|
||||||
if (!resp || !resp.result || !resp.result[0]) {
|
if (!resp || !resp.result || !resp.result[0]) {
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
await removeUser(resp.result[0].userId)
|
await removeUser(resp.result[0].userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function removeUser(id: string) {
|
export async function removeUser(id: string) {
|
||||||
const response = await fetch(process.env.ZITADEL_API_URL! + "/v2/users/" + id, {
|
const response = await fetch(process.env.ZITADEL_API_URL! + "/v2/users/" + id, {
|
||||||
method: 'DELETE',
|
method: "DELETE",
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': "Bearer " + process.env.ZITADEL_SERVICE_USER_TOKEN!
|
Authorization: "Bearer " + process.env.ZITADEL_SERVICE_USER_TOKEN!,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
if (response.statusCode >= 400 && response.statusCode != 404) {
|
if (response.statusCode >= 400 && response.statusCode != 404) {
|
||||||
const error = 'HTTP Error: ' + response.statusCode + ' - ' + response.statusMessage;
|
const error = "HTTP Error: " + response.statusCode + " - " + response.statusMessage;
|
||||||
console.error(error);
|
console.error(error);
|
||||||
throw new Error(error);
|
throw new Error(error);
|
||||||
}
|
}
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getUserByUsername(username: string) {
|
export async function getUserByUsername(username: string) {
|
||||||
const listUsersBody = {
|
const listUsersBody = {
|
||||||
queries: [{
|
queries: [
|
||||||
userNameQuery: {
|
{
|
||||||
userName: username,
|
userNameQuery: {
|
||||||
}
|
userName: username,
|
||||||
}]
|
},
|
||||||
}
|
},
|
||||||
const jsonBody = JSON.stringify(listUsersBody)
|
],
|
||||||
const registerResponse = await fetch(process.env.ZITADEL_API_URL! + "/v2/users", {
|
};
|
||||||
method: 'POST',
|
const jsonBody = JSON.stringify(listUsersBody);
|
||||||
body: jsonBody,
|
const registerResponse = await fetch(process.env.ZITADEL_API_URL! + "/v2/users", {
|
||||||
headers: {
|
method: "POST",
|
||||||
'Content-Type': 'application/json',
|
body: jsonBody,
|
||||||
'Authorization': "Bearer " + process.env.ZITADEL_SERVICE_USER_TOKEN!
|
headers: {
|
||||||
}
|
"Content-Type": "application/json",
|
||||||
});
|
Authorization: "Bearer " + process.env.ZITADEL_SERVICE_USER_TOKEN!,
|
||||||
if (registerResponse.statusCode >= 400) {
|
},
|
||||||
const error = 'HTTP Error: ' + registerResponse.statusCode + ' - ' + registerResponse.statusMessage;
|
});
|
||||||
console.error(error);
|
if (registerResponse.statusCode >= 400) {
|
||||||
throw new Error(error);
|
const error = "HTTP Error: " + registerResponse.statusCode + " - " + registerResponse.statusMessage;
|
||||||
}
|
console.error(error);
|
||||||
const respJson = await registerResponse.json()
|
throw new Error(error);
|
||||||
return respJson
|
}
|
||||||
}
|
const respJson = await registerResponse.json();
|
||||||
|
return respJson;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {defineConfig, devices} from "@playwright/test";
|
import { defineConfig, devices } from "@playwright/test";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read environment variables from file.
|
* Read environment variables from file.
|
||||||
@@ -12,33 +12,33 @@ import {defineConfig, devices} from "@playwright/test";
|
|||||||
* See https://playwright.dev/docs/test-configuration.
|
* See https://playwright.dev/docs/test-configuration.
|
||||||
*/
|
*/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
testDir: "./acceptance/tests",
|
testDir: "./acceptance/tests",
|
||||||
/* Run tests in files in parallel */
|
/* Run tests in files in parallel */
|
||||||
fullyParallel: true,
|
fullyParallel: true,
|
||||||
/* Fail the build on CI if you accidentally left test.only in the source code. */
|
/* Fail the build on CI if you accidentally left test.only in the source code. */
|
||||||
forbidOnly: !!process.env.CI,
|
forbidOnly: !!process.env.CI,
|
||||||
/* Retry on CI only */
|
/* Retry on CI only */
|
||||||
retries: process.env.CI ? 2 : 0,
|
retries: process.env.CI ? 2 : 0,
|
||||||
/* Opt out of parallel tests on CI. */
|
/* Opt out of parallel tests on CI. */
|
||||||
workers: process.env.CI ? 1 : undefined,
|
workers: process.env.CI ? 1 : undefined,
|
||||||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
|
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
|
||||||
reporter: "html",
|
reporter: "html",
|
||||||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
|
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
|
||||||
use: {
|
use: {
|
||||||
/* Base URL to use in actions like `await page.goto('/')`. */
|
/* Base URL to use in actions like `await page.goto('/')`. */
|
||||||
baseURL: "http://localhost:3000",
|
baseURL: "http://localhost:3000",
|
||||||
|
|
||||||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
|
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
|
||||||
trace: "on-first-retry",
|
trace: "on-first-retry",
|
||||||
|
},
|
||||||
|
|
||||||
|
/* Configure projects for major browsers */
|
||||||
|
projects: [
|
||||||
|
{
|
||||||
|
name: "chromium",
|
||||||
|
use: { ...devices["Desktop Chrome"] },
|
||||||
},
|
},
|
||||||
|
/*
|
||||||
/* Configure projects for major browsers */
|
|
||||||
projects: [
|
|
||||||
{
|
|
||||||
name: "chromium",
|
|
||||||
use: {...devices["Desktop Chrome"]},
|
|
||||||
},
|
|
||||||
/*
|
|
||||||
{
|
{
|
||||||
name: "firefox",
|
name: "firefox",
|
||||||
use: { ...devices["Desktop Firefox"] },
|
use: { ...devices["Desktop Firefox"] },
|
||||||
@@ -50,32 +50,32 @@ export default defineConfig({
|
|||||||
},
|
},
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Test against mobile viewports. */
|
/* Test against mobile viewports. */
|
||||||
// {
|
// {
|
||||||
// name: 'Mobile Chrome',
|
// name: 'Mobile Chrome',
|
||||||
// use: { ...devices['Pixel 5'] },
|
// use: { ...devices['Pixel 5'] },
|
||||||
// },
|
// },
|
||||||
// {
|
// {
|
||||||
// name: 'Mobile Safari',
|
// name: 'Mobile Safari',
|
||||||
// use: { ...devices['iPhone 12'] },
|
// use: { ...devices['iPhone 12'] },
|
||||||
// },
|
// },
|
||||||
|
|
||||||
/* Test against branded browsers. */
|
/* Test against branded browsers. */
|
||||||
// {
|
// {
|
||||||
// name: 'Microsoft Edge',
|
// name: 'Microsoft Edge',
|
||||||
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
|
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
|
||||||
// },
|
// },
|
||||||
// {
|
// {
|
||||||
// name: 'Google Chrome',
|
// name: 'Google Chrome',
|
||||||
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
|
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
|
||||||
// },
|
// },
|
||||||
],
|
],
|
||||||
|
|
||||||
/* Run local dev server before starting the tests */
|
/* Run local dev server before starting the tests */
|
||||||
webServer: {
|
webServer: {
|
||||||
command: "pnpm start:built",
|
command: "pnpm start:built",
|
||||||
url: "http://127.0.0.1:3000",
|
url: "http://127.0.0.1:3000",
|
||||||
reuseExistingServer: !process.env.CI,
|
reuseExistingServer: !process.env.CI,
|
||||||
timeout: 5 * 60_000,
|
timeout: 5 * 60_000,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user