Skip to content

Commit

Permalink
Run all the functional tests in wasm (#5765)
Browse files Browse the repository at this point in the history
  • Loading branch information
bakulf authored Jan 25, 2023
1 parent be6dd78 commit 41a094b
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 133 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/wasm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 0 additions & 27 deletions src/apps/vpn/inspector/inspectorhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,33 +681,6 @@ static QList<InspectorCommand> s_commands{
return obj;
}},

InspectorCommand{
"reset_devices",
"Remove all the existing devices and add the current one if needed", 0,
[](InspectorHandler*, const QList<QByteArray>&) {
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<QByteArray>&) {
Expand Down
32 changes: 0 additions & 32 deletions tests/functional/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
});
},
};
2 changes: 2 additions & 0 deletions tests/functional/testAuthenticationInApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', '[email protected]');
Expand Down
131 changes: 62 additions & 69 deletions tests/functional/testPushMessageHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '[email protected]',
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: '[email protected]',
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();
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 0 additions & 4 deletions tests/functional/wasm-test-ignore

This file was deleted.

0 comments on commit 41a094b

Please sign in to comment.