Skip to content

Commit

Permalink
test(e2e): add tests for multiple passcode incorrect functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
coldlink committed Feb 6, 2025
1 parent 1001900 commit 3400255
Show file tree
Hide file tree
Showing 3 changed files with 322 additions and 0 deletions.
115 changes: 115 additions & 0 deletions cypress/integration/ete/registration_1.2.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,62 @@ describe('Registration flow - Split 1/2', () => {
},
);
});

it('should redirect with error when multiple passcode attempts fail', () => {
const unregisteredEmail = randomMailosaurEmail();
cy.visit(`/register/email`);

const timeRequestWasMade = new Date();
cy.get('input[name=email]').type(unregisteredEmail);
cy.get('[data-cy="main-form-submit-button"]').click();

cy.contains('Enter your code');
cy.contains(unregisteredEmail);
cy.contains('send again');
cy.contains('try another address');

cy.checkForEmailAndGetDetails(unregisteredEmail, timeRequestWasMade).then(
({ body, codes }) => {
// email
expect(body).to.have.string('Your verification code');
expect(codes?.length).to.eq(1);
const code = codes?.[0].value;
expect(code).to.match(/^\d{6}$/);

// passcode page
cy.url().should('include', '/register/email-sent');

// attempt 1 - auto submit
cy.contains('Submit verification code');
cy.get('input[name=code]').type('000000');
cy.contains('Incorrect code');
cy.url().should('include', '/register/code');

// attempt 2 - manual submit
cy.get('input[name=code]').type('000000');
cy.contains('Submit verification code').click();
cy.contains('Incorrect code');
cy.url().should('include', '/register/code');

// attempt 3
cy.get('input[name=code]').type('000000');
cy.contains('Submit verification code').click();
cy.contains('Incorrect code');
cy.url().should('include', '/register/code');

// attempt 4
cy.get('input[name=code]').type('000000');
cy.contains('Submit verification code').click();
cy.contains('Incorrect code');
cy.url().should('include', '/register/code');

// attempt 5
cy.get('input[name=code]').type('000000');
cy.contains('Submit verification code').click();
cy.url().should('include', '/welcome/expired');
},
);
});
});

context('existing user going through registration flow', () => {
Expand Down Expand Up @@ -600,6 +656,65 @@ describe('Registration flow - Split 1/2', () => {
});
});

it('should redirect with error when multiple passcode attempts fail', () => {
cy
.createTestUser({
isUserEmailValidated: true,
})
?.then(({ emailAddress }) => {
cy.setCookie('cypress-mock-state', '1'); // passcode send again timer

cy.visit(`/register/email`);
cy.get('input[name=email]').clear().type(emailAddress);

const timeRequestWasMade = new Date();
cy.get('[data-cy="main-form-submit-button"]').click();

cy.checkForEmailAndGetDetails(emailAddress, timeRequestWasMade).then(
({ body, codes }) => {
// email
expect(body).to.have.string('Your one-time passcode');
expect(codes?.length).to.eq(1);
const code = codes?.[0].value;
expect(code).to.match(/^\d{6}$/);

// passcode page
cy.url().should('include', '/register/email-sent');
cy.contains('Enter your code');

// attempt 1 - auto submit
cy.contains('Submit verification code');
cy.get('input[name=code]').type('000000');
cy.contains('Incorrect code');
cy.url().should('include', '/register/code');

// attempt 2 - manual submit
cy.get('input[name=code]').type('000000');
cy.contains('Submit verification code').click();
cy.contains('Incorrect code');
cy.url().should('include', '/register/code');

// attempt 3
cy.get('input[name=code]').type('000000');
cy.contains('Submit verification code').click();
cy.contains('Incorrect code');
cy.url().should('include', '/register/code');

// attempt 4
cy.get('input[name=code]').type('000000');
cy.contains('Submit verification code').click();
cy.contains('Incorrect code');
cy.url().should('include', '/register/code');

// attempt 5
cy.get('input[name=code]').type('000000');
cy.contains('Submit verification code').click();
cy.url().should('include', '/register/email');
},
);
});
});

