Skip to content

Commit

Permalink
test(e2e): add support functions and type definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Oct 19, 2021
1 parent 0c91f0c commit c82d68d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
30 changes: 29 additions & 1 deletion test/e2e/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Cypress.Commands.add('shortPrivilegedSessionTime', ({} = {}) => {

Cypress.Commands.add('longPrivilegedSessionTime', ({} = {}) => {
updateConfigFile((config) => {
config.selfservice.flows.settings.privileged_session_max_age = '1m'
config.selfservice.flows.settings.privileged_session_max_age = '5m'
return config
})
})
Expand All @@ -69,6 +69,18 @@ Cypress.Commands.add('shortVerificationLifespan', ({} = {}) => {
return config
})
})
Cypress.Commands.add('sessionRequiresNo2fa', ({} = {}) => {
updateConfigFile((config) => {
config.session.whoami.required_aal = 'aal1'
return config
})
})
Cypress.Commands.add('sessionRequires2fa', ({} = {}) => {
updateConfigFile((config) => {
config.session.whoami.required_aal = 'highest_available'
return config
})
})
Cypress.Commands.add('shortLinkLifespan', ({} = {}) => {
updateConfigFile((config) => {
config.selfservice.methods.link.config.lifespan = '1ms'
Expand Down Expand Up @@ -575,6 +587,13 @@ Cypress.Commands.add('waitForPrivilegedSessionToExpire', () => {
})
})

Cypress.Commands.add('getLookupSecrets', () =>
cy.get('[data-testid="node/text/lookup_secret_codes/text"] code').then(($e) => $e.map((_, e) => e.innerText.trim()).toArray())
)
Cypress.Commands.add('expectSettingsSaved', () =>
cy.get('[data-testid="ui/message/1050001"]').should('contain.text', 'Your changes have been saved')
)

Cypress.Commands.add('getMail', ({removeMail = true} = {}) => {
let tries = 0
const req = () =>
Expand All @@ -599,3 +618,12 @@ Cypress.Commands.add('getMail', ({removeMail = true} = {}) => {

return req()
})

Cypress.Commands.add('clearAllCookies',() => {
cy.clearCookies({domain: null})
})

Cypress.Commands.add('submitPasswordForm',() => {
cy.get('[name="method"][value="password"]').click()
cy.get('[name="method"][value="password"]:disabled').should('not.exist')
})
27 changes: 26 additions & 1 deletion test/e2e/cypress/support/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ declare global {
getSession(opts?:
{
expectAal: 'aal2' | 'aal1',
expectMethods: Array<'password' | 'webauthn'>,
expectMethods: Array<'password' | 'webauthn' | 'lookup_secret'>,
}
): Chainable<Session>

Expand Down Expand Up @@ -144,6 +144,31 @@ declare global {
expect: { email },
type: { email?: string, password?: string }
}): Chainable<void>

/**
* Do not require 2fa for /session/whoami
*/
sessionRequiresNo2fa(): Chainable<void>

/**
* Require 2fa for /session/whoami if available
*/
sessionRequires2fa(): Chainable<void>

/**
* Gets the lookup codes from the settings page
*/
getLookupSecrets(): Chainable<Array<string>>

/**
* Expect the settings to be saved.
*/
expectSettingsSaved(): Chainable<void>

clearCookies(options?: Partial<Loggable & Timeoutable & { domain: null | string }>): Chainable<null>
clearAllCookies(): Chainable<null>

submitPasswordForm(): Chainable<null>
}
}
}

0 comments on commit c82d68d

Please sign in to comment.