Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cmintey committed Dec 18, 2023
1 parent 79c6d3c commit 1f828ac
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 7 deletions.
1 change: 1 addition & 0 deletions tests/e2e/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ services:
DB_ENGINE: sqlite
OIDC_AUTH_ENABLED: True
OIDC_SIGNUP_ENABLED: True
OIDC_ADMIN_GROUP: admin
OIDC_CONFIGURATION_URL: http://localhost:8080/default/.well-known/openid-configuration
OIDC_CLIENT_ID: default

Expand Down
101 changes: 94 additions & 7 deletions tests/e2e/login.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,104 @@
import { test, expect } from '@playwright/test';

test('oidc-login', async ({ page }) => {
test('password login', async ({ page }) => {
await page.goto('http://localhost:9000/login');
await page.getByLabel('Email or Username').click();
await page.getByLabel('Email or Username').fill('[email protected]');
await page.locator('div').filter({ hasText: /^Password$/ }).nth(3).click();
await page.getByLabel('Password').fill('MyPassword');
await page.getByRole('button', { name: 'Login', exact: true }).click();
await expect(page.getByRole('navigation')).toContainText('Change Me');
});

test('oidc initial login', async ({ page }) => {
const username = "testUser"
const name = "Test User"
const claims = {
"sub": username,
"email": `${username}@example.com`,
"preferred_username": username,
"name": name
}

await page.goto('http://localhost:9000/login');
await page.getByRole('button', { name: 'Login with OIDC' }).click();
await page.getByPlaceholder('Enter any user/subject').fill(username);
await page.getByPlaceholder('Optional claims JSON value,').fill(JSON.stringify(claims));
await page.getByRole('button', { name: 'Sign-in' }).click();
await expect(page.getByRole('navigation')).toContainText(name);
});

test('oidc sequential login', async ({ page }) => {
const username = "testUser2"
const name = "Test User 2"
const claims = {
"sub": username,
"email": `${username}@example.com`,
"preferred_username": username,
"name": name
}

await page.goto('http://localhost:9000/login');
await page.getByRole('button', { name: 'Login with OIDC' }).click();
await page.getByPlaceholder('Enter any user/subject').fill(username);
await page.getByPlaceholder('Optional claims JSON value,').fill(JSON.stringify(claims));
await page.getByRole('button', { name: 'Sign-in' }).click();
await expect(page.getByRole('navigation')).toContainText(name);
await page.getByRole('button', { name: 'Logout' }).click();

await page.goto('http://localhost:9000/login');
await page.getByRole('button', { name: 'Login with OIDC' }).click();
await page.getByPlaceholder('Enter any user/subject').fill(username);
await page.getByPlaceholder('Optional claims JSON value,').fill(JSON.stringify(claims));
await page.getByRole('button', { name: 'Sign-in' }).click();
await expect(page.getByRole('navigation')).toContainText(name);
});

test('settings page verify oidc', async ({ page }) => {
const username = "oidcUser"
const name = "OIDC User"
const claims = {
"sub": username,
"email": `${username}@example.com`,
"preferred_username": username,
"name": name
}

await page.goto('http://localhost:9000/login');
await page.getByRole('button', { name: 'Login with OIDC' }).click();
await page.getByPlaceholder('Enter any user/subject').fill(username);
await page.getByPlaceholder('Optional claims JSON value,').fill(JSON.stringify(claims));
await page.getByRole('button', { name: 'Sign-in' }).click();
await expect(page.getByRole('navigation')).toContainText(name);
await page.getByRole('button', { name: 'Logout' }).click();

await page.goto('http://localhost:9000/login');
await page.getByLabel('Email or Username').click();
await page.getByLabel('Email or Username').fill('[email protected]');
await page.getByLabel('Password').click();
await page.getByLabel('Password').fill('MyPassword');
await page.getByRole('button', { name: 'Login', exact: true }).click();
await page.getByRole('link', { name: 'Settings' }).click();
await page.getByRole('link', { name: 'Users' }).click();
await page.getByRole('cell', { name: username, exact: true }).click();
await expect(page.getByText('Permissions Administrator')).toBeVisible();
});

test('oidc admin user', async ({ page }) => {
const username = "oidcAdmin"
const name = "OIDC Admin"
const claims = {
"sub": "testUser",
"email": "[email protected]",
"preferred_username": "test",
"name": "Test User"
"sub": username,
"email": `${username}@example.com`,
"preferred_username": username,
"name": name,
"groups": ["admin"]
}

await page.goto('http://localhost:9000/login');
await page.getByRole('button', { name: 'Login with OIDC' }).click();
await page.getByPlaceholder('Enter any user/subject').fill('testUser');
await page.getByPlaceholder('Enter any user/subject').fill(username);
await page.getByPlaceholder('Optional claims JSON value,').fill(JSON.stringify(claims));
await page.getByRole('button', { name: 'Sign-in' }).click();
await expect(page.getByRole('button', { name: 'Create', exact: true })).toBeVisible();
await expect(page.getByRole('navigation')).toContainText(name);
});

0 comments on commit 1f828ac

Please sign in to comment.