1
0
mirror of https://github.com/pocket-id/pocket-id.git synced 2026-02-04 11:36:46 +00:00

feat: improve initial admin creation workflow

This commit is contained in:
Elias Schneider
2025-06-27 23:38:02 +02:00
parent 73e7e0b1c5
commit 287314f016
20 changed files with 180 additions and 108 deletions

View File

@@ -4,7 +4,7 @@ import authUtil from '../utils/auth.util';
import { cleanupBackend } from '../utils/cleanup.util';
import passkeyUtil from '../utils/passkey.util';
test.beforeEach(cleanupBackend);
test.beforeEach(() => cleanupBackend());
test('Update account details', async ({ page }) => {
await page.goto('/settings/account');

View File

@@ -1,7 +1,7 @@
import test, { expect } from '@playwright/test';
import { cleanupBackend } from '../utils/cleanup.util';
test.beforeEach(cleanupBackend);
test.beforeEach(() => cleanupBackend());
test('Update general configuration', async ({ page }) => {
await page.goto('/settings/admin/application-configuration');

View File

@@ -1,7 +1,7 @@
import test, { expect } from '@playwright/test';
import { cleanupBackend } from '../utils/cleanup.util';
test.beforeEach(cleanupBackend);
test.beforeEach(() => cleanupBackend());
test.describe('LDAP Integration', () => {
test.skip(

View File

@@ -2,7 +2,7 @@ import test, { expect } from '@playwright/test';
import { oidcClients } from '../data';
import { cleanupBackend } from '../utils/cleanup.util';
test.beforeEach(cleanupBackend);
test.beforeEach(() => cleanupBackend());
test('Create OIDC client', async ({ page }) => {
await page.goto('/settings/admin/oidc-clients');

View File

@@ -5,7 +5,7 @@ import { generateIdToken, generateOauthAccessToken } from '../utils/jwt.util';
import * as oidcUtil from '../utils/oidc.util';
import passkeyUtil from '../utils/passkey.util';
test.beforeEach(cleanupBackend);
test.beforeEach(() => cleanupBackend());
test('Authorize existing client', async ({ page }) => {
const oidcClient = oidcClients.nextcloud;
@@ -189,19 +189,6 @@ test('Refresh token fails when used for the wrong client', async ({ request }) =
})
.then((r) => r.text());
// Perform the exchange
const refreshResponse = await request.post('/api/oidc/token', {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
form: {
grant_type: 'refresh_token',
client_id: clientId,
refresh_token: refreshToken,
client_secret: clientSecret
}
});
expect(refreshResponse.status()).toBe(400);
});

View File

@@ -2,7 +2,7 @@ import test, { expect } from '@playwright/test';
import { oneTimeAccessTokens } from '../data';
import { cleanupBackend } from '../utils/cleanup.util';
test.beforeEach(cleanupBackend);
test.beforeEach(() => cleanupBackend());
// Disable authentication for these tests
test.use({ storageState: { cookies: [], origins: [] } });

View File

@@ -2,7 +2,7 @@ import test, { expect } from '@playwright/test';
import { userGroups, users } from '../data';
import { cleanupBackend } from '../utils/cleanup.util';
test.beforeEach(cleanupBackend);
test.beforeEach(() => cleanupBackend());
test('Create user group', async ({ page }) => {
await page.goto('/settings/admin/user-groups');

View File

@@ -2,7 +2,7 @@ import test, { expect } from '@playwright/test';
import { userGroups, users } from '../data';
import { cleanupBackend } from '../utils/cleanup.util';
test.beforeEach(cleanupBackend);
test.beforeEach(() => cleanupBackend());
test('Create user', async ({ page }) => {
const user = users.steve;

View File

@@ -1,9 +1,9 @@
import test, { expect } from '@playwright/test';
import { signupTokens, users } from 'data';
import { cleanupBackend } from '../utils/cleanup.util';
import passkeyUtil from '../utils/passkey.util';
import { users, signupTokens } from 'data';
test.beforeEach(cleanupBackend);
test.beforeEach(() => cleanupBackend());
test.describe('User Signup', () => {
async function setSignupMode(page: any, mode: 'Disabled' | 'Signup with token' | 'Open Signup') {
@@ -177,3 +177,36 @@ test.describe('User Signup', () => {
await expect(page.getByText('Token is invalid or expired.')).toBeVisible();
});
});
test.describe('Initial User Signup', () => {
test.beforeEach(async ({ page }) => {
await page.context().clearCookies();
});
test('Initial Signup - success flow', async ({ page }) => {
await cleanupBackend(true);
await page.goto('/setup');
await page.getByLabel('First name').fill('Jane');
await page.getByLabel('Last name').fill('Smith');
await page.getByLabel('Username').fill('janesmith');
await page.getByLabel('Email').fill('jane.smith@test.com');
await page.getByRole('button', { name: 'Sign Up' }).click();
await page.waitForURL('/signup/add-passkey');
await expect(page.getByText('Set up your passkey')).toBeVisible();
});
test('Initial Signup - setup already completed', async ({ page }) => {
await page.goto('/setup');
await page.getByLabel('First name').fill('Test');
await page.getByLabel('Last name').fill('User');
await page.getByLabel('Username').fill('testuser123');
await page.getByLabel('Email').fill(users.tim.email);
await page.getByRole('button', { name: 'Sign Up' }).click();
await expect(page.getByText('Setup already completed')).toBeVisible();
});
});

View File

@@ -1,12 +1,16 @@
import playwrightConfig from '../playwright.config';
export async function cleanupBackend() {
export async function cleanupBackend(skipSeed = false) {
const url = new URL('/api/test/reset', playwrightConfig.use!.baseURL);
if (process.env.SKIP_LDAP_TESTS === 'true') {
if (process.env.SKIP_LDAP_TESTS === 'true' || skipSeed) {
url.searchParams.append('skip-ldap', 'true');
}
if (skipSeed) {
url.searchParams.append('skip-seed', 'true');
}
const response = await fetch(url, {
method: 'POST'
});