-
Notifications
You must be signed in to change notification settings - Fork 214
Expand file tree
/
Copy pathpasswordless-and-password-reset.spec.js
More file actions
184 lines (141 loc) · 6.64 KB
/
passwordless-and-password-reset.spec.js
File metadata and controls
184 lines (141 loc) · 6.64 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
/*
* Copyright (c) 2025, Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
const {test, expect} = require('@playwright/test')
const config = require('../../config.js')
const {generateUserCredentials} = require('../../scripts/utils.js')
const {answerConsentTrackingForm} = require('../../scripts/pageHelpers.js')
const GUEST_USER_CREDENTIALS = generateUserCredentials()
// Skip this test suite if not running private client tests
test.skip(
() => !process.env.RUN_PRIVATE_CLIENT_TESTS,
'Passwordless login tests require private client configuration'
)
/**
* Test that a user can login with passwordless login on mobile. There is no programmatic way to check the email,
* so we will check that the necessary API call is being made and expected UI is shown
*/
test('Verify passwordless login request on mobile', async ({page}) => {
let interceptedRequest = null
await page.route(
'**/mobify/slas/private/shopper/auth/v1/organizations/*/oauth2/passwordless/login',
(route) => {
interceptedRequest = route.request()
route.continue()
}
)
await page.goto(config.EXTRA_FEATURES_E2E_RETAIL_APP_HOME + '/login')
await answerConsentTrackingForm(page)
await page.locator('#email').scrollIntoViewIfNeeded()
await page.fill('#email', config.PWA_E2E_USER_EMAIL)
await page.getByRole('button', {name: 'Continue Securely'}).scrollIntoViewIfNeeded()
await page.getByRole('button', {name: 'Continue Securely'}).click()
await page.waitForResponse(
'**/mobify/slas/private/shopper/auth/v1/organizations/*/oauth2/passwordless/login'
)
expect(interceptedRequest).toBeTruthy()
expect(interceptedRequest.method()).toBe('POST')
const postData = interceptedRequest.postData()
expect(postData).toBeTruthy()
const params = new URLSearchParams(postData)
expect(params.get('user_id')).toBe(config.PWA_E2E_USER_EMAIL)
expect(params.get('mode')).toBe('callback')
expect(params.get('channel_id')).toBe(config.EXTRA_FEATURES_E2E_RETAIL_APP_HOME_SITE)
expect(params.get('callback_uri')).toMatch(/.*\/passwordless-login-callback$/)
})
test('Verify password reset callback request on mobile (extra features enabled)', async ({
page
}) => {
let interceptedRequest = null
await page.route(
'**/mobify/slas/private/shopper/auth/v1/organizations/*/oauth2/password/reset',
(route) => {
interceptedRequest = route.request()
route.continue()
}
)
await page.goto(config.EXTRA_FEATURES_E2E_RETAIL_APP_HOME + '/login')
await answerConsentTrackingForm(page)
await page.locator('#email').scrollIntoViewIfNeeded()
await page.fill('#email', config.PWA_E2E_USER_EMAIL)
await page.getByRole('button', {name: 'Password'}).click()
await page.getByRole('button', {name: 'Forgot password?'}).click()
await page.fill('#email', config.PWA_E2E_USER_EMAIL)
await page.getByRole('button', {name: /reset password/i}).click()
await page.waitForResponse(
'**/mobify/slas/private/shopper/auth/v1/organizations/*/oauth2/password/reset'
)
expect(interceptedRequest).toBeTruthy()
expect(interceptedRequest.method()).toBe('POST')
const postData = interceptedRequest.postData()
expect(postData).toBeTruthy()
const params = new URLSearchParams(postData)
expect(params.get('user_id')).toBe(config.PWA_E2E_USER_EMAIL)
expect(params.get('mode')).toBe('callback')
expect(params.get('channel_id')).toBe(config.EXTRA_FEATURES_E2E_RETAIL_APP_HOME_SITE)
expect(params.get('callback_uri')).toMatch(/.*\/reset-password-callback$/)
expect(params.get('hint')).toBe('cross_device')
})
test('Verify password reset callback request on mobile when extra login features are not enabled', async ({
page
}) => {
let interceptedRequest = null
await page.route(
'**/mobify/proxy/api/shopper/auth/v1/organizations/*/oauth2/password/reset',
(route) => {
interceptedRequest = route.request()
route.continue()
}
)
await page.goto(config.RETAIL_APP_HOME + '/login')
await answerConsentTrackingForm(page)
await page.locator('#email').scrollIntoViewIfNeeded()
await page.fill('#email', config.PWA_E2E_USER_EMAIL)
await page.getByRole('button', {name: 'Forgot password?'}).click()
await page.waitForSelector('form[data-testid="sf-auth-modal-form"] >> text=Reset Password')
await page.fill('form[data-testid="sf-auth-modal-form"] #email', config.PWA_E2E_USER_EMAIL)
await page.getByRole('button', {name: /reset password/i}).click()
await page.waitForResponse(
'**/mobify/proxy/api/shopper/auth/v1/organizations/*/oauth2/password/reset'
)
expect(interceptedRequest).toBeTruthy()
expect(interceptedRequest.method()).toBe('POST')
const postData = interceptedRequest.postData()
expect(postData).toBeTruthy()
const params = new URLSearchParams(postData)
expect(params.get('user_id')).toBe(config.PWA_E2E_USER_EMAIL)
expect(params.get('mode')).toBe('callback')
expect(params.get('channel_id')).toBe(config.RETAIL_APP_HOME_SITE)
expect(params.get('callback_uri')).toMatch(/.*\/reset-password-callback$/)
expect(params.get('hint')).toBe('cross_device')
})
test('Verify password reset request on mobile', async ({page}) => {
let interceptedRequest = null
await page.route(
'**/mobify/slas/private/shopper/auth/v1/organizations/*/oauth2/password/action',
(route) => {
interceptedRequest = route.request()
route.continue()
}
)
await page.goto(
config.EXTRA_FEATURES_E2E_RETAIL_APP_HOME +
`/reset-password-landing?token=1234567&email=${GUEST_USER_CREDENTIALS.email}`
)
await answerConsentTrackingForm(page)
await page.locator('#password').scrollIntoViewIfNeeded()
await page.fill('#password', GUEST_USER_CREDENTIALS.password)
await page.locator('#confirmPassword').scrollIntoViewIfNeeded()
await page.fill('#confirmPassword', GUEST_USER_CREDENTIALS.password)
expect(await page.inputValue('#password')).toBe(GUEST_USER_CREDENTIALS.password)
expect(await page.inputValue('#confirmPassword')).toBe(GUEST_USER_CREDENTIALS.password)
await page.getByRole('button', {name: 'Reset Password'}).scrollIntoViewIfNeeded()
await page.getByRole('button', {name: 'Reset Password'}).click()
await page.waitForResponse(
'**/mobify/slas/private/shopper/auth/v1/organizations/*/oauth2/password/action'
)
expect(interceptedRequest).toBeTruthy()
})