From 41a094ba4caf407031d3f3e17df7116ee7df52c5 Mon Sep 17 00:00:00 2001 From: Andrea Marchesini Date: Wed, 25 Jan 2023 08:23:01 -0400 Subject: [PATCH] Run all the functional tests in wasm (#5765) --- .github/workflows/wasm.yaml | 2 +- src/apps/vpn/inspector/inspectorhandler.cpp | 27 ---- tests/functional/helper.js | 32 ----- tests/functional/testAuthenticationInApp.js | 2 + tests/functional/testPushMessageHandlers.js | 131 +++++++++----------- tests/functional/wasm-test-ignore | 4 - 6 files changed, 65 insertions(+), 133 deletions(-) delete mode 100644 tests/functional/wasm-test-ignore diff --git a/.github/workflows/wasm.yaml b/.github/workflows/wasm.yaml index 6b61f12411..bf50938656 100644 --- a/.github/workflows/wasm.yaml +++ b/.github/workflows/wasm.yaml @@ -65,7 +65,7 @@ jobs: run: | echo -n "tests=" >> $GITHUB_OUTPUT for test in $(find tests/functional -name 'test*.js' | sort); do - grep "$(basename ${test%.js})" tests/functional/wasm-test-ignore &>/dev/null || printf '{"name": "%s", "path": "%s"}' $(basename ${test%.js} | sed -n 's/test//p') $test + printf '{"name": "%s", "path": "%s"}' $(basename ${test%.js} | sed -n 's/test//p') $test done | jq -s -c >> $GITHUB_OUTPUT - name: Check tests diff --git a/src/apps/vpn/inspector/inspectorhandler.cpp b/src/apps/vpn/inspector/inspectorhandler.cpp index 86f770f4eb..24b1894251 100644 --- a/src/apps/vpn/inspector/inspectorhandler.cpp +++ b/src/apps/vpn/inspector/inspectorhandler.cpp @@ -681,33 +681,6 @@ static QList s_commands{ return obj; }}, - InspectorCommand{ - "reset_devices", - "Remove all the existing devices and add the current one if needed", 0, - [](InspectorHandler*, const QList&) { - MozillaVPN* vpn = MozillaVPN::instance(); - Q_ASSERT(vpn); - - DeviceModel* dm = vpn->deviceModel(); - Q_ASSERT(dm); - - bool hasCurrentOne = false; - for (const Device& device : dm->devices()) { - if (device.isCurrentDevice(vpn->keys())) { - hasCurrentOne = true; - continue; - } - - vpn->removeDeviceFromPublicKey(device.publicKey()); - } - - if (!hasCurrentOne) { - vpn->addCurrentDeviceAndRefreshData(false); - } - - return QJsonObject(); - }}, - InspectorCommand{"public_key", "Retrieve the public key of the current device", 0, [](InspectorHandler*, const QList&) { diff --git a/tests/functional/helper.js b/tests/functional/helper.js index f3c78f04dc..f4aeb00270 100644 --- a/tests/functional/helper.js +++ b/tests/functional/helper.js @@ -340,10 +340,6 @@ module.exports = { await this.waitForVPNProperty('VPN', 'userState', 'UserAuthenticated'); await this.waitForQuery(queries.screenPostAuthentication.BUTTON.visible()); - // Clean-up extra devices (otherwise test account will fill up in a - // heartbeats) - await this._maybeRemoveExistingDevices(); - if (clickOnPostAuthenticate) { await this.waitForQuery(queries.global.SCREEN_LOADER.ready()); await this.clickOnQuery( @@ -392,10 +388,6 @@ module.exports = { await this.waitForVPNProperty('VPN', 'userState', 'UserAuthenticated'); await this.waitForQuery(queries.screenPostAuthentication.BUTTON.visible()); - // Clean-up extra devices (otherwise test account will fill up in a - // heartbeats) - await this._maybeRemoveExistingDevices(); - if (clickOnPostAuthenticate) { await this.clickOnQuery( queries.screenPostAuthentication.BUTTON.visible()); @@ -590,28 +582,4 @@ module.exports = { wr(json); } }, - - async _maybeRemoveExistingDevices() { - const json = await this._writeCommand('devices'); - assert( - json.type === 'devices' && !('error' in json), - `Command failed: ${json.error}`); - - if (json.value.find(device => device.currentDevice)) { - return; - } - - const addJson = await this._writeCommand('reset_devices'); - assert( - addJson.type === 'reset_devices' && !('error' in addJson), - `Command failed: ${addJson.error}`); - - await this.waitForCondition(async () => { - const json = await this._writeCommand('devices'); - assert( - json.type === 'devices' && !('error' in json), - `Command failed: ${json.error}`); - return json.value.find(device => device.currentDevice); - }); - }, }; diff --git a/tests/functional/testAuthenticationInApp.js b/tests/functional/testAuthenticationInApp.js index be31a11791..5b3fce3886 100644 --- a/tests/functional/testAuthenticationInApp.js +++ b/tests/functional/testAuthenticationInApp.js @@ -905,6 +905,8 @@ describe('User authentication', function() { // Step 6: email code -> back -> start -> totp -> error code await vpn.waitForQueryAndClick(queries.screenAuthenticationInApp .AUTH_EMAILVER_BACK_BUTTON.visible()); + await vpn.waitForQuery( + queries.screenAuthenticationInApp.AUTH_START_TEXT_INPUT.visible()); await vpn.setQueryProperty( queries.screenAuthenticationInApp.AUTH_START_TEXT_INPUT.visible(), 'text', 'test@test.com'); diff --git a/tests/functional/testPushMessageHandlers.js b/tests/functional/testPushMessageHandlers.js index 9ffc692339..54675c8bf0 100644 --- a/tests/functional/testPushMessageHandlers.js +++ b/tests/functional/testPushMessageHandlers.js @@ -10,80 +10,71 @@ const queries = require('./queries.js'); describe('PushMessage.handlers', function() { describe('DEVICE_DELETED', function() { const messageType = 'DEVICE_DELETED'; - this.ctx.authenticationNeeded = true; - - this.beforeEach(async () => { - // Override the guardian endpoints to return more than one device. - const UserData = { - avatar: '', - display_name: 'Test', - email: 'test@mozilla.com', - max_devices: 5, - subscriptions: {vpn: {active: true}}, - devices: [ - { - name: 'currentDevice', - unique_id: 'currentDevice', - pubkey: await vpn.getPublicKey(), - ipv4_address: '127.0.0.1', - ipv6_address: '::1', - created_at: new Date().toISOString() - }, - { - name: 'device_2', - unique_id: 'device_2', - pubkey: 'publicKey_2', - ipv4_address: '127.0.0.1', - ipv6_address: '::1', - created_at: new Date().toISOString() - }, - { - name: 'device_3', - unique_id: 'device_3', - pubkey: 'publicKey_3', - ipv4_address: '127.0.0.1', - ipv6_address: '::1', - created_at: new Date().toISOString() - }, - { - name: 'device_4', - unique_id: 'device_4', - pubkey: 'publicKey_4', - ipv4_address: '127.0.0.1', - ipv6_address: '::1', - created_at: new Date().toISOString() + + const UserData = { + avatar: '', + display_name: 'Test', + email: 'test@mozilla.com', + max_devices: 5, + subscriptions: {vpn: {active: true}}, + devices: [ + { + name: 'device_1', + unique_id: 'device_1', + pubkey: 'a', + ipv4_address: '127.0.0.1', + ipv6_address: '::1', + created_at: new Date().toISOString() + }, + { + name: 'device_2', + unique_id: 'device_2', + pubkey: 'b', + ipv4_address: '127.0.0.1', + ipv6_address: '::1', + created_at: new Date().toISOString() + }, + { + name: 'device_3', + unique_id: 'device_3', + pubkey: 'c', + ipv4_address: '127.0.0.1', + ipv6_address: '::1', + created_at: new Date().toISOString() + }, + { + name: 'device_4', + unique_id: 'device_4', + pubkey: 'd', + ipv4_address: '127.0.0.1', + ipv6_address: '::1', + created_at: new Date().toISOString() + }, + ], + }; + + this.ctx.guardianOverrideEndpoints = { + GETs: { + '/api/v1/vpn/account': + {status: 200, requiredHeaders: ['Authorization'], body: UserData}, + }, + POSTs: { + '/api/v1/vpn/device': { + status: 201, + requiredHeaders: ['Authorization'], + callback: (req) => { + UserData.devices[0].name = req.body.name; + UserData.devices[0].pubkey = req.body.pubkey; + UserData.devices[0].unique_id = req.body.unique_id; }, - { - name: 'device_5', - unique_id: 'device_5', - pubkey: 'publicKey_5', - ipv4_address: '127.0.0.1', - ipv6_address: '::1', - created_at: new Date().toISOString() - } - ], - }; - - this.ctx.guardianOverrideEndpoints = { - GETs: { - '/api/v1/vpn/account': - {status: 200, requiredHeaders: ['Authorization'], body: UserData}, + body: {} }, - }; - }); - - it('no-op', () => { - // We need this test case here for due to the following situation: - // - // We need the guardian overrides to be inside a `beforeEach` block, - // otherwise we cannot use `await` to wait for the publicKey function to complete. - // - // That means it runs _after_ the VPN is initialized for the first time - // which means the overrides are only effective after a test case has already run. - }) + } + }; it('attempting to delete the current device leads to a logout', async () => { + await vpn.authenticateInApp(true, true); await vpn.waitForQuery(queries.screenHome.CONTROLLER_TITLE.visible()); const devices = await vpn.getDevices(); @@ -100,6 +91,7 @@ describe('PushMessage.handlers', function() { it('attempting to delete a third device updates the device list', async () => { + await vpn.authenticateInApp(true, true); await vpn.waitForQuery(queries.screenHome.CONTROLLER_TITLE.visible()); let devices = await vpn.getDevices(); @@ -129,6 +121,7 @@ describe('PushMessage.handlers', function() { }); it('invalid device deletion messages are ignored', async () => { + await vpn.authenticateInApp(true, true); await vpn.waitForQuery(queries.screenHome.CONTROLLER_TITLE.visible()); const devices = await vpn.getDevices(); diff --git a/tests/functional/wasm-test-ignore b/tests/functional/wasm-test-ignore deleted file mode 100644 index 7bd80add22..0000000000 --- a/tests/functional/wasm-test-ignore +++ /dev/null @@ -1,4 +0,0 @@ -testAuthenticationInApp.js -testCaptivePortal.js -testSubscription.js -testPushMessageHandlers.js