Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions openaev-front/tests_e2e/tests/aop/audit_log/login-audit.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { expect } from '@playwright/test';

import { test } from '../../../fixtures/baseFixtures';
Comment thread
a19836 marked this conversation as resolved.
import LoginPage from '../../../model/login.page';
import appUrl, { tenantUrl } from '../../../utils/url';

test.describe('Authentication flow', () => {
test.use({
storageState: {
cookies: [],
origins: [],
},
});

test('should login and logout successfully', async ({ page }) => {
test.info().annotations.push({
type: 'manual',
description: 'Please verify if backend-api console contains audit log entries for login and logout (console transport enabled).',
});

// -- ARRANGE --
const loginPage = new LoginPage(page);
const username = process.env.E2E_USERNAME ?? 'admin@openaev.io';
const password = process.env.E2E_PASSWORD ?? 'admin';

Comment thread
a19836 marked this conversation as resolved.
await page.goto(appUrl());
await expect(loginPage.getLoginPage()).toBeVisible();

// -- ACT --
await loginPage.getLoginInput().fill(username);
await loginPage.getPasswordInput().fill(password);
await loginPage.getSignInButton().click();

// Ensure we are on an admin page (the URL assertion below prevents /admin/login redirects)
await page.goto(tenantUrl('/admin'));
await expect(page).toHaveURL(/\/admin(?!\/login)/);

// Trigger CsrfFilter once to ensure XSRF-TOKEN cookie exists, then logout with matching header.
await page.evaluate(async () => {
await fetch('/api/scenarios/search', {
method: 'POST',
credentials: 'include',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({}),
}).catch(() => {});

const tokenCookie = document.cookie
.split('; ')
.find(cookie => cookie.startsWith('XSRF-TOKEN='));
const token = tokenCookie ? decodeURIComponent(tokenCookie.split('=')[1]) : '';

await fetch('/logout', {
method: 'POST',
credentials: 'include',
headers: token ? { 'X-XSRF-TOKEN': token } : {},
});
});
await page.goto(appUrl());

// -- ASSERT --
await expect(loginPage.getSignInButton()).toBeVisible();
});
});
Loading