Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 2fa check on reset password if 2fa have invalid setup #312

Merged
merged 1 commit into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion web/api/reset_password.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ func (ar *Router) RequestResetPassword() http.HandlerFunc {
return
}

if user.TFAInfo.IsEnabled && ar.tfaType != model.TFATypeEmail {
_, enabled2FA, _ := ar.check2FA(app.TFAStatus, ar.tfaType, user)

if enabled2FA && ar.tfaType != model.TFATypeEmail {
if d.TFACode != "" {
otpVerified, err := ar.verifyOTPCode(user, d.TFACode)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('simple login by email', () => {
it('login with remember', () => {
cy.serverSetLoginOptions({ login_with: { username: false, phone: false, email: true, federated: false }, tfa_type: 'app' });
cy.visitLogin();
cy.loginWithEmail(undefined, undefined, true);
cy.loginWithEmail({ remember: true });
cy.verifyRefreshSuccessToken();
cy.screenshot();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ describe('simple reset password with tfa email', () => {
before(() => {
cy.createAppAndUser();
cy.appSet({ tfa_status: 'mandatory' });
cy.userSet({ phone: '+1234567890', tfa_info: { is_enabled: true, phone: '+1234567890' } });
cy.userSet({ phone: '+1234567890', tfa_info: { is_enabled: true, phone: '+1234567890', secret: 'TND2SXAH76TAS55J' } });
});
after(() => {
cy.deleteAppAndUser();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
describe('2fa mandatory email', () => {
before(() => {
cy.createApp();
cy.createUser({ tfa_info: { is_enabled: true } });
cy.serverSetLoginOptions({ login_with: { username: false, phone: false, email: true, federated: false }, tfa_type: 'sms' });
cy.appSet({ tfa_status: 'mandatory' });
});
after(() => {
cy.deleteAppAndUser();
});
it('forgot by email with 2fa sms', () => {
cy.visitLogin();
cy.contains('Forgot password').click();
cy.get('#email').click().type('test@test.com');
cy.screenshot();
cy.contains('Send the link').click();
cy.contains('We sent you an email with a link');
cy.contains('Go back to login');
cy.screenshot();
cy.getResetTokenURL().then(url => {
cy.visit(url);
});
cy.contains('Set up a new password');
cy.get('#password').click().type('NewPassword');
cy.screenshot();
cy.contains('Save password').click().type('NewPassword');

cy.loginWithEmail({ password: 'NewPassword' });
cy.contains('Use phone as 2fa');
cy.contains('Go back to login');
cy.get('[placeholder=Phone]').click().type('+0123456789');
cy.screenshot();
cy.contains('Setup phone').click();
cy.verifyTfa();
cy.verifySuccessToken();
cy.screenshot();
});
});
11 changes: 7 additions & 4 deletions web_apps_src/web-element/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ Cypress.Commands.add('deleteAppAndUser', async data => {
await login();
await deleteTestApp();
await deleteTestUser();
await deleteTestUserBySearch();
});
// Change app settings
Cypress.Commands.add('appSet', async data => {
Expand Down Expand Up @@ -203,6 +204,7 @@ Cypress.Commands.add('userSet', async data => {

Cypress.Commands.add('getResetTokenURL', async () => {
await login();
console.log(userId);
const resetTokenData = await fetch(`${adminUrl}/users/generate_new_reset_token`, {
body: JSON.stringify({ user_id: userId, app_id: lastAppId }),
method: 'POST',
Expand All @@ -227,10 +229,11 @@ Cypress.Commands.add('visitLogin', options => {
window.localStorage.setItem('debug', true);
return cy.visit(`${Cypress.config('baseUrl')}/login/?${new URLSearchParams({ ...options, appId: lastAppId, url: Cypress.config('serverUrl') }).toString()}`);
});
Cypress.Commands.add('loginWithEmail', (email = 'test@test.com', password = 'Password', remember = false) => {
cy.get('[placeholder=Email]').click().type(email);
cy.get('[placeholder=Password]').click().type(password);
if (remember) {
Cypress.Commands.add('loginWithEmail', p => {
const login = { ...{ email: 'test@test.com', password: 'Password', remember: false }, ...p };
cy.get('[placeholder=Email]').click().type(login.email);
cy.get('[placeholder=Password]').click().type(login.password);
if (login.remember) {
cy.contains('Remember me').click();
}
cy.screenshot();
Expand Down