-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcognito_endpoints.js
More file actions
39 lines (33 loc) · 1.03 KB
/
cognito_endpoints.js
File metadata and controls
39 lines (33 loc) · 1.03 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
class CognitoEndpoints {
static create (user) {
const credentials = this._credentials(user)
const encodedCredentials = this._encodeCredentials(credentials)
cy
.api({
method: 'POST',
url: this._url(),
headers: {
'content-type': 'application/x-www-form-urlencoded',
accept: 'application/json',
Authorization: `Basic ${encodedCredentials}`
}
})
.then(({ body }) => {
Cypress.env('token', body.access_token)
})
}
static _url () {
return `${Cypress.env('TOKEN_URL')}?grant_type=client_credentials`
}
static _credentials (user) {
return {
user: user === 'admin' ? Cypress.env('ADMIN_USER') : Cypress.env('SYSTEM_USER'),
password: user === 'admin' ? Cypress.env('ADMIN_PASSWORD') : Cypress.env('SYSTEM_PASSWORD')
}
}
static _encodeCredentials (credentials) {
const keys = `${credentials.user}:${credentials.password}`
return Buffer.from(keys).toString('base64')
}
}
export default CognitoEndpoints