-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreset_password_passcode_remaining_users.spec.ts
More file actions
194 lines (154 loc) · 6.71 KB
/
Copy pathreset_password_passcode_remaining_users.spec.ts
File metadata and controls
194 lines (154 loc) · 6.71 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import { expect } from '@playwright/test';
import { Status } from '../../../src/server/models/okta/User';
import {
randomMailosaurEmail,
randomPassword,
createTestUser,
} from '../../helpers/api/idapi';
import { checkForEmailAndGetDetails } from '../../helpers/api/mailosaur';
import {
getTestOktaUser,
resetOktaUserPassword,
expireOktaUserPassword,
} from '../../helpers/api/okta';
import { test } from '../../fixtures/e2eFixture';
test.describe('Password reset recovery flows - with Passcodes', () => {
test.describe('RECOVERY user', () => {
test('allows the user to change their password - RECOVERY', async ({
request,
page,
}) => {
const { emailAddress } = await createTestUser(request, {
isGuestUser: false,
});
await resetOktaUserPassword(request, emailAddress);
const oktaUser = await getTestOktaUser(request, emailAddress);
expect(oktaUser.status).toBe(Status.RECOVERY);
await page.goto('/reset-password');
const timeRequestWasMade = new Date();
await page.locator('input[name=email]').fill(emailAddress);
await page.locator('[data-cy="main-form-submit-button"]').click();
const { body, codes } = await checkForEmailAndGetDetails(
emailAddress,
timeRequestWasMade,
);
// email
expect(body).toContain('Your one-time passcode');
expect(codes?.length).toBe(1);
const code = codes?.[0].value;
expect(code).toMatch(/^\d{6}$/);
// passcode page
await expect(page).toHaveURL(/\/reset-password\/email-sent/);
await expect(page.getByText('Enter your one-time code')).toBeVisible();
await expect(page.getByText('Submit one-time code')).toBeVisible();
await page.locator('input[name=code]').clear();
await page.locator('input[name=code]').fill(code!);
// password page
await expect(page).toHaveURL(/\/reset-password\/password/);
await page.locator('input[name="password"]').fill(randomPassword());
await page.locator('button[type="submit"]').click();
// password complete page
await expect(page).toHaveURL(/\/reset-password\/complete/);
await expect(page.getByText('Password updated')).toBeVisible();
});
});
test.describe('PASSWORD_EXPIRED user', () => {
test('allows the user to change their password - PASSWORD_EXPIRED', async ({
request,
page,
}) => {
const { emailAddress } = await createTestUser(request, {
isGuestUser: false,
});
await expireOktaUserPassword(request, emailAddress);
const oktaUser = await getTestOktaUser(request, emailAddress);
expect(oktaUser.status).toBe(Status.PASSWORD_EXPIRED);
await page.goto('/reset-password');
const timeRequestWasMade = new Date();
await page.locator('input[name=email]').fill(emailAddress);
await page.locator('[data-cy="main-form-submit-button"]').click();
const { body, codes } = await checkForEmailAndGetDetails(
emailAddress,
timeRequestWasMade,
);
// email
expect(body).toContain('Your one-time passcode');
expect(codes?.length).toBe(1);
const code = codes?.[0].value;
expect(code).toMatch(/^\d{6}$/);
// passcode page
await expect(page).toHaveURL(/\/reset-password\/email-sent/);
await expect(page.getByText('Enter your one-time code')).toBeVisible();
await expect(page.getByText('Submit one-time code')).toBeVisible();
await page.locator('input[name=code]').clear();
await page.locator('input[name=code]').fill(code!);
// password page
await expect(page).toHaveURL(/\/reset-password\/password/);
await page.locator('input[name="password"]').fill(randomPassword());
await page.locator('button[type="submit"]').click();
// password complete page
await expect(page).toHaveURL(/\/reset-password\/complete/);
await expect(page.getByText('Password updated')).toBeVisible();
});
});
test.describe('NON_EXISTENT user', () => {
test('shows the passcode page with no account info, and using passcode returns error', async ({
page,
}) => {
const emailAddress = randomMailosaurEmail();
await page.goto(`/reset-password`);
await expect(page.getByText('Reset password')).toBeVisible();
await page.locator('input[name=email]').fill(emailAddress);
await page.locator('[data-cy="main-form-submit-button"]').click();
// passcode page
await expect(page).toHaveURL(/\/reset-password\/email-sent/);
await expect(page.getByText('Enter your one-time code')).toBeVisible();
await expect(page.getByText('Don’t have an account?')).toBeVisible();
await expect(page.getByText('Submit one-time code')).toBeVisible();
await page.locator('input[name=code]').clear();
await page.locator('input[name=code]').fill('123456');
await expect(page).toHaveURL(/\/reset-password\/code/);
await expect(page.getByText('Enter your one-time code')).toBeVisible();
await expect(page.getByText('Don’t have an account?')).toBeVisible();
await expect(page.getByText('Incorrect code')).toBeVisible();
});
test('should redirect with error when multiple passcode attempts fail', async ({
page,
}) => {
const emailAddress = randomMailosaurEmail();
await page.goto(`/reset-password`);
await expect(page.getByText('Reset password')).toBeVisible();
await page.locator('input[name=email]').fill(emailAddress);
await page.locator('[data-cy="main-form-submit-button"]').click();
// passcode page
await expect(page).toHaveURL(/\/reset-password\/email-sent/);
await expect(page.getByText('Enter your one-time code')).toBeVisible();
await expect(page.getByText('Don’t have an account?')).toBeVisible();
// attempt 1
await expect(page.getByText('Submit one-time code')).toBeVisible();
await page.locator('input[name=code]').fill('123456');
await expect(page).toHaveURL(/\/reset-password\/code/);
await expect(page.getByText('Incorrect code')).toBeVisible();
// attempt 2
await page.locator('input[name=code]').fill('123456');
await page.getByText('Submit one-time code').click();
await expect(page).toHaveURL(/\/reset-password\/code/);
await expect(page.getByText('Incorrect code')).toBeVisible();
// attempt 3
await page.locator('input[name=code]').fill('123456');
await page.getByText('Submit one-time code').click();
await expect(page).toHaveURL(/\/reset-password\/code/);
await expect(page.getByText('Incorrect code')).toBeVisible();
// attempt 4
await page.locator('input[name=code]').fill('123456');
await page.getByText('Submit one-time code').click();
await expect(page).toHaveURL(/\/reset-password\/code/);
await expect(page.getByText('Incorrect code')).toBeVisible();
// attempt 5
await page.locator('input[name=code]').fill('123456');
await page.getByText('Submit one-time code').click();
await expect(page).toHaveURL(/\/reset-password/);
await expect(page.getByText('Your code has expired')).toBeVisible();
});
});
});