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

[IAMRISK-3553] Swapped CAPTCHA on each reload #2558

Closed
Closed
Show file tree
Hide file tree
Changes from 3 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
209 changes: 208 additions & 1 deletion src/__tests__/connection/database/actions.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
import Immutable, { List, Map } from 'immutable';
import { signUp } from '../../../connection/database/actions';
import {
signUp,
resetPasswordSuccess,
showResetPasswordActivity,
showLoginActivity, showSignUpActivity
} from '../../../connection/database/actions';
import { swap, setEntity } from '../../../store';
import { swapCaptcha } from "../../../connection/captcha";
import { hasScreen } from "../../../connection/database";
Fixed Show fixed Hide fixed

const webApiMock = () => require('core/web_api');
const coreActionsMock = () => require('core/actions');

jest.mock('core/actions', () => ({
validateAndSubmit: jest.fn()
}));

jest.mock('../../../connection/captcha', () => {
const originalCaptcha = jest.requireActual('../../../connection/captcha');
return {
__esModule: true,
...originalCaptcha,
swapCaptcha: jest.fn((id, flow, wasInvalid, next) => {
next();
}),
}
});

jest.mock('core/web_api', () => ({
signUp: jest.fn()
}));
Expand Down Expand Up @@ -208,4 +227,192 @@
}
});
});

describe('resetPasswordSuccess', () => {
it('runs swap CAPTCHA', () => {
const id = 2;
const m = Immutable.fromJS({
field: {
email: {
value: '[email protected]'
},
password: {
value: 'testpass'
},
family_name: {
value: 'test-family-name'
},
given_name: {
value: 'test-given-name'
},
name: {
value: 'test-name'
},
nickname: {
value: 'test-nickname'
},
picture: {
value: 'test-pic'
},
other_prop: {
value: 'test-other'
}
},
database: {
additionalSignUpFields: [
{ name: 'family_name', storage: 'root' },
{ name: 'given_name', storage: 'root' },
{ name: 'name', storage: 'root' },
{ name: 'nickname', storage: 'root' },
{ name: 'picture', storage: 'root' },
{ name: 'other_prop' }
]
},
});
swap(setEntity, 'lock', id, m);
resetPasswordSuccess(id);
expect(swapCaptcha.mock.calls.length).toEqual(1);
});
});

describe('showResetPasswordActivity', () => {
it('runs swap CAPTCHA', () => {
const id = 2;
const m = Immutable.fromJS({
field: {
email: {
value: '[email protected]'
},
password: {
value: 'testpass'
},
family_name: {
value: 'test-family-name'
},
given_name: {
value: 'test-given-name'
},
name: {
value: 'test-name'
},
nickname: {
value: 'test-nickname'
},
picture: {
value: 'test-pic'
},
other_prop: {
value: 'test-other'
}
},
database: {
additionalSignUpFields: [
{ name: 'family_name', storage: 'root' },
{ name: 'given_name', storage: 'root' },
{ name: 'name', storage: 'root' },
{ name: 'nickname', storage: 'root' },
{ name: 'picture', storage: 'root' },
{ name: 'other_prop' }
]
},
});
swap(setEntity, 'lock', id, m);
showResetPasswordActivity(id);
expect(swapCaptcha.mock.calls.length).toEqual(1);
});
});

describe('showLoginActivity', () => {
it('runs swap CAPTCHA', () => {
const id = 2;
const m = Immutable.fromJS({
field: {
email: {
value: '[email protected]'
},
password: {
value: 'testpass'
},
family_name: {
value: 'test-family-name'
},
given_name: {
value: 'test-given-name'
},
name: {
value: 'test-name'
},
nickname: {
value: 'test-nickname'
},
picture: {
value: 'test-pic'
},
other_prop: {
value: 'test-other'
}
},
database: {
additionalSignUpFields: [
{ name: 'family_name', storage: 'root' },
{ name: 'given_name', storage: 'root' },
{ name: 'name', storage: 'root' },
{ name: 'nickname', storage: 'root' },
{ name: 'picture', storage: 'root' },
{ name: 'other_prop' }
]
},
});
swap(setEntity, 'lock', id, m);
showLoginActivity(id);
expect(swapCaptcha.mock.calls.length).toEqual(1);
});
});

describe('showSignupActivity', () => {
it('runs swap CAPTCHA', () => {
const id = 2;
const m = Immutable.fromJS({
field: {
email: {
value: '[email protected]'
},
password: {
value: 'testpass'
},
family_name: {
value: 'test-family-name'
},
given_name: {
value: 'test-given-name'
},
name: {
value: 'test-name'
},
nickname: {
value: 'test-nickname'
},
picture: {
value: 'test-pic'
},
other_prop: {
value: 'test-other'
}
},
database: {
additionalSignUpFields: [
{ name: 'family_name', storage: 'root' },
{ name: 'given_name', storage: 'root' },
{ name: 'name', storage: 'root' },
{ name: 'nickname', storage: 'root' },
{ name: 'picture', storage: 'root' },
{ name: 'other_prop' }
]
},
});
swap(setEntity, 'lock', id, m);
showSignUpActivity(id);
expect(swapCaptcha.mock.calls.length).toEqual(1);
});
});
});
32 changes: 21 additions & 11 deletions src/connection/database/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,17 @@ export function resetPassword(id) {
});
}

function resetPasswordSuccess(id) {
export function resetPasswordSuccess(id) {
const m = read(getEntity, 'lock', id);
if (hasScreen(m, 'login')) {
swap(
updateEntity,
'lock',
id,
m => setScreen(l.setSubmitting(m, false), 'login', ['']) // array with one empty string tells the function to not clear any field
);
swapCaptcha(id, Flow.PASSWORD_RESET, false, () => {
swap(
updateEntity,
'lock',
id,
m => setScreen(l.setSubmitting(m, false), 'login', ['']) // array with one empty string tells the function to not clear any field
);
});

// TODO: should be handled by box
setTimeout(() => {
Expand All @@ -278,7 +280,9 @@ function resetPasswordSuccess(id) {
if (l.ui.autoclose(m)) {
closeLock(id);
} else {
swap(updateEntity, 'lock', id, m => l.setSubmitting(m, false).set('passwordResetted', true));
swapCaptcha(id, Flow.PASSWORD_RESET, false, () => {
swap(updateEntity, 'lock', id, m => l.setSubmitting(m, false).set('passwordResetted', true));
});
}
}
}
Expand All @@ -305,15 +309,21 @@ function resetPasswordError(id, error) {
}

export function showLoginActivity(id, fields = ['password']) {
swap(updateEntity, 'lock', id, setScreen, 'login', fields);
swapCaptcha(id, Flow.PASSWORD_RESET, false, () => {
swap(updateEntity, 'lock', id, setScreen, 'login', fields);
});
}

export function showSignUpActivity(id, fields = ['password']) {
swap(updateEntity, 'lock', id, setScreen, 'signUp', fields);
swapCaptcha(id, Flow.PASSWORD_RESET, false, () => {
swap(updateEntity, 'lock', id, setScreen, 'signUp', fields);
});
}

export function showResetPasswordActivity(id, fields = ['password']) {
swap(updateEntity, 'lock', id, setScreen, 'forgotPassword', fields);
swapCaptcha(id, Flow.PASSWORD_RESET, false, () => {
swap(updateEntity, 'lock', id, setScreen, 'forgotPassword', fields);
});
}

export function cancelResetPassword(id) {
Expand Down