Skip to content

Commit

Permalink
Make device protection e2e tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
monkbroc committed Jun 21, 2024
1 parent 9d82f98 commit b6e34e7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
"test:e2e:ci": "npm run test:e2e:no-device -- --forbid-only",
"test:e2e:no-device": "npm run test:e2e -- --grep @device --invert",
"test:e2e:wifi": "npm run test:e2e -- --grep @device,@wifi",
"test:e2e:device-protection": "npm run test:e2e -- --grep @device,@device-protection",
"test:e2e:watch": "npm run test:e2e -- --watch --watch-extensions js,json",
"test:e2e:inspect": "npm test:e2e -- --inspect-brk",
"test:e2e:silent": "PARTICLE_NOOP=$(npm run test:e2e:ci)",
Expand Down
4 changes: 4 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ The e2e tests run in two modes: with a device connected, and without. Since the

1. run `npm run test:e2e:no-device`

### Running device protection tests

1. Ensure the device `E2E_PRODUCT_01_DEVICE_01_ID` in product `E2E_PRODUCT_01_ID` is an Open Device in a product with device protection active at the start of the tests.
2. run `npm run test:e2e:device-protection`

## Adding Tests

Expand Down
44 changes: 27 additions & 17 deletions test/e2e/device-protection.e2e.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const { expect } = require('../setup');
const cli = require('../lib/cli');
const {
DEVICE_ID,
PRODUCT_01_DEVICE_01_ID
PRODUCT_01_DEVICE_01_ID,
PRODUCT_01_ID
} = require('../lib/env');
const { delay } = require('../../src/lib/utilities');

const FLASH_TIME = 15000;

describe('Device Protection Commands [@device,@device-protection]', () => {
const help = [
Expand All @@ -26,10 +28,14 @@ describe('Device Protection Commands [@device,@device-protection]', () => {

before(async () => {
await cli.setTestProfileAndLogin();
// Ensure device starts as an Open Device
await cli.run(['device-protection', 'disable', '--open']);

// give time to flash the device
await delay(FLASH_TIME);
});

after(async () => {
await cli.run(['usb', 'setup-done']);
await cli.logout();
await cli.setDefaultProfile();
});
Expand Down Expand Up @@ -62,68 +68,72 @@ describe('Device Protection Commands [@device,@device-protection]', () => {
it('Gets the current device protection status', async () => {
const { stdout, stderr, exitCode } = await cli.run(['device-protection', 'status']);

expect(stdout).to.include(`[${DEVICE_ID}] (Product ${PRODUCT_01_DEVICE_01_ID}): Open device\nRun particle device-protection enable to protect the device.`);
expect(stdout).to.include(`[${PRODUCT_01_DEVICE_01_ID}] (Product ${PRODUCT_01_ID}): Open device\nRun particle device-protection enable to protect the device.`);
expect(stderr).to.equal('');
expect(exitCode).to.equal(0);
});

it('Attempts to disable protection status on an open device', async () => {
const { stdout, stderr, exitCode } = await cli.run(['device-protection', 'disable']);

expect(stdout).to.include(`[${DEVICE_ID}] (Product ${PRODUCT_01_DEVICE_01_ID}) is not a protected device.`);
expect(stdout).to.include(`[${PRODUCT_01_DEVICE_01_ID}] (Product ${PRODUCT_01_ID}) is not a protected device.`);
expect(stderr).to.equal('');
expect(exitCode).to.equal(0);
});

it('Enables protection status on the device', async () => {
const { stdout, stderr, exitCode } = await cli.run(['device-protection', 'status']);
const { stdout, stderr, exitCode } = await cli.run(['device-protection', 'enable']);

expect(stdout).to.include(`[${DEVICE_ID}] (Product ${PRODUCT_01_DEVICE_01_ID}) is now a protected device.\nDevice removed from development mode to maintain current settings.`);
expect(stdout).to.include(`[${PRODUCT_01_DEVICE_01_ID}] (Product ${PRODUCT_01_ID}) is now a protected device.\nDevice removed from development mode to maintain current settings.`);
expect(stderr).to.equal('');
expect(exitCode).to.equal(0);

// give time to flash the device
await delay(FLASH_TIME);
});

it('Gets the current status of the device', async () => {
const { stdout, stderr, exitCode } = await cli.run(['device-protection', 'disable', '--open']);
it('Gets the current status of a Protected Device', async () => {
const { stdout, stderr, exitCode } = await cli.run(['device-protection', 'status']);

expect(stdout).to.include(`[${DEVICE_ID}] (Product ${PRODUCT_01_DEVICE_01_ID}): Protected device\nRun particle device-protection disable to put the device in service mode.`);
expect(stdout).to.include(`[${PRODUCT_01_DEVICE_01_ID}] (Product ${PRODUCT_01_ID}): Protected device\nRun particle device-protection disable to put the device in service mode.`);
expect(stderr).to.equal('');
expect(exitCode).to.equal(0);
});

it('Attempts to enable protection status on a protected device', async () => {
const { stdout, stderr, exitCode } = await cli.run(['device-protection', 'enable']);

expect(stdout).to.include(`[${DEVICE_ID}] (Product ${PRODUCT_01_DEVICE_01_ID}) is already a protected device.`);
expect(stdout).to.include(`[${PRODUCT_01_DEVICE_01_ID}] (Product ${PRODUCT_01_ID}) is already a protected device.`);
expect(stderr).to.equal('');
expect(exitCode).to.equal(0);
});

it('Puts the device in service mode', async () => {
const { stdout, stderr, exitCode } = await cli.run(['device-protection', 'disable']);

expect(stdout).to.include(`[${DEVICE_ID}] (Product ${PRODUCT_01_DEVICE_01_ID}) is now in service mode.\nA protected device stays in service mode for a total of 20 reboots or 24 hours.`);
expect(stdout).to.include(`[${PRODUCT_01_DEVICE_01_ID}] (Product ${PRODUCT_01_ID}) is now in service mode.\nA protected device stays in service mode for a total of 20 reboots or 24 hours.`);
expect(stderr).to.equal('');
expect(exitCode).to.equal(0);
});

it('Turns the device to an open device', async () => {
const { stdout, stderr, exitCode } = await cli.run(['device-protection', 'disable', '--open']);

expect(stdout).to.include(`[${DEVICE_ID}] (Product ${PRODUCT_01_DEVICE_01_ID}) is now an open device.\nDevice placed in development mode to maintain current settings.`);
expect(stdout).to.include(`[${PRODUCT_01_DEVICE_01_ID}] (Product ${PRODUCT_01_ID}) is now an open device.\nDevice placed in development mode to maintain current settings.`);
expect(stderr).to.equal('');
expect(exitCode).to.equal(0);

// give time to flash the device
await delay(FLASH_TIME);
});

it('Gets the current status of the device', async () => {
const { stdout, stderr, exitCode } = await cli.run(['device-protection', 'disable', '--open']);
const { stdout, stderr, exitCode } = await cli.run(['device-protection', 'status']);

expect(stdout).to.include(`[${DEVICE_ID}] (Product ${PRODUCT_01_DEVICE_01_ID}): Open device\nRun particle device-protection enable to protect the device.`);
expect(stdout).to.include(`[${PRODUCT_01_DEVICE_01_ID}] (Product ${PRODUCT_01_ID}): Open device\nRun particle device-protection enable to protect the device.`);
expect(stderr).to.equal('');
expect(exitCode).to.equal(0);
});

});

});

0 comments on commit b6e34e7

Please sign in to comment.