Skip to content
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

test: [M3-8108, M3-8113] - Improve security of Linodes created by tests #10538

Merged
Merged
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-10538-tests-1717187190983.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Tests
---

Improve test Linode security ([#10538](https://github.com/linode/manager/pull/10538))
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* @file Tests for service transfer functionality between accounts.
*/

import { createLinode } from '@linode/api-v4/lib/linodes';
import { getProfile } from '@linode/api-v4/lib/profile';
import { EntityTransfer, Linode, Profile } from '@linode/api-v4';
import { entityTransferFactory } from 'src/factories/entityTransfers';
Expand All @@ -19,6 +18,7 @@ import {
} from 'support/intercepts/account';
import { mockGetLinodes } from 'support/intercepts/linodes';
import { ui } from 'support/ui';
import { createTestLinode } from 'support/util/linodes';
import { pollLinodeStatus } from 'support/util/polling';
import { randomLabel, randomUuid } from 'support/util/random';
import { visitUrlWithManagedEnabled } from 'support/api/managed';
Expand Down Expand Up @@ -244,15 +244,18 @@ describe('Account service transfers', () => {
* - Confirms that users can cancel a service transfer
*/
it('can initiate and cancel a service transfer', () => {
// Create a Linode to transfer and wait for it to boot.
// Create a Linode to transfer.
const setupLinode = async (): Promise<Linode> => {
const payload = createLinodeRequestFactory.build({
label: randomLabel(),
region: chooseRegion().id,
});

const linode: Linode = await createLinode(payload);
await pollLinodeStatus(linode.id, 'running', {
const linode: Linode = await createTestLinode(payload, {
securityMethod: 'powered_off',
});

await pollLinodeStatus(linode.id, 'offline', {
initialDelay: 15000,
});

Expand Down Expand Up @@ -320,7 +323,7 @@ describe('Account service transfers', () => {
cy.get('[data-qa-close-drawer]').should('be.visible').click();
});

// Attempt to receive the an invalid token.
// Attempt to receive an invalid token.
redeemToken(randomUuid());
assertReceiptError('Not found');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { createLinode } from '@linode/api-v4/lib/linodes';
import { createTestLinode } from 'support/util/linodes';
import { createLinodeRequestFactory } from 'src/factories/linodes';
import { authenticate } from 'support/api/authentication';
import { containsClick, getClick } from 'support/helpers';
import { interceptCreateFirewall } from 'support/intercepts/firewalls';
import { randomString, randomLabel } from 'support/util/random';
import { ui } from 'support/ui';
Expand Down Expand Up @@ -33,10 +32,10 @@ describe('create firewall', () => {
.should('be.visible')
.within(() => {
// An error message appears when attempting to create a Firewall without a label
getClick('[data-testid="submit"]');
cy.get('[data-testid="submit"]').click();
cy.findByText('Label is required.');
// Fill out and submit firewall create form.
containsClick('Label').type(firewall.label);
cy.contains('Label').click().type(firewall.label);
ui.buttonGroup
.findButtonByTitle('Create Firewall')
.should('be.visible')
Expand Down Expand Up @@ -75,7 +74,10 @@ describe('create firewall', () => {
label: randomLabel(),
};

cy.defer(createLinode(linodeRequest), 'creating Linode').then((linode) => {
cy.defer(
createTestLinode(linodeRequest, { securityMethod: 'powered_off' }),
'creating Linode'
).then((linode) => {
interceptCreateFirewall().as('createFirewall');
cy.visitWithLogin('/firewalls/create');

Expand All @@ -84,7 +86,7 @@ describe('create firewall', () => {
.should('be.visible')
.within(() => {
// Fill out and submit firewall create form.
containsClick('Label').type(firewall.label);
cy.contains('Label').click().type(firewall.label);
cy.findByLabelText('Linodes')
.should('be.visible')
.click()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
regionFactory,
} from '@src/factories';
import { authenticate } from 'support/api/authentication';
import { createLinode } from '@linode/api-v4';
import {
interceptCreateFirewall,
interceptGetFirewalls,
Expand All @@ -23,6 +22,7 @@ import { cleanUp } from 'support/util/cleanup';
import { randomLabel, randomNumber } from 'support/util/random';
import type { Linode, Region } from '@linode/api-v4';
import { chooseRegions } from 'support/util/regions';
import { createTestLinode } from 'support/util/linodes';

const mockRegions: Region[] = [
regionFactory.build({
Expand Down Expand Up @@ -66,7 +66,7 @@ const migrationNoticeSubstrings = [
authenticate();
describe('Migrate Linode With Firewall', () => {
before(() => {
cleanUp('firewalls');
cleanUp(['firewalls', 'linodes']);
});

/*
Expand Down Expand Up @@ -144,7 +144,9 @@ describe('Migrate Linode With Firewall', () => {
interceptGetFirewalls().as('getFirewalls');

// Create a Linode, then navigate to the Firewalls landing page.
cy.defer(createLinode(linodePayload)).then((linode: Linode) => {
cy.defer(
createTestLinode(linodePayload, { securityMethod: 'powered_off' })
).then((linode: Linode) => {
interceptMigrateLinode(linode.id).as('migrateLinode');
cy.visitWithLogin('/firewalls');
cy.wait('@getFirewalls');
Expand Down Expand Up @@ -194,7 +196,7 @@ describe('Migrate Linode With Firewall', () => {

// Make sure Linode is running before attempting to migrate.
cy.get('[data-qa-linode-status]').within(() => {
cy.findByText('RUNNING');
cy.findByText('OFFLINE');
});

ui.actionMenu
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable sonarjs/no-duplicate-string */
import type { Linode } from '@linode/api-v4';
import { createLinode } from '@linode/api-v4';
import {
linodeFactory,
linodeBackupsFactory,
Expand All @@ -27,6 +26,7 @@ import { randomLabel } from 'support/util/random';
import { dcPricingMockLinodeTypesForBackups } from 'support/constants/dc-specific-pricing';
import { chooseRegion } from 'support/util/regions';
import { expectManagedDisabled } from 'support/api/managed';
import { createTestLinode } from 'support/util/linodes';

authenticate();
describe('linode backups', () => {
Expand All @@ -53,7 +53,7 @@ describe('linode backups', () => {
booted: false,
});

cy.defer(createLinode(createLinodeRequest), 'creating Linode').then(
cy.defer(createTestLinode(createLinodeRequest), 'creating Linode').then(
(linode: Linode) => {
interceptGetLinode(linode.id).as('getLinode');
interceptEnableLinodeBackups(linode.id).as('enableBackups');
Expand Down Expand Up @@ -116,7 +116,7 @@ describe('linode backups', () => {

const snapshotName = randomLabel();

cy.defer(createLinode(createLinodeRequest), 'creating Linode').then(
cy.defer(createTestLinode(createLinodeRequest), 'creating Linode').then(
(linode: Linode) => {
interceptGetLinode(linode.id).as('getLinode');
interceptCreateLinodeSnapshot(linode.id).as('createSnapshot');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Linode, createLinode } from '@linode/api-v4';
import { linodeFactory, createLinodeRequestFactory } from '@src/factories';
import {
interceptCloneLinode,
Expand All @@ -18,6 +17,8 @@ import { chooseRegion, getRegionById } from 'support/util/regions';
import { randomLabel } from 'support/util/random';
import { authenticate } from 'support/api/authentication';
import { cleanUp } from 'support/util/cleanup';
import { createTestLinode } from 'support/util/linodes';
import type { Linode } from '@linode/api-v4';

/**
* Returns the Cloud Manager URL to clone a given Linode.
Expand Down Expand Up @@ -49,12 +50,13 @@ describe('clone linode', () => {
region: linodeRegion.id,
// Specifying no image allows the Linode to provision and clone faster.
image: undefined,
booted: false,
type: 'g6-nanode-1',
});

const newLinodeLabel = `${linodePayload.label}-clone`;

cy.defer(createLinode(linodePayload)).then((linode: Linode) => {
cy.defer(createTestLinode(linodePayload)).then((linode: Linode) => {
const linodeRegion = getRegionById(linodePayload.region!);

interceptCloneLinode(linode.id).as('cloneLinode');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,10 @@ describe('Linode Config management', () => {
*/
it('Boots a config', () => {
cy.defer(
createLinodeAndGetConfig(null, { waitForBoot: true }),
createLinodeAndGetConfig(
{ booted: true },
{ waitForBoot: true, securityMethod: 'vlan_no_internet' }
),
'Creating and booting test Linode'
).then(([linode, config]: [Linode, Config]) => {
const kernel = findKernelById(kernels, config.kernel);
Expand Down Expand Up @@ -281,8 +284,8 @@ describe('Linode Config management', () => {
// Create clone source and destination Linodes.
const createCloneTestLinodes = async () => {
return Promise.all([
createTestLinode(null, { waitForBoot: true }),
createTestLinode(),
createTestLinode({ booted: true }, { waitForBoot: true }),
createTestLinode({ booted: true }),
]);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable sonarjs/no-duplicate-string */
import { Linode } from '@linode/api-v4';
import { authenticate } from 'support/api/authentication';
import { createLinode } from 'support/api/linodes';
import { createTestLinode } from 'support/util/linodes';
import { containsVisible, fbtClick, fbtVisible } from 'support/helpers';
import { ui } from 'support/ui';
import { cleanUp } from 'support/util/cleanup';
Expand Down Expand Up @@ -103,8 +103,8 @@ describe('linode storage tab', () => {
});

it('try to delete in use disk', () => {
const diskName = 'Debian 10 Disk';
createLinode().then((linode) => {
const diskName = 'Debian 11 Disk';
cy.defer(createTestLinode({ booted: true })).then((linode) => {
cy.intercept(
'DELETE',
apiMatcher(`linode/instances/${linode.id}/disks/*`)
Expand All @@ -127,7 +127,7 @@ describe('linode storage tab', () => {

it('delete disk', () => {
const diskName = 'cy-test-disk';
createLinode({ image: null }).then((linode: Linode) => {
cy.defer(createTestLinode({ image: null })).then((linode) => {
cy.intercept(
'DELETE',
apiMatcher(`linode/instances/${linode.id}/disks/*`)
Expand Down Expand Up @@ -157,7 +157,7 @@ describe('linode storage tab', () => {

it('add a disk', () => {
const diskName = 'cy-test-disk';
createLinode({ image: null }).then((linode: Linode) => {
cy.defer(createTestLinode({ image: null })).then((linode: Linode) => {
cy.intercept(
'POST',
apiMatcher(`/linode/instances/${linode.id}/disks`)
Expand All @@ -171,7 +171,7 @@ describe('linode storage tab', () => {

it('resize disk', () => {
const diskName = 'Debian 10 Disk';
createLinode({ image: null }).then((linode: Linode) => {
cy.defer(createTestLinode({ image: null })).then((linode: Linode) => {
cy.intercept(
'POST',
apiMatcher(`linode/instances/${linode.id}/disks`)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createLinode, CreateLinodeRequest, Linode } from '@linode/api-v4';
import { CreateLinodeRequest, Linode } from '@linode/api-v4';
import { ui } from 'support/ui';
import { randomString, randomLabel } from 'support/util/random';
import { authenticate } from 'support/api/authentication';
Expand All @@ -12,6 +12,7 @@ import {
mockGetLinodeDetails,
mockRebuildLinodeError,
} from 'support/intercepts/linodes';
import { createTestLinode } from 'support/util/linodes';

/**
* Creates a Linode and StackScript.
Expand All @@ -27,7 +28,7 @@ const createStackScriptAndLinode = async (
) => {
return Promise.all([
createStackScript(stackScriptRequestPayload),
createLinode(linodeRequestPayload),
createTestLinode(linodeRequestPayload),
]);
};

Expand Down Expand Up @@ -117,7 +118,7 @@ describe('rebuild linode', () => {
region: chooseRegion().id,
});

cy.defer(createLinode(linodeCreatePayload), 'creating Linode').then(
cy.defer(createTestLinode(linodeCreatePayload), 'creating Linode').then(
(linode: Linode) => {
interceptRebuildLinode(linode.id).as('linodeRebuild');

Expand Down Expand Up @@ -171,7 +172,7 @@ describe('rebuild linode', () => {
region: chooseRegion().id,
});

cy.defer(createLinode(linodeCreatePayload), 'creating Linode').then(
cy.defer(createTestLinode(linodeCreatePayload), 'creating Linode').then(
(linode: Linode) => {
interceptRebuildLinode(linode.id).as('linodeRebuild');
interceptGetStackScripts().as('getStackScripts');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Linode } from '@linode/api-v4';
import { createLinode } from '@linode/api-v4';
import { createLinodeRequestFactory, linodeFactory } from '@src/factories';
import { authenticate } from 'support/api/authentication';
import {
Expand All @@ -12,6 +11,7 @@ import {
} from 'support/intercepts/linodes';
import { ui } from 'support/ui';
import { cleanUp } from 'support/util/cleanup';
import { createTestLinode } from 'support/util/linodes';
import { randomLabel } from 'support/util/random';
import { chooseRegion } from 'support/util/regions';

Expand Down Expand Up @@ -43,7 +43,7 @@ describe('Rescue Linodes', () => {
region: chooseRegion().id,
});

cy.defer(createLinode(linodePayload), 'creating Linode').then(
cy.defer(createTestLinode(linodePayload), 'creating Linode').then(
(linode: Linode) => {
interceptGetLinodeDetails(linode.id).as('getLinode');
interceptRebootLinodeIntoRescueMode(linode.id).as(
Expand Down
Loading
Loading