-
Notifications
You must be signed in to change notification settings - Fork 1.5k
test: e2e encryption banner race and iOS Maestro shard 11 timeout #7663
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
Merged
+196
−7
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
db655c9
fix: wait for E2E_Enable before skipping encryption init and rebalanc…
diegolmello 9f2e54e
test: move jump-to-message expectation from shard 11 to shard 5 in sn…
diegolmello 2010504
Merge branch 'develop' into diegolmello/e2e-flaky-encryption-banner
diegolmello File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,167 @@ | ||
| jest.mock('../../lib/methods/userPreferences', () => ({ | ||
| __esModule: true, | ||
| default: { | ||
| getString: jest.fn() | ||
| } | ||
| })); | ||
|
|
||
| jest.mock('../../lib/services/restApi', () => ({ | ||
| e2eFetchMyKeys: jest.fn() | ||
| })); | ||
|
|
||
| jest.mock('../../lib/methods/readMessages', () => ({ | ||
| readMessages: jest.fn() | ||
| })); | ||
|
|
||
| jest.mock('../../lib/methods/helpers/log', () => ({ | ||
| __esModule: true, | ||
| default: jest.fn() | ||
| })); | ||
|
|
||
| jest.mock('../../lib/encryption', () => ({ | ||
| Encryption: { | ||
| initialize: jest.fn(), | ||
| persistKeys: jest.fn(), | ||
| createKeys: jest.fn(), | ||
| decodePrivateKey: jest.fn(), | ||
| stop: jest.fn() | ||
| } | ||
| })); | ||
|
|
||
| const mockServersFind = jest.fn(); | ||
|
|
||
| jest.mock('../../lib/database', () => ({ | ||
| __esModule: true, | ||
| default: { | ||
| servers: { | ||
| get: jest.fn(() => ({ | ||
| find: () => mockServersFind() | ||
| })) | ||
| } | ||
| } | ||
| })); | ||
|
|
||
| import encryptionRoot from '../encryption'; | ||
| import { encryptionInit } from '../../actions/encryption'; | ||
| import { addSettings } from '../../actions/settings'; | ||
| import { setUser, logout } from '../../actions/login'; | ||
| import { selectServerSuccess, selectServerRequest } from '../../actions/server'; | ||
| import UserPreferences from '../../lib/methods/userPreferences'; | ||
| import { e2eFetchMyKeys } from '../../lib/services/restApi'; | ||
| import { Encryption } from '../../lib/encryption'; | ||
| import { E2E_BANNER_TYPE } from '../../lib/constants/keys'; | ||
| import { cancelSagaTasks, createRecordingStore, flushSagaMicrotasks } from '../../lib/testUtils/sagaStore'; | ||
| import type { RecordingStore } from '../../lib/testUtils/sagaStore'; | ||
|
|
||
| const setupStore = (): RecordingStore => createRecordingStore(encryptionRoot); | ||
|
|
||
| const SERVER_URL = 'https://open.rocket.chat'; | ||
| const USER = { id: 'user-1', token: 'token-1', username: 'diego' }; | ||
|
|
||
| const selectServerAndLogin = (store: RecordingStore['store']) => { | ||
| store.dispatch(selectServerSuccess({ server: SERVER_URL, version: '7.0.0', name: 'Open' })); | ||
| store.dispatch(setUser(USER)); | ||
| }; | ||
|
|
||
| describe('encryption saga — settings arriving after ENCRYPTION.INIT', () => { | ||
| beforeEach(() => { | ||
| jest.mocked(UserPreferences.getString).mockReturnValue(null); | ||
| jest.mocked(e2eFetchMyKeys).mockResolvedValue({ privateKey: 'private-key' } as any); | ||
| mockServersFind.mockReset().mockRejectedValue(new Error('not found')); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| cancelSagaTasks(); | ||
| }); | ||
|
|
||
| it('sets the banner once E2E_Enable arrives after ENCRYPTION.INIT', async () => { | ||
| const { store } = setupStore(); | ||
| selectServerAndLogin(store); | ||
|
|
||
| store.dispatch(encryptionInit()); | ||
| await flushSagaMicrotasks(); | ||
|
|
||
| expect(store.getState().encryption.banner).toBe(''); | ||
|
|
||
| store.dispatch(addSettings({ E2E_Enable: true })); | ||
| await flushSagaMicrotasks(); | ||
|
|
||
| expect(store.getState().encryption.banner).toBe(E2E_BANNER_TYPE.REQUEST_PASSWORD); | ||
| expect(Encryption.initialize).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('sets the banner immediately when settings are already present', async () => { | ||
| const { store } = setupStore(); | ||
| selectServerAndLogin(store); | ||
| store.dispatch(addSettings({ E2E_Enable: true })); | ||
|
|
||
| store.dispatch(encryptionInit()); | ||
| await flushSagaMicrotasks(); | ||
|
|
||
| expect(store.getState().encryption.banner).toBe(E2E_BANNER_TYPE.REQUEST_PASSWORD); | ||
| }); | ||
|
|
||
| it('leaves the banner unset when E2E_Enable arrives as false', async () => { | ||
| const { store } = setupStore(); | ||
| selectServerAndLogin(store); | ||
|
|
||
| store.dispatch(encryptionInit()); | ||
| await flushSagaMicrotasks(); | ||
|
|
||
| store.dispatch(addSettings({ E2E_Enable: false })); | ||
| await flushSagaMicrotasks(); | ||
|
|
||
| expect(store.getState().encryption.banner).toBe(''); | ||
| expect(Encryption.initialize).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('sets the banner when the servers row exists with E2E_Enable undefined and settings arrive later', async () => { | ||
| mockServersFind.mockResolvedValue({ E2E_Enable: undefined }); | ||
|
|
||
| const { store } = setupStore(); | ||
| selectServerAndLogin(store); | ||
|
|
||
| store.dispatch(encryptionInit()); | ||
| await flushSagaMicrotasks(); | ||
|
|
||
| expect(store.getState().encryption.banner).toBe(''); | ||
|
|
||
| store.dispatch(addSettings({ E2E_Enable: true })); | ||
| await flushSagaMicrotasks(); | ||
|
|
||
| expect(store.getState().encryption.banner).toBe(E2E_BANNER_TYPE.REQUEST_PASSWORD); | ||
| }); | ||
|
|
||
| it('stops waiting for settings once the user logs out', async () => { | ||
| const { store } = setupStore(); | ||
| selectServerAndLogin(store); | ||
|
|
||
| store.dispatch(encryptionInit()); | ||
| await flushSagaMicrotasks(); | ||
|
|
||
| store.dispatch(logout(true)); | ||
| await flushSagaMicrotasks(); | ||
|
|
||
| store.dispatch(addSettings({ E2E_Enable: true })); | ||
| await flushSagaMicrotasks(); | ||
|
|
||
| expect(store.getState().encryption.banner).toBe(''); | ||
| }); | ||
|
|
||
| it('stops waiting for settings once a server switch is requested', async () => { | ||
| const { store } = setupStore(); | ||
| selectServerAndLogin(store); | ||
|
|
||
| store.dispatch(encryptionInit()); | ||
| await flushSagaMicrotasks(); | ||
|
|
||
| store.dispatch(selectServerRequest('https://other.rocket.chat', '7.0.0')); | ||
| await flushSagaMicrotasks(); | ||
|
|
||
| store.dispatch(addSettings({ E2E_Enable: true })); | ||
| await flushSagaMicrotasks(); | ||
|
|
||
| expect(store.getState().encryption.banner).toBe(''); | ||
| expect(Encryption.initialize).not.toHaveBeenCalled(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.