2019-12-08 00:32:00 +05:30
|
|
|
import expect from 'app/test/unexpected';
|
2020-01-18 02:07:52 +05:30
|
|
|
import sinon, { SinonMock } from 'sinon';
|
2017-08-23 00:09:08 +05:30
|
|
|
|
|
|
|
import MfaState from './MfaState';
|
2019-12-08 00:32:00 +05:30
|
|
|
import CompleteState from 'app/services/authFlow/CompleteState';
|
|
|
|
import PasswordState from 'app/services/authFlow/PasswordState';
|
2017-08-23 00:09:08 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
import { bootstrap, expectState, expectNavigate, expectRun, MockedAuthContext } from './helpers';
|
2017-08-23 00:09:08 +05:30
|
|
|
|
|
|
|
describe('MfaState', () => {
|
2020-05-24 04:38:24 +05:30
|
|
|
let state: MfaState;
|
|
|
|
let context: MockedAuthContext;
|
|
|
|
let mock: SinonMock;
|
2017-08-23 00:09:08 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
state = new MfaState();
|
2017-08-23 00:09:08 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
const data = bootstrap();
|
|
|
|
context = data.context;
|
|
|
|
mock = data.mock;
|
|
|
|
});
|
2017-08-23 00:09:08 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
afterEach(() => {
|
|
|
|
mock.verify();
|
2019-11-27 14:33:32 +05:30
|
|
|
});
|
2020-05-24 04:38:24 +05:30
|
|
|
|
|
|
|
describe('#enter', () => {
|
|
|
|
it('should navigate to /mfa', () => {
|
|
|
|
context.getState.returns({
|
|
|
|
auth: {
|
|
|
|
credentials: {
|
|
|
|
login: 'foo',
|
|
|
|
password: 'bar',
|
|
|
|
isTotpRequired: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expectNavigate(mock, '/mfa');
|
|
|
|
|
|
|
|
state.enter(context);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should transition to complete if no totp required', () => {
|
|
|
|
context.getState.returns({
|
|
|
|
auth: {
|
|
|
|
credentials: {
|
|
|
|
login: 'foo',
|
|
|
|
password: 'bar',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expectState(mock, CompleteState);
|
|
|
|
|
|
|
|
state.enter(context);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#resolve', () => {
|
|
|
|
it('should call login with login and password', () => {
|
|
|
|
const expectedLogin = 'foo';
|
|
|
|
const expectedPassword = 'bar';
|
|
|
|
const expectedTotp = '111222';
|
|
|
|
const expectedRememberMe = true;
|
|
|
|
|
|
|
|
context.getState.returns({
|
|
|
|
auth: {
|
|
|
|
credentials: {
|
|
|
|
login: expectedLogin,
|
|
|
|
password: expectedPassword,
|
|
|
|
rememberMe: expectedRememberMe,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-10-23 03:53:59 +05:30
|
|
|
expectRun(mock, 'setAccountSwitcher', false);
|
2020-05-24 04:38:24 +05:30
|
|
|
expectRun(
|
|
|
|
mock,
|
|
|
|
'login',
|
|
|
|
sinon.match({
|
|
|
|
totp: expectedTotp,
|
|
|
|
login: expectedLogin,
|
|
|
|
password: expectedPassword,
|
|
|
|
rememberMe: expectedRememberMe,
|
|
|
|
}),
|
|
|
|
).returns(Promise.resolve());
|
|
|
|
expectState(mock, CompleteState);
|
|
|
|
|
|
|
|
const payload = { totp: expectedTotp };
|
|
|
|
|
|
|
|
return expect(state.resolve(context, payload), 'to be fulfilled');
|
|
|
|
});
|
2017-08-23 00:09:08 +05:30
|
|
|
});
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
describe('#goBack', () => {
|
|
|
|
it('should transition to login state', () => {
|
|
|
|
expectState(mock, PasswordState);
|
2017-08-23 00:09:08 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
state.goBack(context);
|
|
|
|
});
|
2017-08-23 00:09:08 +05:30
|
|
|
});
|
|
|
|
});
|