MM-20780 MM-20782 Clear cookies on logout (#3645)

This commit is contained in:
Elias Nahum 2019-12-02 21:33:09 -03:00 committed by Saturnino Abril
parent 9096818003
commit 59c8cbed55
5 changed files with 36 additions and 17 deletions

View file

@ -2,7 +2,9 @@
// See LICENSE.txt for license information.
import {Alert, AppState, Dimensions, Linking, NativeModules, Platform} from 'react-native';
import CookieManager from 'react-native-cookies';
import DeviceInfo from 'react-native-device-info';
import RNFetchBlob from 'rn-fetch-blob';
import semver from 'semver';
import {setAppState, setServerVersion} from 'mattermost-redux/actions/general';
@ -22,6 +24,7 @@ import {showOverlay} from 'app/actions/navigation';
import {loadConfigAndLicense, setDeepLinkURL, startDataCleanup} from 'app/actions/views/root';
import {NavigationTypes, ViewTypes} from 'app/constants';
import {getTranslations, resetMomentLocale} from 'app/i18n';
import mattermostBucket from 'app/mattermost_bucket';
import mattermostManaged from 'app/mattermost_managed';
import PushNotifications from 'app/push_notifications';
import {getCurrentLocale} from 'app/selectors/i18n';
@ -148,11 +151,30 @@ class GlobalEventHandler {
onLogout = async () => {
this.store.dispatch(closeWebSocket(false));
this.store.dispatch(setServerVersion(''));
deleteFileCache();
removeAppCredentials();
deleteFileCache();
resetMomentLocale();
// TODO: Handle when multi-server support is added
CookieManager.clearAll(Platform.OS === 'ios');
PushNotifications.clearNotifications();
const cacheDir = RNFetchBlob.fs.dirs.CacheDir;
const mainPath = cacheDir.split('/').slice(0, -1).join('/');
await RNFetchBlob.fs.unlink(cacheDir);
mattermostBucket.removePreference('cert');
if (Platform.OS === 'ios') {
mattermostBucket.removeFile('entities');
} else {
const cookies = await RNFetchBlob.fs.exists(`${mainPath}/app_webview/Cookies`);
const cookiesJ = await RNFetchBlob.fs.exists(`${mainPath}/app_webview/Cookies-journal`);
if (cookies) {
RNFetchBlob.fs.unlink(`${mainPath}/app_webview/Cookies`);
}
if (cookiesJ) {
RNFetchBlob.fs.unlink(`${mainPath}/app_webview/Cookies-journal`);
}
}
if (this.launchApp) {
this.launchApp();

View file

@ -6,6 +6,7 @@ import thunk from 'redux-thunk';
import intitialState from 'app/initial_state';
import PushNotification from 'app/push_notifications';
import mattermostBucket from 'app/mattermost_bucket';
import * as I18n from 'app/i18n';
import GlobalEventHandler from './global_event_handler';
@ -43,10 +44,14 @@ describe('GlobalEventHandler', () => {
it('should clear notifications and reset moment locale on logout', async () => {
const clearNotifications = jest.spyOn(PushNotification, 'clearNotifications');
const resetMomentLocale = jest.spyOn(I18n, 'resetMomentLocale');
const removePreference = jest.spyOn(mattermostBucket, 'removePreference');
const removeFile = jest.spyOn(mattermostBucket, 'removeFile');
await GlobalEventHandler.onLogout();
expect(clearNotifications).toHaveBeenCalled();
expect(resetMomentLocale).toHaveBeenCalledWith();
expect(resetMomentLocale).toHaveBeenCalled();
expect(removePreference).toHaveBeenCalledWith('cert');
expect(removeFile).toHaveBeenCalledWith('entities');
});
it('should call onAppStateChange after configuration', () => {

View file

@ -5,7 +5,6 @@ import React, {PureComponent} from 'react';
import PropTypes from 'prop-types';
import {injectIntl, intlShape} from 'react-intl';
import {
InteractionManager,
Text,
View,
Platform,
@ -81,7 +80,7 @@ class SSO extends PureComponent {
this.state = {
error: null,
renderWebView: false,
renderWebView: true,
jsCode: '',
messagingEnabled: false,
};
@ -106,16 +105,6 @@ class SSO extends PureComponent {
}
}
componentDidMount() {
InteractionManager.runAfterInteractions(this.clearPreviousCookies);
}
clearPreviousCookies = () => {
CookieManager.clearAll(this.useWebkit).then(() => {
this.setState({renderWebView: true});
});
};
goToChannel = () => {
tracker.initialLoad = Date.now();
@ -232,7 +221,8 @@ class SSO extends PureComponent {
onLoadEnd={this.onLoadEnd}
onMessage={messagingEnabled ? this.onMessage : null}
useSharedProcessPool={true}
cacheEnabled={true}
sharedCookiesEnabled={true}
cacheEnabled={false}
/>
);
}

View file

@ -103,6 +103,7 @@ export async function deleteFileCache() {
if (isVideosDir) {
await RNFetchBlob.fs.unlink(VIDEOS_PATH);
}
return true;
}

View file

@ -117,6 +117,7 @@ jest.mock('react-native-cookies', () => ({
openURL: jest.fn(),
canOpenURL: jest.fn(),
getInitialURL: jest.fn(),
clearAll: jest.fn(),
}));
jest.mock('react-native-navigation', () => {
@ -201,7 +202,7 @@ jest.mock('rn-fetch-blob', () => ({
fs: {
dirs: {
DocumentDir: () => jest.fn(),
CacheDir: () => jest.fn(),
CacheDir: '/data/com.mattermost.beta/cache',
},
exists: jest.fn(),
existsWithDiffExt: jest.fn(),
@ -215,7 +216,7 @@ jest.mock('rn-fetch-blob', () => ({
jest.mock('rn-fetch-blob/fs', () => ({
dirs: {
DocumentDir: () => jest.fn(),
CacheDir: () => jest.fn(),
CacheDir: '/data/com.mattermost.beta/cache',
},
exists: jest.fn(),
existsWithDiffExt: jest.fn(),