-
-
Notifications
You must be signed in to change notification settings - Fork 931
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add e2e tests for react native 2fa
- Loading branch information
Showing
2 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
103 changes: 103 additions & 0 deletions
103
test/e2e/cypress/integration/profiles/mobile/mfa/backup.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { gen, MOBILE_URL, website } from '../../../../helpers' | ||
|
||
context('Mobile Profile', () => { | ||
describe('TOTP 2FA Flow', () => { | ||
before(() => { | ||
cy.useConfigProfile('mobile') | ||
}) | ||
|
||
describe('password', () => { | ||
const email = gen.email() | ||
const password = gen.password() | ||
|
||
before(() => { | ||
cy.registerApi({ | ||
email, | ||
password, | ||
fields: { 'traits.website': website } | ||
}) | ||
}) | ||
|
||
beforeEach(() => { | ||
cy.loginMobile({ email, password }) | ||
cy.visit(MOBILE_URL + '/Settings') | ||
}) | ||
|
||
it('should be able to lifecycle through lookup_secret flows', () => { | ||
cy.get('*[data-testid="field/lookup_secret_codes"]').should('not.exist') | ||
cy.get('*[data-testid="field/lookup_secret_confirm/true"]').should( | ||
'not.exist' | ||
) | ||
cy.get('*[data-testid="field/lookup_secret_reveal/true"]').should( | ||
'not.exist' | ||
) | ||
cy.get('*[data-testid="field/lookup_secret_regenerate/true"]').click() | ||
cy.get('*[data-testid="field/lookup_secret_reveal/true"]').should( | ||
'not.exist' | ||
) | ||
cy.get('*[data-testid="field/lookup_secret_codes"]').should('exist') | ||
let codes | ||
cy.get('*[data-testid="field/lookup_secret_codes/text"]').then(($e) => { | ||
codes = $e.text().trim().split(', ') | ||
}) | ||
cy.get('*[data-testid="field/lookup_secret_confirm/true"]').click() | ||
cy.get('*[data-testid="form-messages"]').should( | ||
'contain.text', | ||
'Your changes have been saved!' | ||
) | ||
|
||
cy.get('*[data-testid="field/lookup_secret_confirm/true"]').should( | ||
'not.exist' | ||
) | ||
cy.get('*[data-testid="field/lookup_secret_regenerate/true"]').should( | ||
'not.exist' | ||
) | ||
cy.get('*[data-testid="field/lookup_secret_codes/true"]').should( | ||
'not.exist' | ||
) | ||
|
||
cy.get('*[data-testid="field/lookup_secret_reveal/true"]').click() | ||
cy.get('*[data-testid="field/lookup_secret_regenerate/true"]').should( | ||
'exist' | ||
) | ||
cy.get('*[data-testid="field/lookup_secret_codes/text"]').then(($e) => { | ||
const actualCodes = $e.text().trim().split(', ') | ||
expect(actualCodes.join(', ')).to.eq(codes.join(', ')) | ||
}) | ||
|
||
let newCodes | ||
cy.get('*[data-testid="field/lookup_secret_regenerate/true"]').click() | ||
cy.get('*[data-testid="field/lookup_secret_codes/text"]').then(($e) => { | ||
newCodes = $e.text().trim().split(', ') | ||
}) | ||
cy.get('*[data-testid="field/lookup_secret_confirm/true"]').click() | ||
cy.get('*[data-testid="field/lookup_secret_reveal/true"]').click() | ||
cy.get('*[data-testid="field/lookup_secret_codes/text"]').then(($e) => { | ||
const actualCodes = $e.text().trim().split(', ') | ||
expect(actualCodes.join(', ')).to.eq(newCodes.join(', ')) | ||
}) | ||
|
||
cy.visit(MOBILE_URL + '/Login?aal=aal2') | ||
|
||
// First use a wrong code | ||
cy.get('*[data-testid="field/lookup_secret"]').then(($e) => { | ||
cy.wrap($e).type(codes[0]) | ||
}) | ||
cy.get('*[data-testid="field/method/lookup_secret"]').click() | ||
cy.get('*[data-testid="form-messages"]').should( | ||
'contain.text', | ||
'The backup recovery code is not valid.' | ||
) | ||
cy.get('*[data-testid="field/lookup_secret"]').then(($e) => { | ||
cy.wrap($e).type(newCodes[0]) | ||
}) | ||
cy.get('*[data-testid="field/method/lookup_secret"]').click() | ||
cy.get('[data-testid="session-content"]').should('contain', 'aal2') | ||
cy.get('[data-testid="session-content"]').should( | ||
'contain', | ||
'lookup_secret' | ||
) | ||
}) | ||
}) | ||
}) | ||
}) |
74 changes: 74 additions & 0 deletions
74
test/e2e/cypress/integration/profiles/mobile/mfa/mix.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { APP_URL, gen, MOBILE_URL, website } from '../../../../helpers' | ||
import { authenticator } from 'otplib' | ||
|
||
context('Mobile Profile', () => { | ||
describe('TOTP 2FA Flow', () => { | ||
before(() => { | ||
cy.useConfigProfile('mobile') | ||
}) | ||
|
||
describe('password', () => { | ||
const email = gen.email() | ||
const password = gen.password() | ||
|
||
before(() => { | ||
cy.registerApi({ | ||
email, | ||
password, | ||
fields: { 'traits.website': website } | ||
}) | ||
}) | ||
|
||
beforeEach(() => { | ||
cy.loginMobile({ email, password }) | ||
cy.visit(MOBILE_URL + '/Settings') | ||
}) | ||
|
||
it('should be able to use both TOTP and lookup', () => { | ||
// set up totp | ||
let totpSecret | ||
cy.get('*[data-testid="field/totp_secret_key/text"]').then(($e) => { | ||
totpSecret = $e.text().trim() | ||
}) | ||
cy.get('*[data-testid="field/totp_code"]').then(($e) => { | ||
cy.wrap($e).type(authenticator.generate(totpSecret)) | ||
}) | ||
cy.get('*[data-testid="field/method/totp"]').click() | ||
|
||
// Set up backup code | ||
cy.get('*[data-testid="field/lookup_secret_regenerate/true"]').click() | ||
let recoveryCodes | ||
cy.get('*[data-testid="field/lookup_secret_codes/text"]').then(($e) => { | ||
recoveryCodes = $e.text().trim().split(', ') | ||
}) | ||
cy.get('*[data-testid="field/lookup_secret_confirm/true"]').click() | ||
|
||
// Lets sign in with TOTP | ||
cy.visit(MOBILE_URL + '/Login?aal=aal2') | ||
cy.get('*[data-testid="field/totp_code"]').then(($e) => { | ||
cy.wrap($e).type(authenticator.generate(totpSecret)) | ||
}) | ||
cy.get('*[data-testid="field/method/totp"]').click() | ||
|
||
// We have AAL now | ||
cy.get('[data-testid="session-content"]').should('contain', 'aal2') | ||
cy.get('[data-testid="session-content"]').should('contain', 'totp') | ||
|
||
// Lets sign in with lookup secret | ||
cy.visit(MOBILE_URL + '/Login?aal=aal2&refresh=true') | ||
cy.get('*[data-testid="field/lookup_secret"]').then(($e) => { | ||
cy.wrap($e).type(recoveryCodes[0]) | ||
}) | ||
cy.get('*[data-testid="field/method/lookup_secret"]').click() | ||
|
||
// We have AAL now | ||
cy.get('[data-testid="session-content"]').should('contain', 'aal2') | ||
cy.get('[data-testid="session-content"]').should('contain', 'totp') | ||
cy.get('[data-testid="session-content"]').should( | ||
'contain', | ||
'lookup_secret' | ||
) | ||
}) | ||
}) | ||
}) | ||
}) |