mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-11 19:42:16 +00:00
Merge branch 'acceptance-test-suite' into test_definitions
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
services:
|
||||
zitadel:
|
||||
user: "${ZITADEL_DEV_UID}"
|
||||
image: "${ZITADEL_IMAGE:-ghcr.io/zitadel/zitadel:latest}"
|
||||
image: ghcr.io/zitadel/zitadel:v2.65.0
|
||||
command: 'start-from-init --masterkey "MasterkeyNeedsToHave32Characters" --tlsMode disabled --config /zitadel.yaml --steps /zitadel.yaml'
|
||||
ports:
|
||||
- "8080:8080"
|
||||
@@ -13,8 +13,8 @@ services:
|
||||
condition: "service_healthy"
|
||||
|
||||
db:
|
||||
restart: 'always'
|
||||
image: "${POSTGRES_IMAGE:-postgres:latest}"
|
||||
restart: "always"
|
||||
image: postgres:17.0-alpine3.19
|
||||
environment:
|
||||
- POSTGRES_USER=zitadel
|
||||
- PGUSER=zitadel
|
||||
@@ -23,21 +23,16 @@ services:
|
||||
command: postgres -c shared_preload_libraries=pg_stat_statements -c pg_stat_statements.track=all -c shared_buffers=1GB -c work_mem=16MB -c effective_io_concurrency=100 -c wal_level=minimal -c archive_mode=off -c max_wal_senders=0
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready"]
|
||||
interval: '10s'
|
||||
timeout: '30s'
|
||||
interval: "10s"
|
||||
timeout: "30s"
|
||||
retries: 5
|
||||
start_period: '20s'
|
||||
start_period: "20s"
|
||||
ports:
|
||||
- 5432:5432
|
||||
|
||||
wait_for_zitadel:
|
||||
image: curlimages/curl:8.00.1
|
||||
command:
|
||||
[
|
||||
"/bin/sh",
|
||||
"-c",
|
||||
"i=0; while ! curl http://zitadel:8080/debug/ready && [ $$i -lt 30 ]; do sleep 1; i=$$((i+1)); done; [ $$i -eq 120 ] && exit 1 || exit 0",
|
||||
]
|
||||
command: /bin/sh -c "until curl -s -o /dev/null -i -f http://zitadel:8080/debug/ready; do echo 'waiting' && sleep 1; done; echo 'ready' && sleep 5;" || false
|
||||
depends_on:
|
||||
- zitadel
|
||||
|
||||
@@ -49,9 +44,11 @@ services:
|
||||
PAT_FILE: /pat/zitadel-admin-sa.pat
|
||||
ZITADEL_API_INTERNAL_URL: http://zitadel:8080
|
||||
WRITE_ENVIRONMENT_FILE: /apps/login/.env.local
|
||||
WRITE_TEST_ENVIRONMENT_FILE: /acceptance/tests/.env.local
|
||||
volumes:
|
||||
- "./pat:/pat"
|
||||
- "../apps/login:/apps/login"
|
||||
- "../acceptance/tests:/acceptance/tests"
|
||||
depends_on:
|
||||
wait_for_zitadel:
|
||||
condition: "service_completed_successfully"
|
||||
|
||||
@@ -26,9 +26,30 @@ fi
|
||||
|
||||
WRITE_ENVIRONMENT_FILE=${WRITE_ENVIRONMENT_FILE:-$(dirname "$0")/../apps/login/.env.local}
|
||||
echo "Writing environment file to ${WRITE_ENVIRONMENT_FILE} when done."
|
||||
WRITE_TEST_ENVIRONMENT_FILE=${WRITE_TEST_ENVIRONMENT_FILE:-$(dirname "$0")/../acceptance/tests/.env.local}
|
||||
echo "Writing environment file to ${WRITE_TEST_ENVIRONMENT_FILE} when done."
|
||||
|
||||
echo "ZITADEL_API_URL=${ZITADEL_API_URL}
|
||||
ZITADEL_SERVICE_USER_ID=${ZITADEL_SERVICE_USER_ID}
|
||||
ZITADEL_SERVICE_USER_TOKEN=${PAT}" > ${WRITE_ENVIRONMENT_FILE}
|
||||
ZITADEL_SERVICE_USER_TOKEN=${PAT}
|
||||
DEBUG=true"| tee "${WRITE_ENVIRONMENT_FILE}" "${WRITE_TEST_ENVIRONMENT_FILE}" > /dev/null
|
||||
echo "Wrote environment file ${WRITE_ENVIRONMENT_FILE}"
|
||||
cat ${WRITE_ENVIRONMENT_FILE}
|
||||
|
||||
echo "Wrote environment file ${WRITE_TEST_ENVIRONMENT_FILE}"
|
||||
cat ${WRITE_TEST_ENVIRONMENT_FILE}
|
||||
|
||||
DEFAULTORG_RESPONSE_RESULTS=0
|
||||
# waiting for default organization
|
||||
until [ ${DEFAULTORG_RESPONSE_RESULTS} -eq 1 ]
|
||||
do
|
||||
DEFAULTORG_RESPONSE=$(curl -s --request POST \
|
||||
--url "${ZITADEL_API_INTERNAL_URL}/v2/organizations/_search" \
|
||||
--header "Authorization: Bearer ${PAT}" \
|
||||
--header "Host: ${ZITADEL_API_DOMAIN}" \
|
||||
--header "Content-Type: application/json" \
|
||||
-d "{\"queries\": [{\"defaultQuery\":{}}]}" )
|
||||
echo "Received default organization response: ${DEFAULTORG_RESPONSE}"
|
||||
DEFAULTORG_RESPONSE_RESULTS=$(echo $DEFAULTORG_RESPONSE | jq -r '.result | length')
|
||||
echo "Received default organization response result: ${DEFAULTORG_RESPONSE_RESULTS}"
|
||||
done
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {test} from "@playwright/test";
|
||||
import {loginScreenExpect, loginWithPassword} from "./login";
|
||||
import { test } from "@playwright/test";
|
||||
import { loginScreenExpect, loginWithPassword } from "./login";
|
||||
|
||||
test("admin login", async ({page}) => {
|
||||
await loginWithPassword(page, "zitadel-admin@zitadel.localhost", "Password1.")
|
||||
await loginScreenExpect(page, "ZITADEL Admin");
|
||||
test("admin login", async ({ page }) => {
|
||||
await loginWithPassword(page, "zitadel-admin@zitadel.localhost", "Password1!");
|
||||
await loginScreenExpect(page, "ZITADEL Admin");
|
||||
});
|
||||
|
||||
@@ -1,29 +1,28 @@
|
||||
import {expect, Page} from "@playwright/test";
|
||||
import {loginname} from "./loginname";
|
||||
import {password} from "./password";
|
||||
import { expect, Page } from "@playwright/test";
|
||||
import { loginname } from "./loginname";
|
||||
import { password } from "./password";
|
||||
|
||||
export async function startLogin(page: Page) {
|
||||
await page.goto("/loginname");
|
||||
await page.goto("/loginname");
|
||||
}
|
||||
|
||||
export async function loginWithPassword(page: Page, username: string, pw: string) {
|
||||
await startLogin(page);
|
||||
await loginname(page, username);
|
||||
await password(page, pw);
|
||||
await startLogin(page);
|
||||
await loginname(page, username);
|
||||
await password(page, pw);
|
||||
}
|
||||
|
||||
export async function loginWithPasskey(page: Page, authenticatorId: string, username: string) {
|
||||
await startLogin(page);
|
||||
await loginname(page, username);
|
||||
// await passkey(page, authenticatorId);
|
||||
await startLogin(page);
|
||||
await loginname(page, username);
|
||||
// await passkey(page, authenticatorId);
|
||||
}
|
||||
|
||||
export async function loginScreenExpect(page: Page, fullName: string) {
|
||||
await expect(page.getByRole('heading')).toContainText(fullName);
|
||||
await expect(page).toHaveURL(/signedin.*/);
|
||||
await expect(page.getByRole("heading")).toContainText(fullName);
|
||||
}
|
||||
|
||||
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) {
|
||||
await page.getByTestId(usernameUserInput).pressSequentially(username);
|
||||
await page.getByTestId(usernameUserInput).pressSequentially(username);
|
||||
}
|
||||
|
||||
export async function loginnameScreenExpect(page: Page, username: string) {
|
||||
await expect(page.getByTestId(usernameUserInput)).toHaveValue(username);
|
||||
await expect(page.getByTestId('error').locator('div')).toContainText("Could not find user")
|
||||
await expect(page.getByTestId(usernameUserInput)).toHaveValue(username);
|
||||
await expect(page.getByTestId("error").locator("div")).toContainText("Could not find user");
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {Page} from "@playwright/test";
|
||||
import {loginnameScreen} from "./loginname-screen";
|
||||
import { Page } from "@playwright/test";
|
||||
import { loginnameScreen } from "./loginname-screen";
|
||||
|
||||
export async function loginname(page: Page, username: string) {
|
||||
await loginnameScreen(page, username)
|
||||
await page.getByTestId("submit-button").click()
|
||||
await loginnameScreen(page, username);
|
||||
await page.getByTestId("submit-button").click();
|
||||
}
|
||||
|
||||
@@ -3,29 +3,29 @@ import * as http from "node:http";
|
||||
let messages = new Map<string, any>();
|
||||
|
||||
export function startSink() {
|
||||
const hostname = "127.0.0.1"
|
||||
const port = 3030
|
||||
const hostname = "127.0.0.1";
|
||||
const port = 3030;
|
||||
|
||||
const server = http.createServer((req, res) => {
|
||||
console.log("Sink received message: ")
|
||||
let body = '';
|
||||
req.on('data', (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();
|
||||
});
|
||||
const server = http.createServer((req, res) => {
|
||||
console.log("Sink received message: ");
|
||||
let body = "";
|
||||
req.on("data", (chunk) => {
|
||||
body += chunk;
|
||||
});
|
||||
|
||||
server.listen(port, hostname, () => {
|
||||
console.log(`Sink running at http://${hostname}:${port}/`);
|
||||
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();
|
||||
});
|
||||
return server
|
||||
}
|
||||
});
|
||||
|
||||
server.listen(port, hostname, () => {
|
||||
console.log(`Sink running at http://${hostname}:${port}/`);
|
||||
});
|
||||
return server;
|
||||
}
|
||||
|
||||
@@ -1,110 +1,109 @@
|
||||
import {expect, Page} from "@playwright/test";
|
||||
import {CDPSession} from "playwright-core";
|
||||
import { expect, Page } from "@playwright/test";
|
||||
import { CDPSession } from "playwright-core";
|
||||
|
||||
interface session {
|
||||
client: CDPSession
|
||||
authenticatorId: string
|
||||
client: CDPSession;
|
||||
authenticatorId: string;
|
||||
}
|
||||
|
||||
async function client(page: Page): Promise<session> {
|
||||
const cdpSession = await page.context().newCDPSession(page);
|
||||
await cdpSession.send('WebAuthn.enable', {enableUI: false});
|
||||
const result = await cdpSession.send('WebAuthn.addVirtualAuthenticator', {
|
||||
options: {
|
||||
protocol: 'ctap2',
|
||||
transport: 'internal',
|
||||
hasResidentKey: true,
|
||||
hasUserVerification: true,
|
||||
isUserVerified: true,
|
||||
automaticPresenceSimulation: true,
|
||||
},
|
||||
});
|
||||
return {client: cdpSession, authenticatorId: result.authenticatorId};
|
||||
const cdpSession = await page.context().newCDPSession(page);
|
||||
await cdpSession.send("WebAuthn.enable", { enableUI: false });
|
||||
const result = await cdpSession.send("WebAuthn.addVirtualAuthenticator", {
|
||||
options: {
|
||||
protocol: "ctap2",
|
||||
transport: "internal",
|
||||
hasResidentKey: true,
|
||||
hasUserVerification: true,
|
||||
isUserVerified: true,
|
||||
automaticPresenceSimulation: true,
|
||||
},
|
||||
});
|
||||
return { client: cdpSession, authenticatorId: result.authenticatorId };
|
||||
}
|
||||
|
||||
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 simulateSuccessfulPasskeyRegister(
|
||||
session.client,
|
||||
session.authenticatorId,
|
||||
() =>
|
||||
page.getByTestId("submit-button").click()
|
||||
);
|
||||
await passkeyRegistered(session.client, session.authenticatorId);
|
||||
await passkeyNotExisting(session.client, session.authenticatorId);
|
||||
await simulateSuccessfulPasskeyRegister(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) {
|
||||
const cdpSession = await page.context().newCDPSession(page);
|
||||
await cdpSession.send('WebAuthn.enable', {enableUI: false});
|
||||
const cdpSession = await page.context().newCDPSession(page);
|
||||
await cdpSession.send("WebAuthn.enable", { enableUI: false });
|
||||
|
||||
const signCount = await passkeyExisting(cdpSession, authenticatorId);
|
||||
const signCount = await passkeyExisting(cdpSession, authenticatorId);
|
||||
|
||||
await simulateSuccessfulPasskeyInput(
|
||||
cdpSession,
|
||||
authenticatorId,
|
||||
() =>
|
||||
page.getByTestId("submit-button").click()
|
||||
);
|
||||
await simulateSuccessfulPasskeyInput(cdpSession, authenticatorId, () => page.getByTestId("submit-button").click());
|
||||
|
||||
await passkeyUsed(cdpSession, authenticatorId, signCount);
|
||||
await passkeyUsed(cdpSession, authenticatorId, signCount);
|
||||
}
|
||||
|
||||
async function passkeyNotExisting(client: CDPSession, authenticatorId: string) {
|
||||
const result = await client.send('WebAuthn.getCredentials', {authenticatorId});
|
||||
expect(result.credentials).toHaveLength(0);
|
||||
const result = await client.send("WebAuthn.getCredentials", { authenticatorId });
|
||||
expect(result.credentials).toHaveLength(0);
|
||||
}
|
||||
|
||||
async function passkeyRegistered(client: CDPSession, authenticatorId: string) {
|
||||
const result = await client.send('WebAuthn.getCredentials', {authenticatorId});
|
||||
expect(result.credentials).toHaveLength(1);
|
||||
await passkeyUsed(client, authenticatorId, 0);
|
||||
const result = await client.send("WebAuthn.getCredentials", { authenticatorId });
|
||||
expect(result.credentials).toHaveLength(1);
|
||||
await passkeyUsed(client, authenticatorId, 0);
|
||||
}
|
||||
|
||||
async function passkeyExisting(client: CDPSession, authenticatorId: string): Promise<number> {
|
||||
const result = await client.send('WebAuthn.getCredentials', {authenticatorId});
|
||||
expect(result.credentials).toHaveLength(1);
|
||||
return result.credentials[0].signCount
|
||||
const result = await client.send("WebAuthn.getCredentials", { authenticatorId });
|
||||
expect(result.credentials).toHaveLength(1);
|
||||
return result.credentials[0].signCount;
|
||||
}
|
||||
|
||||
async function passkeyUsed(client: CDPSession, authenticatorId: string, signCount: number) {
|
||||
const result = await client.send('WebAuthn.getCredentials', {authenticatorId});
|
||||
expect(result.credentials).toHaveLength(1);
|
||||
expect(result.credentials[0].signCount).toBeGreaterThan(signCount);
|
||||
const result = await client.send("WebAuthn.getCredentials", { authenticatorId });
|
||||
expect(result.credentials).toHaveLength(1);
|
||||
expect(result.credentials[0].signCount).toBeGreaterThan(signCount);
|
||||
}
|
||||
|
||||
async function simulateSuccessfulPasskeyRegister(client: CDPSession, authenticatorId: string, operationTrigger: () => Promise<void>) {
|
||||
// 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()
|
||||
});
|
||||
async function simulateSuccessfulPasskeyRegister(
|
||||
client: CDPSession,
|
||||
authenticatorId: string,
|
||||
operationTrigger: () => Promise<void>,
|
||||
) {
|
||||
// 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
|
||||
await operationTrigger();
|
||||
// perform a user action that triggers passkey prompt
|
||||
await operationTrigger();
|
||||
|
||||
// wait to receive the event that the passkey was successfully registered or verified
|
||||
await operationCompleted;
|
||||
// wait to receive the event that the passkey was successfully registered or verified
|
||||
await operationCompleted;
|
||||
}
|
||||
|
||||
async function simulateSuccessfulPasskeyInput(client: CDPSession, authenticatorId: string, operationTrigger: () => Promise<void>) {
|
||||
// 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()
|
||||
});
|
||||
async function simulateSuccessfulPasskeyInput(
|
||||
client: CDPSession,
|
||||
authenticatorId: string,
|
||||
operationTrigger: () => Promise<void>,
|
||||
) {
|
||||
// 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
|
||||
await operationTrigger();
|
||||
// perform a user action that triggers passkey prompt
|
||||
await operationTrigger();
|
||||
|
||||
// wait to receive the event that the passkey was successfully registered or verified
|
||||
await operationCompleted;
|
||||
// wait to receive the event that the passkey was successfully registered or verified
|
||||
await operationCompleted;
|
||||
}
|
||||
s
|
||||
@@ -1,47 +1,57 @@
|
||||
import {expect, Page} from "@playwright/test";
|
||||
import { expect, Page } from "@playwright/test";
|
||||
|
||||
const passwordField = 'password-text-input'
|
||||
const passwordConfirmField = 'password-confirm-text-input'
|
||||
const lengthCheck = "length-check"
|
||||
const symbolCheck = "symbol-check"
|
||||
const numberCheck = "number-check"
|
||||
const uppercaseCheck = "uppercase-check"
|
||||
const lowercaseCheck = "lowercase-check"
|
||||
const equalCheck = "equal-check"
|
||||
const passwordField = "password-text-input";
|
||||
const passwordConfirmField = "password-confirm-text-input";
|
||||
const lengthCheck = "length-check";
|
||||
const symbolCheck = "symbol-check";
|
||||
const numberCheck = "number-check";
|
||||
const uppercaseCheck = "uppercase-check";
|
||||
const lowercaseCheck = "lowercase-check";
|
||||
const equalCheck = "equal-check";
|
||||
|
||||
const matchText = "Matches"
|
||||
const noMatchText = "Doesn\'t match"
|
||||
const matchText = "Matches";
|
||||
const noMatchText = "Doesn't match";
|
||||
|
||||
export async function changePasswordScreen(page: Page, password1: string, password2: string) {
|
||||
await page.getByTestId(passwordField).pressSequentially(password1);
|
||||
await page.getByTestId(passwordConfirmField).pressSequentially(password2);
|
||||
await page.getByTestId(passwordField).pressSequentially(password1);
|
||||
await page.getByTestId(passwordConfirmField).pressSequentially(password2);
|
||||
}
|
||||
|
||||
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) {
|
||||
await expect(page.getByTestId(passwordField)).toHaveValue(password);
|
||||
await expect(page.getByTestId('error').locator('div')).toContainText("Could not verify password");
|
||||
await expect(page.getByTestId(passwordField)).toHaveValue(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) {
|
||||
await expect(page.getByTestId(passwordField)).toHaveValue(password1);
|
||||
await expect(page.getByTestId(passwordConfirmField)).toHaveValue(password2);
|
||||
export async function changePasswordScreenExpect(
|
||||
page: Page,
|
||||
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, symbolCheck, symbol);
|
||||
await checkContent(page, numberCheck, number);
|
||||
await checkContent(page, uppercaseCheck, uppercase);
|
||||
await checkContent(page, lowercaseCheck, lowercase);
|
||||
await checkContent(page, equalCheck, equals);
|
||||
await checkContent(page, lengthCheck, length);
|
||||
await checkContent(page, symbolCheck, symbol);
|
||||
await checkContent(page, numberCheck, number);
|
||||
await checkContent(page, uppercaseCheck, uppercase);
|
||||
await checkContent(page, lowercaseCheck, lowercase);
|
||||
await checkContent(page, equalCheck, equals);
|
||||
}
|
||||
|
||||
async function checkContent(page: Page, testid: string, match: boolean) {
|
||||
if (match) {
|
||||
await expect(page.getByTestId(testid)).toContainText(matchText);
|
||||
} else {
|
||||
await expect(page.getByTestId(testid)).toContainText(noMatchText);
|
||||
}
|
||||
}
|
||||
if (match) {
|
||||
await expect(page.getByTestId(testid)).toContainText(matchText);
|
||||
} else {
|
||||
await expect(page.getByTestId(testid)).toContainText(noMatchText);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
import {Page} from "@playwright/test";
|
||||
import {changePasswordScreen, passwordScreen} from "./password-screen";
|
||||
|
||||
const passwordSubmitButton = "submit-button"
|
||||
import { Page } from "@playwright/test";
|
||||
import { changePasswordScreen, passwordScreen } from "./password-screen";
|
||||
|
||||
const passwordSubmitButton = "submit-button";
|
||||
|
||||
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) {
|
||||
await startChangePassword(page, loginname);
|
||||
await changePasswordScreen(page, password, password)
|
||||
await page.getByTestId(passwordSubmitButton).click();
|
||||
await startChangePassword(page, loginname);
|
||||
await changePasswordScreen(page, password, password);
|
||||
await page.getByTestId(passwordSubmitButton).click();
|
||||
}
|
||||
|
||||
export async function password(page: Page, password: string) {
|
||||
await passwordScreen(page, password)
|
||||
await page.getByTestId(passwordSubmitButton).click()
|
||||
await passwordScreen(page, password);
|
||||
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 passwordConfirmField = 'password-confirm-text-input'
|
||||
const passwordField = "password-text-input";
|
||||
const passwordConfirmField = "password-confirm-text-input";
|
||||
|
||||
export async function registerUserScreenPassword(page: Page, firstname: string, lastname: string, email: string) {
|
||||
await registerUserScreen(page, firstname, lastname, email)
|
||||
await page.getByTestId('Password-radio').click();
|
||||
await registerUserScreen(page, firstname, lastname, email);
|
||||
await page.getByTestId("Password-radio").click();
|
||||
}
|
||||
|
||||
export async function registerUserScreenPasskey(page: Page, firstname: string, lastname: string, email: string) {
|
||||
await registerUserScreen(page, firstname, lastname, email)
|
||||
await page.getByTestId('Passkeys-radio').click();
|
||||
await registerUserScreen(page, firstname, lastname, email);
|
||||
await page.getByTestId("Passkeys-radio").click();
|
||||
}
|
||||
|
||||
export async function registerPasswordScreen(page: Page, password1: string, password2: string) {
|
||||
await page.getByTestId(passwordField).pressSequentially(password1);
|
||||
await page.getByTestId(passwordConfirmField).pressSequentially(password2);
|
||||
await page.getByTestId(passwordField).pressSequentially(password1);
|
||||
await page.getByTestId(passwordConfirmField).pressSequentially(password2);
|
||||
}
|
||||
|
||||
export async function registerUserScreen(page: Page, firstname: string, lastname: string, email: string) {
|
||||
await page.getByTestId('firstname-text-input').pressSequentially(firstname);
|
||||
await page.getByTestId('lastname-text-input').pressSequentially(lastname);
|
||||
await page.getByTestId('email-text-input').pressSequentially(email);
|
||||
await page.getByTestId('privacy-policy-checkbox').check();
|
||||
await page.getByTestId('tos-checkbox').check();
|
||||
}
|
||||
await page.getByTestId("firstname-text-input").pressSequentially(firstname);
|
||||
await page.getByTestId("lastname-text-input").pressSequentially(lastname);
|
||||
await page.getByTestId("email-text-input").pressSequentially(email);
|
||||
await page.getByTestId("privacy-policy-checkbox").check();
|
||||
await page.getByTestId("tos-checkbox").check();
|
||||
}
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
import {test} from "@playwright/test";
|
||||
import {registerWithPasskey, registerWithPassword} from './register';
|
||||
import {loginScreenExpect} from "./login";
|
||||
import {removeUserByUsername} from './zitadel';
|
||||
import path from 'path';
|
||||
import dotenv from 'dotenv';
|
||||
import { test } from "@playwright/test";
|
||||
import dotenv from "dotenv";
|
||||
import path from "path";
|
||||
import { loginScreenExpect } from "./login";
|
||||
import { registerWithPasskey, registerWithPassword } from "./register";
|
||||
import { removeUserByUsername } from "./zitadel";
|
||||
|
||||
// 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}) => {
|
||||
const username = "register-password@example.com"
|
||||
const password = "Password1!"
|
||||
const firstname = "firstname"
|
||||
const lastname = "lastname"
|
||||
test("register with password", async ({ page }) => {
|
||||
const username = "register-password@example.com";
|
||||
const password = "Password1!";
|
||||
const firstname = "firstname";
|
||||
const lastname = "lastname";
|
||||
|
||||
await removeUserByUsername(username)
|
||||
await registerWithPassword(page, firstname, lastname, username, password, password)
|
||||
await loginScreenExpect(page, firstname + " " + lastname);
|
||||
await removeUserByUsername(username);
|
||||
await registerWithPassword(page, firstname, lastname, username, password, password);
|
||||
await loginScreenExpect(page, firstname + " " + lastname);
|
||||
});
|
||||
|
||||
test("register with passkey", async ({page}) => {
|
||||
const username = "register-passkey@example.com"
|
||||
const firstname = "firstname"
|
||||
const lastname = "lastname"
|
||||
test("register with passkey", async ({ page }) => {
|
||||
const username = "register-passkey@example.com";
|
||||
const firstname = "firstname";
|
||||
const lastname = "lastname";
|
||||
|
||||
await removeUserByUsername(username)
|
||||
await registerWithPasskey(page, firstname, lastname, username)
|
||||
await loginScreenExpect(page, firstname + " " + lastname);
|
||||
await removeUserByUsername(username);
|
||||
await registerWithPasskey(page, firstname, lastname, username);
|
||||
await loginScreenExpect(page, firstname + " " + lastname);
|
||||
});
|
||||
|
||||
test("register with username and password - only password enabled", async ({user, page}) => {
|
||||
|
||||
@@ -1,18 +1,25 @@
|
||||
import {Page} from "@playwright/test";
|
||||
import {passkeyRegister} from './passkey';
|
||||
import {registerPasswordScreen, registerUserScreenPasskey, registerUserScreenPassword} from './register-screen';
|
||||
import { Page } from "@playwright/test";
|
||||
import { passkeyRegister } from "./passkey";
|
||||
import { registerPasswordScreen, registerUserScreenPasskey, registerUserScreenPassword } from "./register-screen";
|
||||
|
||||
export async function registerWithPassword(page: Page, firstname: string, lastname: string, email: string, 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 registerWithPassword(
|
||||
page: Page,
|
||||
firstname: string,
|
||||
lastname: string,
|
||||
email: string,
|
||||
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> {
|
||||
await page.goto('/register');
|
||||
await registerUserScreenPasskey(page, firstname, lastname, email)
|
||||
await page.getByTestId('submit-button').click();
|
||||
return await passkeyRegister(page)
|
||||
await page.goto("/register");
|
||||
await registerUserScreenPasskey(page, firstname, lastname, email);
|
||||
await page.getByTestId("submit-button").click();
|
||||
return await passkeyRegister(page);
|
||||
}
|
||||
|
||||
@@ -1,205 +1,216 @@
|
||||
import fetch from "node-fetch";
|
||||
import {Page} from "@playwright/test";
|
||||
import {registerWithPasskey} from "./register";
|
||||
import {loginWithPassword} from "./login";
|
||||
import {changePassword} from "./password";
|
||||
import {getUserByUsername, removeUser} from './zitadel';
|
||||
import { Page } from "@playwright/test";
|
||||
import axios from "axios";
|
||||
import { registerWithPasskey } from "./register";
|
||||
import { getUserByUsername, removeUser } from "./zitadel";
|
||||
|
||||
export interface userProps {
|
||||
email: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
organization: string;
|
||||
password: string;
|
||||
email: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
organization: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
class User {
|
||||
private readonly props: userProps;
|
||||
private user: string;
|
||||
private readonly props: userProps;
|
||||
private user: string;
|
||||
|
||||
constructor(userProps: userProps) {
|
||||
this.props = userProps;
|
||||
constructor(userProps: 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!,
|
||||
},
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await axios.post(`${process.env.ZITADEL_API_URL}/v2/users/human`, body, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${process.env.ZITADEL_SERVICE_USER_TOKEN}`,
|
||||
},
|
||||
});
|
||||
|
||||
if (response.status >= 400 && response.status !== 409) {
|
||||
const error = `HTTP Error: ${response.status} - ${response.statusText}`;
|
||||
console.error(error);
|
||||
throw new Error(error);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error making request:", error);
|
||||
throw error;
|
||||
}
|
||||
|
||||
async ensure(page: Page) {
|
||||
await this.remove()
|
||||
// wait for projection of user
|
||||
await page.waitForTimeout(3000);
|
||||
}
|
||||
|
||||
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 remove() {
|
||||
const resp: any = await getUserByUsername(this.getUsername());
|
||||
if (!resp || !resp.result || !resp.result[0]) {
|
||||
return;
|
||||
}
|
||||
await removeUser(resp.result[0].userId);
|
||||
}
|
||||
|
||||
async remove() {
|
||||
await removeUser(this.getUserId())
|
||||
return
|
||||
}
|
||||
public setUserId(userId: string) {
|
||||
this.user = userId;
|
||||
}
|
||||
|
||||
public setUserId(userId: string) {
|
||||
this.user = userId
|
||||
}
|
||||
public getUserId() {
|
||||
return this.user;
|
||||
}
|
||||
|
||||
public getUserId() {
|
||||
return this.user;
|
||||
}
|
||||
public getUsername() {
|
||||
return this.props.email;
|
||||
}
|
||||
|
||||
public getUsername() {
|
||||
return this.props.email;
|
||||
}
|
||||
public getPassword() {
|
||||
return this.props.password;
|
||||
}
|
||||
|
||||
public getPassword() {
|
||||
return this.props.password;
|
||||
}
|
||||
public getFirstname() {
|
||||
return this.props.firstName;
|
||||
}
|
||||
|
||||
public getFirstname() {
|
||||
return this.props.firstName
|
||||
}
|
||||
public getLastname() {
|
||||
return this.props.lastName;
|
||||
}
|
||||
|
||||
public getLastname() {
|
||||
return this.props.lastName
|
||||
}
|
||||
|
||||
public getFullName() {
|
||||
return this.props.firstName + " " + this.props.lastName
|
||||
}
|
||||
|
||||
public async doPasswordChange(page: Page, password: string) {
|
||||
await loginWithPassword(page, this.getUsername(), this.getPassword())
|
||||
await changePassword(page, this.getUsername(), password)
|
||||
this.props.password = password
|
||||
}
|
||||
public getFullName() {
|
||||
return `${this.props.firstName} ${this.props.lastName}`;
|
||||
}
|
||||
}
|
||||
|
||||
export class PasswordUser extends User {
|
||||
}
|
||||
export class PasswordUser extends User {}
|
||||
|
||||
export enum OtpType {
|
||||
sms = "sms",
|
||||
email = "email",
|
||||
sms = "sms",
|
||||
email = "email",
|
||||
}
|
||||
|
||||
export interface otpUserProps {
|
||||
email: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
organization: string;
|
||||
password: string,
|
||||
type: OtpType,
|
||||
email: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
organization: string;
|
||||
password: string;
|
||||
type: OtpType;
|
||||
}
|
||||
|
||||
export class PasswordUserWithOTP extends User {
|
||||
private type: OtpType
|
||||
private code: string
|
||||
private type: OtpType;
|
||||
private code: string;
|
||||
|
||||
constructor(props: otpUserProps) {
|
||||
super({
|
||||
email: props.email,
|
||||
firstName: props.firstName,
|
||||
lastName: props.lastName,
|
||||
organization: props.organization,
|
||||
password: props.password,
|
||||
})
|
||||
this.type = props.type
|
||||
constructor(props: otpUserProps) {
|
||||
super({
|
||||
email: props.email,
|
||||
firstName: props.firstName,
|
||||
lastName: props.lastName,
|
||||
organization: props.organization,
|
||||
password: props.password,
|
||||
});
|
||||
this.type = props.type;
|
||||
}
|
||||
|
||||
async ensure(page: Page) {
|
||||
await super.ensure(page);
|
||||
|
||||
let url = "otp_";
|
||||
switch (this.type) {
|
||||
case OtpType.sms:
|
||||
url = url + "sms";
|
||||
break;
|
||||
case OtpType.email:
|
||||
url = url + "email";
|
||||
break;
|
||||
}
|
||||
|
||||
async ensure(page: Page) {
|
||||
await super.ensure(page)
|
||||
try {
|
||||
const response = await axios.post(
|
||||
`${process.env.ZITADEL_API_URL}/v2/users/${this.getUserId()}/${url}`,
|
||||
{},
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${process.env.ZITADEL_SERVICE_USER_TOKEN}`,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
let url = "otp_"
|
||||
switch (this.type) {
|
||||
case OtpType.sms:
|
||||
url = url + "sms"
|
||||
case OtpType.email:
|
||||
url = url + "email"
|
||||
}
|
||||
if (response.status >= 400 && response.status !== 409) {
|
||||
const error = `HTTP Error: ${response.status} - ${response.statusText}`;
|
||||
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
|
||||
// TODO: get code from SMS or Email provider
|
||||
this.code = "";
|
||||
} catch (error) {
|
||||
console.error("Error making request:", error);
|
||||
throw error;
|
||||
}
|
||||
|
||||
public getCode() {
|
||||
return this.code
|
||||
}
|
||||
// wait for projection of user
|
||||
await page.waitForTimeout(2000);
|
||||
}
|
||||
|
||||
public getCode() {
|
||||
return this.code;
|
||||
}
|
||||
}
|
||||
|
||||
export interface passkeyUserProps {
|
||||
email: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
organization: string;
|
||||
email: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
organization: string;
|
||||
}
|
||||
|
||||
export class PasskeyUser extends User {
|
||||
private authenticatorId: string
|
||||
private authenticatorId: string;
|
||||
|
||||
constructor(props: passkeyUserProps) {
|
||||
super({
|
||||
email: props.email,
|
||||
firstName: props.firstName,
|
||||
lastName: props.lastName,
|
||||
organization: props.organization,
|
||||
password: ""
|
||||
})
|
||||
}
|
||||
constructor(props: passkeyUserProps) {
|
||||
super({
|
||||
email: props.email,
|
||||
firstName: props.firstName,
|
||||
lastName: props.lastName,
|
||||
organization: props.organization,
|
||||
password: "",
|
||||
});
|
||||
}
|
||||
|
||||
public async ensure(page: Page) {
|
||||
await this.remove()
|
||||
const authId = await registerWithPasskey(page, this.getFirstname(), this.getLastname(), this.getUsername())
|
||||
this.authenticatorId = authId
|
||||
}
|
||||
public async ensure(page: Page) {
|
||||
await this.remove();
|
||||
const authId = await registerWithPasskey(page, this.getFirstname(), this.getLastname(), this.getUsername());
|
||||
this.authenticatorId = authId;
|
||||
|
||||
public async remove() {
|
||||
const resp = await getUserByUsername(this.getUsername())
|
||||
if (!resp || !resp.result || !resp.result[0]) {
|
||||
return
|
||||
}
|
||||
this.setUserId(resp.result[0].userId)
|
||||
await super.remove()
|
||||
}
|
||||
// wait for projection of user
|
||||
await page.waitForTimeout(2000);
|
||||
}
|
||||
|
||||
public getAuthenticatorId(): string {
|
||||
return this.authenticatorId
|
||||
}
|
||||
public async remove() {
|
||||
await super.remove();
|
||||
}
|
||||
|
||||
public getAuthenticatorId(): string {
|
||||
return this.authenticatorId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
import {test as base} from "@playwright/test";
|
||||
import path from 'path';
|
||||
import dotenv from 'dotenv';
|
||||
import {PasskeyUser} from "./user";
|
||||
import {loginScreenExpect, loginWithPasskey} from "./login";
|
||||
import { test as base } from "@playwright/test";
|
||||
import dotenv from "dotenv";
|
||||
import path from "path";
|
||||
import { loginScreenExpect, loginWithPasskey } from "./login";
|
||||
import { PasskeyUser } from "./user";
|
||||
|
||||
// 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 }>({
|
||||
user: async ({page}, use) => {
|
||||
const user = new PasskeyUser({
|
||||
email: "passkey@example.com",
|
||||
firstName: "first",
|
||||
lastName: "last",
|
||||
organization: "",
|
||||
});
|
||||
await user.ensure(page);
|
||||
await use(user);
|
||||
},
|
||||
user: async ({ page }, use) => {
|
||||
const user = new PasskeyUser({
|
||||
email: "passkey@example.com",
|
||||
firstName: "first",
|
||||
lastName: "last",
|
||||
organization: "",
|
||||
});
|
||||
await user.ensure(page);
|
||||
await use(user);
|
||||
},
|
||||
});
|
||||
|
||||
test("username and passkey login", async ({user, page}) => {
|
||||
await loginWithPasskey(page, user.getAuthenticatorId(), user.getUsername())
|
||||
await loginScreenExpect(page, user.getFullName());
|
||||
test("username and passkey login", async ({ user, page }) => {
|
||||
await loginWithPasskey(page, user.getAuthenticatorId(), user.getUsername());
|
||||
await loginScreenExpect(page, user.getFullName());
|
||||
});
|
||||
|
||||
test("username and passkey login, if passkey enabled", async ({user, page}) => {
|
||||
|
||||
@@ -1,41 +1,47 @@
|
||||
import {test as base} from "@playwright/test";
|
||||
import {PasswordUser} from './user';
|
||||
import path from 'path';
|
||||
import dotenv from 'dotenv';
|
||||
import {loginScreenExpect, loginWithPassword} from "./login";
|
||||
import {changePassword, startChangePassword} from "./password";
|
||||
import {changePasswordScreen, changePasswordScreenExpect} from "./password-screen";
|
||||
import { test as base } from "@playwright/test";
|
||||
import dotenv from "dotenv";
|
||||
import path from "path";
|
||||
import { loginScreenExpect, loginWithPassword } from "./login";
|
||||
import { changePassword, startChangePassword } from "./password";
|
||||
import { changePasswordScreen, changePasswordScreenExpect } from "./password-screen";
|
||||
import { PasswordUser } from "./user";
|
||||
|
||||
// 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 }>({
|
||||
user: async ({page}, use) => {
|
||||
const user = new PasswordUser({
|
||||
email: "password-changed@example.com",
|
||||
firstName: "first",
|
||||
lastName: "last",
|
||||
password: "Password1!",
|
||||
organization: "",
|
||||
});
|
||||
await user.ensure(page);
|
||||
await use(user);
|
||||
},
|
||||
user: async ({ page }, use) => {
|
||||
const user = new PasswordUser({
|
||||
email: "password-changed@example.com",
|
||||
firstName: "first",
|
||||
lastName: "last",
|
||||
password: "Password1!",
|
||||
organization: "",
|
||||
});
|
||||
await user.ensure(page);
|
||||
await use(user);
|
||||
},
|
||||
});
|
||||
|
||||
test("username and password changed login", async ({user, page}) => {
|
||||
const changedPw = "ChangedPw1!"
|
||||
await loginWithPassword(page, user.getUsername(), user.getPassword())
|
||||
await changePassword(page, user.getUsername(), changedPw)
|
||||
await loginWithPassword(page, user.getUsername(), changedPw)
|
||||
await loginScreenExpect(page, user.getFullName());
|
||||
test("username and password changed login", async ({ user, page }) => {
|
||||
const changedPw = "ChangedPw1!";
|
||||
await loginWithPassword(page, user.getUsername(), user.getPassword());
|
||||
|
||||
// wait for projection of token
|
||||
await page.waitForTimeout(2000);
|
||||
|
||||
await changePassword(page, user.getUsername(), changedPw);
|
||||
await loginScreenExpect(page, user.getFullName());
|
||||
|
||||
await loginWithPassword(page, user.getUsername(), changedPw);
|
||||
await loginScreenExpect(page, user.getFullName());
|
||||
});
|
||||
|
||||
test("password not with desired complexity", async ({user, page}) => {
|
||||
const changedPw1 = "change"
|
||||
const changedPw2 = "chang"
|
||||
await loginWithPassword(page, user.getUsername(), user.getPassword())
|
||||
await startChangePassword(page, user.getUsername());
|
||||
await changePasswordScreen(page, changedPw1, changedPw2)
|
||||
await changePasswordScreenExpect(page, changedPw1, changedPw2, false, false, false, false, true, false)
|
||||
test("password not with desired complexity", async ({ user, page }) => {
|
||||
const changedPw1 = "change";
|
||||
const changedPw2 = "chang";
|
||||
await loginWithPassword(page, user.getUsername(), user.getPassword());
|
||||
await startChangePassword(page, user.getUsername());
|
||||
await changePasswordScreen(page, changedPw1, changedPw2);
|
||||
await changePasswordScreenExpect(page, changedPw1, changedPw2, false, false, false, false, true, false);
|
||||
});
|
||||
|
||||
@@ -1,39 +1,36 @@
|
||||
import {test as base} from "@playwright/test";
|
||||
import {OtpType, PasswordUserWithOTP} from './user';
|
||||
import path from 'path';
|
||||
import dotenv from 'dotenv';
|
||||
import {loginScreenExpect, loginWithPassword} from "./login";
|
||||
import {startSink} from "./otp";
|
||||
import { test as base } from "@playwright/test";
|
||||
import dotenv from "dotenv";
|
||||
import path from "path";
|
||||
import { OtpType, PasswordUserWithOTP } from "./user";
|
||||
|
||||
// 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 }>({
|
||||
user: async ({page}, use) => {
|
||||
const user = new PasswordUserWithOTP({
|
||||
email: "otp_sms@example.com",
|
||||
firstName: "first",
|
||||
lastName: "last",
|
||||
password: "Password1!",
|
||||
organization: "",
|
||||
type: OtpType.sms,
|
||||
});
|
||||
user: async ({ page }, use) => {
|
||||
const user = new PasswordUserWithOTP({
|
||||
email: "otp_sms@example.com",
|
||||
firstName: "first",
|
||||
lastName: "last",
|
||||
password: "Password1!",
|
||||
organization: "",
|
||||
type: OtpType.sms,
|
||||
});
|
||||
|
||||
await user.ensure(page);
|
||||
await use(user);
|
||||
},
|
||||
await user.ensure(page);
|
||||
await use(user);
|
||||
},
|
||||
});
|
||||
|
||||
test("username, password and otp login", async ({user, page}) => {
|
||||
const server = startSink()
|
||||
await loginWithPassword(page, user.getUsername(), user.getPassword())
|
||||
/*
|
||||
test("username, password and otp login", async ({ user, page }) => {
|
||||
//const server = startSink()
|
||||
await loginWithPassword(page, user.getUsername(), user.getPassword());
|
||||
|
||||
|
||||
await loginScreenExpect(page, user.getFullName());
|
||||
server.close()
|
||||
await loginScreenExpect(page, user.getFullName());
|
||||
//server.close()
|
||||
});
|
||||
|
||||
|
||||
test("username, password and sms otp login", async ({user, page}) => {
|
||||
// Given sms otp is enabled on the organizaiton of the user
|
||||
// Given the user has only sms otp configured as second factor
|
||||
@@ -45,7 +42,6 @@ test("username, password and sms otp login", async ({user, page}) => {
|
||||
// User is redirected to the app (default redirect url)
|
||||
});
|
||||
|
||||
|
||||
test("username, password and sms otp login, resend code", async ({user, page}) => {
|
||||
// Given sms otp is enabled on the organizaiton of the user
|
||||
// Given the user has only sms otp configured as second factor
|
||||
@@ -58,7 +54,6 @@ test("username, password and sms otp login, resend code", async ({user, page}) =
|
||||
// User is redirected to the app (default redirect url)
|
||||
});
|
||||
|
||||
|
||||
test("username, password and sms otp login, wrong code", async ({user, page}) => {
|
||||
// Given sms otp is enabled on the organizaiton of the user
|
||||
// Given the user has only sms otp configured as second factor
|
||||
@@ -69,3 +64,4 @@ test("username, password and sms otp login, wrong code", async ({user, page}) =>
|
||||
// User enters a wrond code
|
||||
// Error message - "Invalid code" is shown
|
||||
});
|
||||
*/
|
||||
|
||||
@@ -1,47 +1,47 @@
|
||||
import {test as base} from "@playwright/test";
|
||||
import {PasswordUser} from './user';
|
||||
import path from 'path';
|
||||
import dotenv from 'dotenv';
|
||||
import {loginScreenExpect, loginWithPassword, startLogin} from "./login";
|
||||
import {loginnameScreenExpect} from "./loginname-screen";
|
||||
import {passwordScreenExpect} from "./password-screen";
|
||||
import {loginname} from "./loginname";
|
||||
import {password} from "./password";
|
||||
import { test as base } from "@playwright/test";
|
||||
import dotenv from "dotenv";
|
||||
import path from "path";
|
||||
import { loginScreenExpect, loginWithPassword, startLogin } from "./login";
|
||||
import { loginname } from "./loginname";
|
||||
import { loginnameScreenExpect } from "./loginname-screen";
|
||||
import { password } from "./password";
|
||||
import { passwordScreenExpect } from "./password-screen";
|
||||
import { PasswordUser } from "./user";
|
||||
|
||||
// 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 }>({
|
||||
user: async ({page}, use) => {
|
||||
const user = new PasswordUser({
|
||||
email: "password@example.com",
|
||||
firstName: "first",
|
||||
lastName: "last",
|
||||
password: "Password1!",
|
||||
organization: "",
|
||||
});
|
||||
await user.ensure(page);
|
||||
await use(user);
|
||||
},
|
||||
user: async ({ page }, use) => {
|
||||
const user = new PasswordUser({
|
||||
email: "password@example.com",
|
||||
firstName: "first",
|
||||
lastName: "last",
|
||||
password: "Password1!",
|
||||
organization: "",
|
||||
});
|
||||
await user.ensure(page);
|
||||
await use(user);
|
||||
},
|
||||
});
|
||||
|
||||
test("username and password login", async ({user, page}) => {
|
||||
await loginWithPassword(page, user.getUsername(), user.getPassword())
|
||||
await loginScreenExpect(page, user.getFullName());
|
||||
test("username and password login", async ({ user, page }) => {
|
||||
await loginWithPassword(page, user.getUsername(), user.getPassword());
|
||||
await loginScreenExpect(page, user.getFullName());
|
||||
});
|
||||
|
||||
test("username and password login, unknown username", async ({page}) => {
|
||||
const username = "unknown"
|
||||
await startLogin(page);
|
||||
await loginname(page, username)
|
||||
await loginnameScreenExpect(page, username)
|
||||
test("username and password login, unknown username", async ({ page }) => {
|
||||
const username = "unknown";
|
||||
await startLogin(page);
|
||||
await loginname(page, username);
|
||||
await loginnameScreenExpect(page, username);
|
||||
});
|
||||
|
||||
test("username and password login, wrong password", async ({user, page}) => {
|
||||
await startLogin(page);
|
||||
await loginname(page, user.getUsername())
|
||||
await password(page, "wrong")
|
||||
await passwordScreenExpect(page, "wrong")
|
||||
test("username and password login, wrong password", async ({ user, page }) => {
|
||||
await startLogin(page);
|
||||
await loginname(page, user.getUsername());
|
||||
await password(page, "wrong");
|
||||
await passwordScreenExpect(page, "wrong");
|
||||
});
|
||||
|
||||
test("username and password login, wrong username, ignore unknown usernames", async ({user, page}) => {
|
||||
|
||||
@@ -1,50 +1,60 @@
|
||||
import fetch from "node-fetch";
|
||||
import axios from "axios";
|
||||
|
||||
export async function removeUserByUsername(username: string) {
|
||||
const resp = await getUserByUsername(username)
|
||||
if (!resp || !resp.result || !resp.result[0]) {
|
||||
return
|
||||
}
|
||||
await removeUser(resp.result[0].userId)
|
||||
const resp = await getUserByUsername(username);
|
||||
if (!resp || !resp.result || !resp.result[0]) {
|
||||
return;
|
||||
}
|
||||
await removeUser(resp.result[0].userId);
|
||||
}
|
||||
|
||||
export async function removeUser(id: string) {
|
||||
const response = await fetch(process.env.ZITADEL_API_URL! + "/v2/users/" + id, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'Authorization': "Bearer " + process.env.ZITADEL_SERVICE_USER_TOKEN!
|
||||
}
|
||||
try {
|
||||
const response = await axios.delete(`${process.env.ZITADEL_API_URL}/v2/users/${id}`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${process.env.ZITADEL_SERVICE_USER_TOKEN}`,
|
||||
},
|
||||
});
|
||||
if (response.statusCode >= 400 && response.statusCode != 404) {
|
||||
const error = 'HTTP Error: ' + response.statusCode + ' - ' + response.statusMessage;
|
||||
console.error(error);
|
||||
throw new Error(error);
|
||||
|
||||
if (response.status >= 400 && response.status !== 404) {
|
||||
const error = `HTTP Error: ${response.status} - ${response.statusText}`;
|
||||
console.error(error);
|
||||
throw new Error(error);
|
||||
}
|
||||
return
|
||||
} catch (error) {
|
||||
console.error("Error making request:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getUserByUsername(username: string) {
|
||||
const listUsersBody = {
|
||||
queries: [{
|
||||
userNameQuery: {
|
||||
userName: username,
|
||||
}
|
||||
}]
|
||||
}
|
||||
const jsonBody = JSON.stringify(listUsersBody)
|
||||
const registerResponse = await fetch(process.env.ZITADEL_API_URL! + "/v2/users", {
|
||||
method: 'POST',
|
||||
body: jsonBody,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': "Bearer " + process.env.ZITADEL_SERVICE_USER_TOKEN!
|
||||
}
|
||||
const listUsersBody = {
|
||||
queries: [
|
||||
{
|
||||
userNameQuery: {
|
||||
userName: username,
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await axios.post(`${process.env.ZITADEL_API_URL}/v2/users`, listUsersBody, {
|
||||
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);
|
||||
throw new Error(error);
|
||||
|
||||
if (response.status >= 400) {
|
||||
const error = `HTTP Error: ${response.status} - ${response.statusText}`;
|
||||
console.error(error);
|
||||
throw new Error(error);
|
||||
}
|
||||
const respJson = await registerResponse.json()
|
||||
return respJson
|
||||
}
|
||||
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error("Error making request:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
FirstInstance:
|
||||
PatPath: /pat/zitadel-admin-sa.pat
|
||||
PrivacyPolicy:
|
||||
TOSLink: "https://zitadel.com/docs/legal/terms-of-service"
|
||||
PrivacyLink: "https://zitadel.com/docs/legal/policies/privacy-policy"
|
||||
HelpLink: "https://zitadel.com/docs"
|
||||
SupportEmail: "support@zitadel.com"
|
||||
DocsLink: "https://zitadel.com/docs"
|
||||
Org:
|
||||
Human:
|
||||
UserName: zitadel-admin
|
||||
|
||||
Reference in New Issue
Block a user