-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbasic.test.ts
More file actions
124 lines (93 loc) · 4.5 KB
/
basic.test.ts
File metadata and controls
124 lines (93 loc) · 4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
* Copyright (c) 2025 Ping Identity Corporation. All rights reserved.
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
import { expect, test } from '@forgerock/e2e-shared/coverage-fixture';
import { asyncEvents } from './utils/async-events.js';
import { password, username } from './utils/demo-user.js';
test('Test happy paths on test page', async ({ page }) => {
const { navigate } = asyncEvents(page);
await navigate('/');
expect(page.url()).toBe('http://localhost:5829/');
await expect(page.getByText('Username/Password Form')).toBeVisible();
await page.getByLabel('Username').fill(username);
await page.getByLabel('Password').fill(password);
await page.getByRole('button', { name: 'Sign On' }).click();
await expect(page.getByText('Complete')).toBeVisible();
const sessionToken = await page.locator('#sessionToken').innerText();
const authCode = await page.locator('#authCode').innerText();
expect(sessionToken).toBeTruthy();
expect(authCode).toBeTruthy();
await page.getByText('Get Tokens').click();
const accessToken = await page.locator('#accessTokenValue').innerText();
expect(accessToken).toBeTruthy();
const logoutButton = page.getByRole('button', { name: 'Logout' });
await expect(logoutButton).toBeVisible();
const revokeCall = page.waitForResponse((response) => {
if (response.url().includes('/revoke') && response.status() === 200) {
return true;
}
});
const signoff = page.waitForResponse((response) => {
if (response.url().includes('/signoff') && response.status() === 302) {
return true;
}
});
await logoutButton.click();
await revokeCall;
await signoff;
await expect(page.getByText('Username/Password Form')).toBeVisible();
});
test('ensure query params passed to start are sent off in authorize call', async ({ page }) => {
const { navigate } = asyncEvents(page);
// Wait for the request to a URL containing '/authorize'
const requestPromise = page.waitForRequest((request) => {
return request
.url()
.includes('https://auth.pingone.ca/02fb4743-189a-4bc7-9d6c-a919edfe6447/as/authorize');
});
await navigate('/?testParam=123');
// Wait for the request to be made to authorize
const request = await requestPromise;
// Extract and verify the query parameters from authorize
const url = new URL(request.url());
const queryParams = Object.fromEntries(url.searchParams.entries());
expect(queryParams['testParam']).toBe('123');
expect(queryParams['client_id']).toBe('724ec718-c41c-4d51-98b0-84a583f450f9');
expect(queryParams['response_mode']).toBe('pi.flow');
expect(page.url()).toBe('http://localhost:5829/?testParam=123');
await expect(page.getByText('Username/Password Form')).toBeVisible();
await page.getByLabel('Username').fill(username);
await page.getByLabel('Password').fill(password);
await page.getByText('Sign On').click();
await expect(page.getByText('Complete')).toBeVisible();
const sessionToken = await page.locator('#sessionToken').innerText();
const authCode = await page.locator('#authCode').innerText();
expect(sessionToken).toBeTruthy();
expect(authCode).toBeTruthy();
await page.getByText('Get Tokens').click();
const accessToken = await page.locator('#accessTokenValue').innerText();
expect(accessToken).toBeTruthy();
});
test('Enter a bad username/password, then enter a good username/password', async ({ page }) => {
await page.goto('http://localhost:5829/');
await page.getByRole('textbox', { name: 'Username' }).fill('baduser');
await page.getByRole('textbox', { name: 'Password' }).fill('1231');
await page.getByRole('button', { name: 'Sign On' }).click();
await expect(page.getByText(/Invalid username and\/or password|Validation Error/)).toBeVisible();
await page.getByRole('textbox', { name: 'Username' }).fill(username);
await page.getByRole('textbox', { name: 'Password' }).fill(password);
await page.getByRole('button', { name: 'Sign On' }).click();
const authCode = page.getByTestId('authCode');
const session = page.getByTestId('sessionToken');
// just checking that these values on the page are not empty
// meaning we got something back from the server
await expect(authCode).not.toBeEmpty();
await expect(session).not.toBeEmpty();
await page.getByRole('button', { name: 'Get Tokens' }).click();
const accessToken = page.getByTestId('access-token');
await expect(accessToken).not.toBeEmpty();
await page.getByRole('button', { name: 'Logout' }).click();
});