context('ACTIVE user - with only password authenticator', () => {
it('should sign in with passcode', () => {
/**
Expand Down
105 changes: 105 additions & 0 deletions cypress/integration/ete/reset_password_passcode.7.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,68 @@ describe('Password reset recovery flows - with Passcodes', () => {
});
});

it('should redirect with error when multiple passcode attempts fail', () => {
cy
.createTestUser({
isUserEmailValidated: true,
})
?.then(({ emailAddress }) => {
cy.visit(`/reset-password`);

const timeRequestWasMade = new Date();
cy.get('input[name=email]').type(emailAddress);
cy.get('[data-cy="main-form-submit-button"]').click();

cy.contains('Enter your one-time code');
cy.contains(emailAddress);
cy.contains('send again');
cy.contains('try another address');

cy.checkForEmailAndGetDetails(emailAddress, timeRequestWasMade).then(
({ body, codes }) => {
// email
expect(body).to.have.string('Your one-time passcode');
expect(codes?.length).to.eq(1);
const code = codes?.[0].value;
expect(code).to.match(/^\d{6}$/);

// passcode page
cy.url().should('include', '/reset-password/email-sent');
cy.contains('Enter your one-time code');

// attempt 1 - auto submit
cy.contains('Submit one-time code');
cy.get('input[name=code]').type(`${+code! + 1}`);
cy.url().should('include', '/reset-password/code');
cy.contains('Incorrect code');

// attempt 2 - manual submit
cy.get('input[name=code]').type(`${+code! + 1}`);
cy.contains('Submit one-time code').click();
cy.url().should('include', '/reset-password/code');
cy.contains('Incorrect code');

// attempt 3 - manual submit
cy.get('input[name=code]').type(`${+code! + 1}`);
cy.contains('Submit one-time code').click();
cy.url().should('include', '/reset-password/code');
cy.contains('Incorrect code');

// attempt 4 - manual submit
cy.get('input[name=code]').type(`${+code! + 1}`);
cy.contains('Submit one-time code').click();
cy.url().should('include', '/reset-password/code');
cy.contains('Incorrect code');

// attempt 5 - manual submit
cy.get('input[name=code]').type(`${+code! + 1}`);
cy.contains('Submit one-time code').click();
cy.url().should('include', '/reset-password/expired');
},
);
});
});

it('ACTIVE user with only password authenticator - allow the user to change thier password and authenticate', () => {
const emailAddress = randomMailosaurEmail();
cy.visit(`/register/email`);
Expand Down Expand Up @@ -741,5 +803,48 @@ describe('Password reset recovery flows - with Passcodes', () => {

cy.contains('Incorrect code');
});

it('should redirect with error when multiple passcode attempts fail', () => {
const emailAddress = randomMailosaurEmail();
cy.visit(`/reset-password`);

cy.contains('Reset password');
cy.get('input[name=email]').type(emailAddress);
cy.get('[data-cy="main-form-submit-button"]').click();

// passcode page
cy.url().should('include', '/reset-password/email-sent');
cy.contains('Enter your one-time code');
cy.contains('Don’t have an account?');

// attempt 1
cy.contains('Submit one-time code');
cy.get('input[name=code]').type('123456');
cy.url().should('include', '/reset-password/code');
cy.contains('Incorrect code');

// attempt 2
cy.get('input[name=code]').type('123456');
cy.contains('Submit one-time code').click();
cy.url().should('include', '/reset-password/code');
cy.contains('Incorrect code');

// attempt 3
cy.get('input[name=code]').type('123456');
cy.contains('Submit one-time code').click();
cy.url().should('include', '/reset-password/code');
cy.contains('Incorrect code');

// attempt 4
cy.get('input[name=code]').type('123456');
cy.contains('Submit one-time code').click();
cy.url().should('include', '/reset-password/code');
cy.contains('Incorrect code');

// attempt 5
cy.get('input[name=code]').type('123456');
cy.contains('Submit one-time code').click();
cy.url().should('include', '/reset-password/expired');
});
});
});
102 changes: 102 additions & 0 deletions cypress/integration/ete/sign_in_passcode.8.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,64 @@ describe('Sign In flow, with passcode', () => {
});
});
});

it('should redirect with error when multiple passcode attempts fail', () => {
cy
.createTestUser({
isUserEmailValidated: true,
})
?.then(({ emailAddress }) => {
cy.visit(`/signin?usePasscodeSignIn=true`);
cy.get('input[name=email]').clear().type(emailAddress);

const timeRequestWasMade = new Date();
cy.get('[data-cy="main-form-submit-button"]').click();

cy.checkForEmailAndGetDetails(emailAddress, timeRequestWasMade).then(
({ body, codes }) => {
// email
expect(body).to.have.string('Your one-time passcode');
expect(codes?.length).to.eq(1);
const code = codes?.[0].value;
expect(code).to.match(/^\d{6}$/);

// passcode page
cy.url().should('include', '/signin/code');
cy.contains('Enter your one-time code');

// attempt 1
cy.contains('Sign in');
cy.get('input[name=code]').type(`${+code! + 1}`);
cy.url().should('include', '/signin/code');
cy.contains('Incorrect code');

// attempt 2
cy.get('input[name=code]').type(`${+code! + 1}`);
cy.contains('Sign in').click();
cy.url().should('include', '/signin/code');
cy.contains('Incorrect code');

// attempt 3
cy.get('input[name=code]').type(`${+code! + 1}`);
cy.contains('Sign in').click();
cy.url().should('include', '/signin/code');
cy.contains('Incorrect code');

// attempt 4
cy.get('input[name=code]').type(`${+code! + 1}`);
cy.contains('Sign in').click();
cy.url().should('include', '/signin/code');
cy.contains('Incorrect code');

// attempt 5
cy.get('input[name=code]').type(`${+code! + 1}`);
cy.contains('Sign in').click();
cy.url().should('include', '/signin');
cy.contains('Your code has expired');
},
);
});
});
});

context('ACTIVE user - with only password authenticator', () => {
Expand Down Expand Up @@ -398,5 +456,49 @@ describe('Sign In flow, with passcode', () => {

cy.contains('Incorrect code');
});

it('NON_EXISTENT user - should redirect with error when multiple passcode attempts fail', () => {
const emailAddress = randomMailosaurEmail();
cy.visit(`/signin?usePasscodeSignIn=true`);

cy.contains('Sign in');
cy.get('input[name=email]').type(emailAddress);
cy.get('[data-cy="main-form-submit-button"]').click();

// passcode page
cy.url().should('include', '/signin/code');
cy.contains('Enter your one-time code');
cy.contains('Don’t have an account?');

// attempt 1
cy.contains('Sign in');
cy.get('input[name=code]').type('123456');
cy.url().should('include', '/signin/code');
cy.contains('Incorrect code');

// attempt 2
cy.get('input[name=code]').type('123456');
cy.contains('Sign in').click();
cy.url().should('include', '/signin/code');
cy.contains('Incorrect code');

// attempt 3
cy.get('input[name=code]').type('123456');
cy.contains('Sign in').click();
cy.url().should('include', '/signin/code');
cy.contains('Incorrect code');

// attempt 4
cy.get('input[name=code]').type('123456');
cy.contains('Sign in').click();
cy.url().should('include', '/signin/code');
cy.contains('Incorrect code');

// attempt 5
cy.get('input[name=code]').type('123456');
cy.contains('Sign in').click();
cy.url().should('include', '/signin');
cy.contains('Your code has expired');
});
});
});

0 comments on commit 3400255

Please sign in to comment.