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-8122] - Disable access to internet for Linodes created during Cypress tests #10633

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-10633-tests-1719934397905.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Tests
---

Improve security of Linodes created during tests ([#10633](https://github.com/linode/manager/pull/10633))
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ const getLinodeCloneUrl = (linode: Linode): string => {
return `/linodes/create?linodeID=${linode.id}${regionQuery}&type=Clone+Linode${typeQuery}`;
};

/* Timeout after 3 minutes while waiting for clone. */
const CLONE_TIMEOUT = 180_000;
/* Timeout after 4 minutes while waiting for clone. */
const CLONE_TIMEOUT = 240_000;

authenticate();
describe('clone linode', () => {
Expand All @@ -47,7 +47,7 @@ describe('clone linode', () => {
* - Confirms that Linode can be cloned successfully.
*/
it('can clone a Linode from Linode details page', () => {
const linodeRegion = chooseRegion();
const linodeRegion = chooseRegion({ capabilities: ['Vlans'] });
const linodePayload = createLinodeRequestFactory.build({
label: randomLabel(),
region: linodeRegion.id,
Expand All @@ -64,8 +64,6 @@ describe('clone linode', () => {
cy.defer(() =>
createTestLinode(linodePayload, { securityMethod: 'vlan_no_internet' })
).then((linode: Linode) => {
const linodeRegion = getRegionById(linodePayload.region!);

interceptCloneLinode(linode.id).as('cloneLinode');
cy.visitWithLogin(`/linodes/${linode.id}`);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('Create Linode', () => {
*/
it(`creates a ${planConfig.planType} Linode`, () => {
const linodeRegion = chooseRegion({
capabilities: ['Linodes', 'Premium Plans'],
capabilities: ['Linodes', 'Premium Plans', 'Vlans'],
});
const linodeLabel = randomLabel();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
getVisible,
} from 'support/helpers';
import { ui } from 'support/ui';
import { apiMatcher } from 'support/util/intercepts';
import { randomString, randomLabel, randomNumber } from 'support/util/random';
import { chooseRegion } from 'support/util/regions';
import { getRegionById } from 'support/util/regions';
Expand All @@ -39,6 +38,7 @@ import {
import { mockGetVLANs } from 'support/intercepts/vlans';
import { mockGetLinodeConfigs } from 'support/intercepts/configs';
import {
interceptCreateLinode,
mockCreateLinode,
mockGetLinodeType,
mockGetLinodeTypes,
Expand Down Expand Up @@ -155,10 +155,14 @@ describe('create linode', () => {
// intercept request
cy.visitWithLogin('/linodes/create');
cy.get('[data-qa-deploy-linode]');
cy.intercept('POST', apiMatcher('linode/instances')).as('linodeCreated');
interceptCreateLinode().as('linodeCreated');
cy.get('[data-qa-header="Create"]').should('have.text', 'Create');
ui.regionSelect.find().click();
ui.regionSelect.findItemByRegionLabel(chooseRegion().label).click();
ui.regionSelect
.findItemByRegionLabel(
chooseRegion({ capabilities: ['Vlans', 'Linodes'] }).label
)
.click();
fbtClick('Shared CPU');
getClick('[id="g6-nanode-1"]');
getClick('#linode-label').clear().type(linodeLabel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ describe('OneClick Apps (OCA)', () => {
const password = randomString(16);
const image = 'linode/ubuntu22.04';
const rootPassword = randomString(16);
const region = chooseRegion();
const region = chooseRegion({ capabilities: ['Vlans'] });
const linodeLabel = randomLabel();
const levelName = 'Get the enderman!';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ describe('Create stackscripts', () => {
const stackscriptImageTag = 'alpine3.19';

const linodeLabel = randomLabel();
const linodeRegion = chooseRegion();
const linodeRegion = chooseRegion({ capabilities: ['Vlans'] });

interceptCreateStackScript().as('createStackScript');
interceptGetStackScripts().as('getStackScripts');
Expand Down Expand Up @@ -372,7 +372,10 @@ describe('Create stackscripts', () => {
.click();

interceptCreateLinode().as('createLinode');
fillOutLinodeForm(linodeLabel, chooseRegion().label);
fillOutLinodeForm(
linodeLabel,
chooseRegion({ capabilities: ['Vlans'] }).label
);
ui.button
.findByTitle('Create Linode')
.should('be.visible')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ describe('Community Stackscripts integration tests', () => {
const fairPassword = 'Akamai123';
const rootPassword = randomString(16);
const image = 'AlmaLinux 9';
const region = chooseRegion();
const region = chooseRegion({ capabilities: ['Vlans'] });
const linodeLabel = randomLabel();

interceptGetStackScripts().as('getStackScripts');
Expand Down
11 changes: 10 additions & 1 deletion packages/manager/cypress/support/intercepts/linodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,25 @@ import { makeErrorResponse } from 'support/util/errors';
import { apiMatcher } from 'support/util/intercepts';
import { paginateResponse } from 'support/util/paginate';
import { makeResponse } from 'support/util/response';
import { linodeVlanNoInternetConfig } from 'support/util/linodes';

import type { Disk, Kernel, Linode, LinodeType, Volume } from '@linode/api-v4';

/**
* Intercepts POST request to create a Linode.
*
* The outgoing request payload is modified to create a Linode without access
* to the internet.
*
* @returns Cypress chainable.
*/
export const interceptCreateLinode = (): Cypress.Chainable<null> => {
return cy.intercept('POST', apiMatcher('linode/instances'));
return cy.intercept('POST', apiMatcher('linode/instances'), (req) => {
req.body = {
...req.body,
interfaces: linodeVlanNoInternetConfig,
};
});
};

/**
Expand Down
28 changes: 19 additions & 9 deletions packages/manager/cypress/support/util/linodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,26 @@ import { chooseRegion } from 'support/util/regions';
import { depaginate } from './paginate';
import { pageSize } from 'support/constants/api';

import type { Config, CreateLinodeRequest, Linode } from '@linode/api-v4';
import type {
Config,
CreateLinodeRequest,
InterfacePayload,
Linode,
} from '@linode/api-v4';
import { findOrCreateDependencyFirewall } from 'support/api/firewalls';

/**
* Linode create interface to configure a Linode with no public internet access.
*/
export const linodeVlanNoInternetConfig: InterfacePayload[] = [
{
purpose: 'vlan',
primary: false,
label: randomLabel(),
ipam_address: null,
},
];

/**
* Methods used to secure test Linodes.
*
Expand Down Expand Up @@ -77,14 +94,7 @@ export const createTestLinode = async (

case 'vlan_no_internet':
return {
interfaces: [
{
purpose: 'vlan',
primary: false,
label: randomLabel(),
ipam_address: null,
},
],
interfaces: linodeVlanNoInternetConfig,
};

case 'powered_off':
Expand Down
Loading