Chance encryption reducer a little bit and fix tests
This commit is contained in:
parent
74b59a305e
commit
da7403c5d4
File diff suppressed because one or more lines are too long
|
@ -51,7 +51,7 @@ export function encryptionDecodeKey(password: string): IEncryptionDecodeKey {
|
|||
};
|
||||
}
|
||||
|
||||
export function encryptionDecodeKeyFailed(): Action {
|
||||
export function encryptionDecodeKeyFailure(): Action {
|
||||
return {
|
||||
type: ENCRYPTION.DECODE_KEY_FAILURE
|
||||
};
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
import { encryptionSet, encryptionInit, encryptionSetBanner } from '../actions/encryption';
|
||||
import {
|
||||
encryptionSet,
|
||||
encryptionInit,
|
||||
encryptionSetBanner,
|
||||
encryptionDecodeKey,
|
||||
encryptionDecodeKeyFailure
|
||||
} from '../actions/encryption';
|
||||
import { mockedStore } from './mockedStore';
|
||||
import { initialState } from './encryption';
|
||||
|
||||
|
@ -11,18 +17,29 @@ describe('test encryption reducer', () => {
|
|||
it('should return modified store after encryptionSet', () => {
|
||||
mockedStore.dispatch(encryptionSet(true, 'BANNER'));
|
||||
const state = mockedStore.getState().encryption;
|
||||
expect(state).toEqual({ banner: 'BANNER', enabled: true });
|
||||
expect(state).toEqual({ banner: 'BANNER', enabled: true, failure: false });
|
||||
});
|
||||
|
||||
it('should return empty store after encryptionInit', () => {
|
||||
mockedStore.dispatch(encryptionInit());
|
||||
const state = mockedStore.getState().encryption;
|
||||
expect(state).toEqual({ banner: '', enabled: false });
|
||||
expect(state).toEqual({ banner: '', enabled: false, failure: false });
|
||||
});
|
||||
|
||||
it('should return initial state after encryptionSetBanner', () => {
|
||||
mockedStore.dispatch(encryptionSetBanner('BANNER_NEW'));
|
||||
const state = mockedStore.getState().encryption;
|
||||
expect(state).toEqual({ banner: 'BANNER_NEW', enabled: false });
|
||||
expect(state).toEqual({ banner: 'BANNER_NEW', enabled: false, failure: false });
|
||||
});
|
||||
|
||||
it('should return decode key state changes', () => {
|
||||
mockedStore.dispatch(encryptionInit());
|
||||
mockedStore.dispatch(encryptionDecodeKey('asd'));
|
||||
const state = mockedStore.getState().encryption;
|
||||
expect(state).toEqual({ ...initialState, failure: false });
|
||||
|
||||
mockedStore.dispatch(encryptionDecodeKeyFailure());
|
||||
const stateF = mockedStore.getState().encryption;
|
||||
expect(stateF).toEqual({ ...initialState, failure: true });
|
||||
});
|
||||
});
|
||||
|
|
|
@ -11,7 +11,7 @@ export interface IEncryption {
|
|||
export const initialState: IEncryption = {
|
||||
enabled: false,
|
||||
banner: '',
|
||||
failure: true
|
||||
failure: false
|
||||
};
|
||||
|
||||
export default function encryption(state = initialState, action: TApplicationActions): IEncryption {
|
||||
|
|
|
@ -2,15 +2,11 @@ import EJSON from 'ejson';
|
|||
import { put, select, takeLatest } from 'redux-saga/effects';
|
||||
|
||||
import { ENCRYPTION } from '../actions/actionsTypes';
|
||||
import { encryptionDecodeKeyFailed, encryptionSet } from '../actions/encryption';
|
||||
import { encryptionDecodeKeyFailure, encryptionSet } from '../actions/encryption';
|
||||
import { Encryption } from '../lib/encryption';
|
||||
import Navigation from '../lib/navigation/appNavigation';
|
||||
import database from '../lib/database';
|
||||
import UserPreferences from '../lib/methods/userPreferences';
|
||||
import { getUserSelector } from '../selectors/login';
|
||||
import { showErrorAlert } from '../lib/methods/helpers/info';
|
||||
import { showToast } from '../lib/methods/helpers/showToast';
|
||||
import I18n from '../i18n';
|
||||
import log from '../lib/methods/helpers/log';
|
||||
import { E2E_BANNER_TYPE, E2E_PRIVATE_KEY, E2E_PUBLIC_KEY, E2E_RANDOM_PASSWORD_KEY } from '../lib/constants';
|
||||
import { Services } from '../lib/services';
|
||||
|
@ -114,7 +110,7 @@ const handleEncryptionDecodeKey = function* handleEncryptionDecodeKey({ password
|
|||
yield put(encryptionSet(true));
|
||||
} catch {
|
||||
// Can't decrypt user private key
|
||||
yield put(encryptionDecodeKeyFailed());
|
||||
yield put(encryptionDecodeKeyFailure());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -39,8 +39,7 @@ const E2EEnterYourPasswordView = (): React.ReactElement => {
|
|||
|
||||
/**
|
||||
* If e2ee is enabled, close screen and display success toast.
|
||||
* Note: Debounce prevents `isFocused` from running another re-render
|
||||
* and triggering another toast
|
||||
* Note: Debounce prevents `isFocused` from running another re-render and triggering another toast
|
||||
*/
|
||||
const displayEncryptionEnabled = useDebounce(
|
||||
() => {
|
||||
|
@ -56,14 +55,12 @@ const E2EEnterYourPasswordView = (): React.ReactElement => {
|
|||
}
|
||||
|
||||
// Wrong password
|
||||
if (encryptionFailure !== prevEncryptionFailure) {
|
||||
if (encryptionFailure && password) {
|
||||
showErrorAlert(I18n.t('Encryption_error_desc'), I18n.t('Encryption_error_title'));
|
||||
}
|
||||
if (encryptionFailure !== prevEncryptionFailure && encryptionFailure && password) {
|
||||
showErrorAlert(I18n.t('Encryption_error_desc'), I18n.t('Encryption_error_title'));
|
||||
}
|
||||
|
||||
// If screen is closed and e2ee is still disabled, warns the user via toast
|
||||
if (!isFocused && encryptionFailure && !encryptionEnabled) {
|
||||
if (!isFocused && !encryptionEnabled) {
|
||||
showToast(I18n.t('e2ee_disabled'));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue