From 704e07127560b54206539e78fe6b7209c7fa85ab Mon Sep 17 00:00:00 2001 From: Gung Wah <41157464+kresnaputra@users.noreply.github.com> Date: Fri, 2 Apr 2021 03:27:46 +0800 Subject: [PATCH] [FIX] E2EE password hiding automatically (#2972) * [FIX] E2EE password hiding automatically * add e2e test * fixed hiding banner * move e2e tests to 01-e2eencryption * remove console.log * Fix tests Co-authored-by: Diego Mello --- app/sagas/encryption.js | 3 +- e2e/data.js | 16 +++++- e2e/data/data.cloud.js | 10 ++++ e2e/data/data.docker.js | 10 ++++ e2e/tests/assorted/01-e2eencryption.spec.js | 64 ++++++++++++++++++++- e2e/tests/assorted/07-changeserver.spec.js | 8 +-- e2e/tests/assorted/10-deleteserver.spec.js | 8 +-- 7 files changed, 106 insertions(+), 13 deletions(-) diff --git a/app/sagas/encryption.js b/app/sagas/encryption.js index 395923a4..842cd7a6 100644 --- a/app/sagas/encryption.js +++ b/app/sagas/encryption.js @@ -69,7 +69,8 @@ const handleEncryptionInit = function* handleEncryptionInit() { storedPublicKey = EJSON.parse(storedPublicKey); } - if (storedPublicKey && storedPrivateKey) { + + if (storedPublicKey && storedPrivateKey && !storedRandomPassword) { // Persist these keys yield Encryption.persistKeys(server, storedPublicKey, storedPrivateKey); yield put(encryptionSet(true)); diff --git a/e2e/data.js b/e2e/data.js index f1dbd1bf..77f9f82c 100644 --- a/e2e/data.js +++ b/e2e/data.js @@ -1,9 +1,9 @@ const random = require('./helpers/random'); const value = random(20); const data = { - server: 'https://mobile.rocket.chat', - adminUser: 'e2e_admin', - adminPassword: 'p7mFh4yLwCRXSnMvG', + server: 'http://localhost:3000', + adminUser: 'admin', + adminPassword: 'password', alternateServer: 'https://stable.rocket.chat', users: { regular: { @@ -47,6 +47,16 @@ const data = { password: `password${ value }`, email: `mobile+registering${ value }@rocket.chat` }, + registeringUser2: { + username: `newusertwo${ value }`, + password: `passwordtwo${ value }`, + email: `mobile+registeringtwo${ value }@rocket.chat` + }, + registeringUser3: { + username: `newuserthree${ value }`, + password: `passwordthree${ value }`, + email: `mobile+registeringthree${ value }@rocket.chat` + }, random: value } module.exports = data; diff --git a/e2e/data/data.cloud.js b/e2e/data/data.cloud.js index f1dbd1bf..381d939f 100644 --- a/e2e/data/data.cloud.js +++ b/e2e/data/data.cloud.js @@ -47,6 +47,16 @@ const data = { password: `password${ value }`, email: `mobile+registering${ value }@rocket.chat` }, + registeringUser2: { + username: `newusertwo${ value }`, + password: `passwordtwo${ value }`, + email: `mobile+registeringtwo${ value }@rocket.chat` + }, + registeringUser3: { + username: `newuserthree${ value }`, + password: `passwordthree${ value }`, + email: `mobile+registeringthree${ value }@rocket.chat` + }, random: value } module.exports = data; diff --git a/e2e/data/data.docker.js b/e2e/data/data.docker.js index a5d56af5..77f9f82c 100644 --- a/e2e/data/data.docker.js +++ b/e2e/data/data.docker.js @@ -47,6 +47,16 @@ const data = { password: `password${ value }`, email: `mobile+registering${ value }@rocket.chat` }, + registeringUser2: { + username: `newusertwo${ value }`, + password: `passwordtwo${ value }`, + email: `mobile+registeringtwo${ value }@rocket.chat` + }, + registeringUser3: { + username: `newuserthree${ value }`, + password: `passwordthree${ value }`, + email: `mobile+registeringthree${ value }@rocket.chat` + }, random: value } module.exports = data; diff --git a/e2e/tests/assorted/01-e2eencryption.spec.js b/e2e/tests/assorted/01-e2eencryption.spec.js index a7a28af7..f3e4bcf9 100644 --- a/e2e/tests/assorted/01-e2eencryption.spec.js +++ b/e2e/tests/assorted/01-e2eencryption.spec.js @@ -8,6 +8,18 @@ const data = require('../../data'); const testuser = data.users.regular const otheruser = data.users.alternate +const checkServer = async(server) => { + const label = `Connected to ${ server }`; + await element(by.id('rooms-list-view-sidebar')).tap(); + await waitFor(element(by.id('sidebar-view'))).toBeVisible().withTimeout(2000); + await waitFor(element(by.label(label))).toBeVisible().withTimeout(60000); + await element(by.id('sidebar-close-drawer')).tap(); +} + +const checkBanner = async() => { + await waitFor(element(by.id('listheader-encryption').withDescendant(by.label('Save Your Encryption Password')))).toBeVisible().withTimeout(10000); +} + async function navigateToRoom(roomName) { await searchRoom(`${ roomName }`); await waitFor(element(by.id(`rooms-list-view-item-${ roomName }`))).toExist().withTimeout(60000); @@ -43,7 +55,7 @@ describe('E2E Encryption', () => { describe('Banner', async() => { describe('Render', async () => { it('should have encryption badge', async () => { - await waitFor(element(by.id('listheader-encryption').withDescendant(by.label('Save Your Encryption Password')))).toBeVisible().withTimeout(10000); + await checkBanner(); }); }); @@ -195,4 +207,54 @@ describe('E2E Encryption', () => { }) }); }); + + describe('Persist Banner', () => { + it('check save banner', async() => { + await checkServer(data.server); + await checkBanner(); + }) + + it('should add server and create new user', async() => { + await sleep(5000); + await element(by.id('rooms-list-header-server-dropdown-button')).tap(); + await waitFor(element(by.id('rooms-list-header-server-dropdown'))).toBeVisible().withTimeout(5000); + await element(by.id('rooms-list-header-server-add')).tap(); + + // TODO: refactor + await waitFor(element(by.id('new-server-view'))).toBeVisible().withTimeout(60000); + await element(by.id('new-server-view-input')).replaceText(data.alternateServer); + await element(by.id('new-server-view-button')).tap(); + await waitFor(element(by.id('workspace-view'))).toBeVisible().withTimeout(60000); + await element(by.id('workspace-view-register')).tap(); + await waitFor(element(by.id('register-view'))).toBeVisible().withTimeout(2000); + + // Register new user + await element(by.id('register-view-name')).replaceText(data.registeringUser.username); + await element(by.id('register-view-username')).replaceText(data.registeringUser.username); + await element(by.id('register-view-email')).replaceText(data.registeringUser.email); + await element(by.id('register-view-password')).replaceText(data.registeringUser.password); + await element(by.id('register-view-submit')).tap(); + await waitFor(element(by.id('rooms-list-view'))).toBeVisible().withTimeout(60000); + + await checkServer(data.alternateServer); + }); + + it('should change back', async() => { + await element(by.id('rooms-list-header-server-dropdown-button')).tap(); + await waitFor(element(by.id('rooms-list-header-server-dropdown'))).toBeVisible().withTimeout(5000); + await element(by.id(`rooms-list-header-server-${ data.server }`)).tap(); + await waitFor(element(by.id('rooms-list-view'))).toBeVisible().withTimeout(10000); + await checkServer(data.server); + await checkBanner(); + }); + + it('should reopen the app and have banner', async() => { + await device.launchApp({ + permissions: { notifications: 'YES' }, + newInstance: true + }); + await waitFor(element(by.id('rooms-list-view'))).toBeVisible().withTimeout(10000); + await checkBanner(); + }); + }); }); \ No newline at end of file diff --git a/e2e/tests/assorted/07-changeserver.spec.js b/e2e/tests/assorted/07-changeserver.spec.js index 63506f89..a795e66c 100644 --- a/e2e/tests/assorted/07-changeserver.spec.js +++ b/e2e/tests/assorted/07-changeserver.spec.js @@ -39,10 +39,10 @@ describe('Change server', () => { await waitFor(element(by.id('register-view'))).toBeVisible().withTimeout(2000); // Register new user - await element(by.id('register-view-name')).replaceText(data.registeringUser.username); - await element(by.id('register-view-username')).replaceText(data.registeringUser.username); - await element(by.id('register-view-email')).replaceText(data.registeringUser.email); - await element(by.id('register-view-password')).replaceText(data.registeringUser.password); + await element(by.id('register-view-name')).replaceText(data.registeringUser2.username); + await element(by.id('register-view-username')).replaceText(data.registeringUser2.username); + await element(by.id('register-view-email')).replaceText(data.registeringUser2.email); + await element(by.id('register-view-password')).replaceText(data.registeringUser2.password); await element(by.id('register-view-submit')).tap(); await waitFor(element(by.id('rooms-list-view'))).toBeVisible().withTimeout(60000); diff --git a/e2e/tests/assorted/10-deleteserver.spec.js b/e2e/tests/assorted/10-deleteserver.spec.js index 474ebd26..bf737910 100644 --- a/e2e/tests/assorted/10-deleteserver.spec.js +++ b/e2e/tests/assorted/10-deleteserver.spec.js @@ -29,10 +29,10 @@ describe('Delete server', () => { await waitFor(element(by.id('register-view'))).toBeVisible().withTimeout(2000); // Register new user - await element(by.id('register-view-name')).replaceText(data.registeringUser.username); - await element(by.id('register-view-username')).replaceText(data.registeringUser.username); - await element(by.id('register-view-email')).replaceText(data.registeringUser.email); - await element(by.id('register-view-password')).replaceText(data.registeringUser.password); + await element(by.id('register-view-name')).replaceText(data.registeringUser3.username); + await element(by.id('register-view-username')).replaceText(data.registeringUser3.username); + await element(by.id('register-view-email')).replaceText(data.registeringUser3.email); + await element(by.id('register-view-password')).replaceText(data.registeringUser3.password); await element(by.id('register-view-submit')).tap(); await waitFor(element(by.id('rooms-list-view'))).toBeVisible().withTimeout(60000);