Skip to content

Commit 612f956

Browse files
committed
Displayed OAuth2 accounts in user profile page
1 parent 1de7c11 commit 612f956

File tree

5 files changed

+64
-14
lines changed

5 files changed

+64
-14
lines changed

docs/development/tests.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,24 @@ By default v2 tests are run. These tests require running a fractal-server instan
2020

2121
To run v1 tests start playwright setting the environment variable `TEST_VERSION` to `v1`. These tests require running a fractal-server instance using `FRACTAL_RUNNER_BACKEND=local`.
2222

23-
OAuth2 test requires a running instance of dexidp test image and a fractal-server instance configured to use it. To skip OAuth2 test set the environment variable `SKIP_OAUTH_TEST` to `true`.
23+
OAuth2 test requires a running instance of dexidp test image and a fractal-server instance configured to use it.
24+
25+
To skip OAuth2 test set the environment variable `SKIP_OAUTH_TEST` to `true`.
26+
27+
To run the OAuth2 test locally add the following configuration to `.fractal_server.env`:
28+
29+
```
30+
OAUTH_DEXIDP_CLIENT_ID=client_test_web_id
31+
OAUTH_DEXIDP_CLIENT_SECRET=client_test_web_secret
32+
OAUTH_DEXIDP_REDIRECT_URL=http://localhost:5173/auth/login/oauth2/
33+
OAUTH_DEXIDP_OIDC_CONFIGURATION_ENDPOINT=http://127.0.0.1:5556/dex/.well-known/openid-configuration
34+
```
35+
36+
And then start the test IdP container:
37+
38+
```sh
39+
docker run -d --rm -p 5556:5556 ghcr.io/fractal-analytics-platform/oauth:0.1
40+
```
2441

2542
## Coverage
2643

playwright.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export default defineConfig({
107107

108108
webServer: [
109109
{
110-
command: './tests/start-test-server.sh 2.5.0a0',
110+
command: './tests/start-test-server.sh 2.5.0a1',
111111
port: 8000,
112112
waitForPort: true,
113113
stdout: 'pipe',

src/lib/types.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ export type User = {
117117
slurm_accounts: string[]
118118
group_names?: string[]
119119
group_ids?: number[]
120+
oauth_accounts: Array<{
121+
id: number
122+
account_email: string
123+
oauth_name: string
124+
}>
120125
}
121126

122127
export type Group = {

src/routes/profile/+page.svelte

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,23 @@
263263
</td>
264264
<td />
265265
</tr>
266+
<tr>
267+
<th>OAuth2 accounts</th>
268+
<td colspan="2">
269+
{#if user.oauth_accounts.length === 0}
270+
-
271+
{:else}
272+
<table class="table mb-0">
273+
{#each user.oauth_accounts as account}
274+
<tr>
275+
<th>{account.oauth_name}</th>
276+
<td>{account.account_email}</td>
277+
</tr>
278+
{/each}
279+
</table>
280+
{/if}
281+
</td>
282+
</tr>
266283
</tbody>
267284
</table>
268285
<div id="profileUpdate-error" />

tests/oauth2.spec.js

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,39 @@ import { waitPageLoading } from './utils.js';
44
// Reset storage state for this file to avoid being authenticated
55
test.use({ storageState: { cookies: [], origins: [] } });
66

7-
test('Login using OAuth2 provider', async ({ page }) => {
7+
test('OAuth2 account', async ({ page }) => {
88
if (process.env.SKIP_OAUTH_TEST === 'true') {
99
console.warn(
1010
`WARNING: Skipping OAuth2 test since SKIP_OAUTH_TEST environment variable is set to true`
1111
);
1212
return;
1313
}
1414

15-
await page.goto('/');
16-
expect(await page.textContent('h1')).toBe('Welcome to Fractal web client.');
15+
await test.step('Login using OAuth2 provider', async () => {
16+
await page.goto('/');
17+
expect(await page.textContent('h1')).toBe('Welcome to Fractal web client.');
1718

18-
await page.getByRole('link', { name: 'Login' }).first().click();
19+
await page.getByRole('link', { name: 'Login' }).first().click();
1920

20-
await waitPageLoading(page);
21+
await waitPageLoading(page);
2122

22-
await page.getByText('Login with OAuth2 provider').click();
23-
await expect(page.getByText('as a non-verified user, you have limited access')).toBeVisible();
23+
await page.getByText('Login with OAuth2 provider').click();
24+
await expect(page.getByText('as a non-verified user, you have limited access')).toBeVisible();
25+
});
2426

25-
await page.getByRole('button', { name: '[email protected]' }).click();
26-
await page.getByRole('link', { name: 'Logout' }).click();
27-
await page.waitForURL('/');
27+
await test.step('Check that OAuth2 account is listed on profile', async () => {
28+
await page.goto('/profile');
29+
const row = page.getByRole('row', { name: 'OAuth2 accounts' });
30+
await expect(row).toContainText('[email protected]');
31+
await expect(row).toContainText('openid');
32+
});
2833

29-
await expect(page.getByText('[email protected]')).toHaveCount(0);
30-
await expect(page.getByText('Login')).toHaveCount(2);
34+
await test.step('Logout', async () => {
35+
await page.getByRole('button', { name: '[email protected]' }).click();
36+
await page.getByRole('link', { name: 'Logout' }).click();
37+
await page.waitForURL('/');
38+
39+
await expect(page.getByText('[email protected]')).toHaveCount(0);
40+
await expect(page.getByText('Login')).toHaveCount(2);
41+
});
3142
});

0 commit comments

Comments
 (0)