Skip to content

Commit

Permalink
test: [M3-8776] - Fix lke-create tests and create unit tests for LKE …
Browse files Browse the repository at this point in the history
…ACL (#11176)

* fix lke-create tests, move copy checks to unit tests

* Added changeset: Add unit tests to declutter LKE ACL cypress tests, fix lke-create.spec.ts failures
  • Loading branch information
coliu-akamai authored Oct 28, 2024
1 parent 77111ab commit 1a9d479
Show file tree
Hide file tree
Showing 6 changed files with 241 additions and 112 deletions.
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-11176-tests-1730144406169.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Tests
---

Add unit tests to declutter LKE ACL cypress tests, fix lke-create.spec.ts failures ([#11176](https://github.com/linode/manager/pull/11176))
43 changes: 7 additions & 36 deletions packages/manager/cypress/e2e/core/kubernetes/lke-create.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,14 +411,6 @@ describe('LKE Cluster Creation with ACL', () => {
cy.wait(['@getAccount']);

cy.contains('Control Plane ACL').should('not.exist');
cy.contains(
'Enable an access control list (ACL) on your LKE cluster to restrict access to your cluster’s control plane. When enabled, only the IP addresses and ranges specified by you can connect to the control plane.'
).should('not.exist');
cy.contains('Enable Control Plane ACL').should('not.exist');
cy.contains('IPv4 Addresses or CIDRs').should('not.exist');
cy.contains('IPv6 Addresses or CIDRs').should('not.exist');
cy.contains('Add IPv4 Address').should('not.exist');
cy.contains('Add IPv6 Address').should('not.exist');
});

// setting up mocks
Expand Down Expand Up @@ -511,26 +503,13 @@ describe('LKE Cluster Creation with ACL', () => {
.should('be.visible')
.click();

// Confirm ACL section and disable ACL
// Disable ACL
cy.contains('Control Plane ACL').should('be.visible');
cy.contains(
'Enable an access control list (ACL) on your LKE cluster to restrict access to your cluster’s control plane. When enabled, only the IP addresses and ranges specified by you can connect to the control plane.'
).should('be.visible');
cy.contains('Enable Control Plane ACL').should('be.visible');
cy.contains('IPv4 Addresses or CIDRs').should('be.visible');
cy.contains('IPv6 Addresses or CIDRs').should('be.visible');
cy.contains('Add IPv4 Address').should('be.visible');
cy.contains('Add IPv6 Address').should('be.visible');
ui.toggle
.find()
.should('have.attr', 'data-qa-toggle', 'true')
.should('be.visible')
.click();
// IP related fields do not exist when ACL is not enabled
cy.get('IPv4 Addresses or CIDRs').should('not.exist');
cy.get('IPv6 Addresses or CIDRs').should('not.exist');
cy.get('Add IPv4 Address').should('not.exist');
cy.get('Add IPv6 Address').should('not.exist');

// Add a node pool
cy.log(`Adding ${nodeCount}x ${getLkePlanName(clusterPlan)} node(s)`);
Expand Down Expand Up @@ -637,20 +616,12 @@ describe('LKE Cluster Creation with ACL', () => {

// Confirm ACL section
cy.contains('Control Plane ACL').should('be.visible');
cy.contains(
'Enable an access control list (ACL) on your LKE cluster to restrict access to your cluster’s control plane. When enabled, only the IP addresses and ranges specified by you can connect to the control plane.'
).should('be.visible');
cy.contains('Enable Control Plane ACL').should('be.visible');
cy.contains('IPv4 Addresses or CIDRs').should('be.visible');
cy.contains('IPv6 Addresses or CIDRs').should('be.visible');
cy.contains('Add IPv4 Address').should('be.visible');
cy.contains('Add IPv6 Address').should('be.visible');
ui.toggle
.find()
.should('have.attr', 'data-qa-toggle', 'true')
.should('be.visible');
// Add some IPv4s and an IPv6
cy.findByPlaceholderText('0.0.0.0/0')
cy.findByLabelText('IPv4 Addresses or CIDRs ip-address-0')
.should('be.visible')
.click()
.type('10.0.0.0/24');
Expand All @@ -662,7 +633,7 @@ describe('LKE Cluster Creation with ACL', () => {
.should('be.visible')
.click()
.type('10.0.1.0/24');
cy.findByPlaceholderText('::/0')
cy.findByLabelText('IPv6 Addresses or CIDRs ip-address-0')
.should('be.visible')
.click()
.type('8e61:f9e9:8d40:6e0a:cbff:c97a:2692:827e');
Expand Down Expand Up @@ -763,15 +734,15 @@ describe('LKE Cluster Creation with ACL', () => {
.click();

// Confirm ACL IPv4 validation works as expected
cy.findByPlaceholderText('0.0.0.0/0')
cy.findByLabelText('IPv4 Addresses or CIDRs ip-address-0')
.should('be.visible')
.click()
.type('invalid ip');
// click out of textbox and confirm error is visible
cy.contains('Control Plane ACL').should('be.visible').click();
cy.contains('Must be a valid IPv4 address.').should('be.visible');
// enter valid IP
cy.findByPlaceholderText('0.0.0.0/0')
cy.findByLabelText('IPv4 Addresses or CIDRs ip-address-0')
.should('be.visible')
.click()
.clear()
Expand All @@ -781,15 +752,15 @@ describe('LKE Cluster Creation with ACL', () => {
cy.contains('Must be a valid IPv4 address.').should('not.exist');

// Confirm ACL IPv6 validation works as expected
cy.findByPlaceholderText('::/0')
cy.findByLabelText('IPv6 Addresses or CIDRs ip-address-0')
.should('be.visible')
.click()
.type('invalid ip');
// click out of textbox and confirm error is visible
cy.contains('Control Plane ACL').should('be.visible').click();
cy.contains('Must be a valid IPv6 address.').should('be.visible');
// enter valid IP
cy.findByPlaceholderText('::/0')
cy.findByLabelText('IPv6 Addresses or CIDRs ip-address-0')
.should('be.visible')
.click()
.clear()
Expand Down
83 changes: 10 additions & 73 deletions packages/manager/cypress/e2e/core/kubernetes/lke-update.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1436,16 +1436,8 @@ describe('LKE ACL updates', () => {
.should('be.visible')
.should('not.be.enabled');

cy.contains(
"Control Plane ACL secures network access to your LKE cluster's control plane. Use this form to enable or disable the ACL on your LKE cluster, update the list of allowed IP addresses, and adjust other settings."
).should('be.visible');

// confirm Activation Status section and toggle on 'Enable'
// Enable ACL
cy.contains('Activation Status').should('be.visible');
cy.contains(
'Enable or disable the Control Plane ACL. If the ACL is not enabled, any public IP address can be used to access your control plane. Once enabled, all network access is denied except for the IP addresses and CIDR ranges defined on the ACL.'
).should('be.visible');
cy.findByText('Enable Control Plane ACL');
ui.toggle
.find()
.should('have.attr', 'data-qa-toggle', 'false')
Expand All @@ -1458,39 +1450,19 @@ describe('LKE ACL updates', () => {
.should('be.visible')
.should('be.enabled');

// confirm Revision ID section and edit Revision ID
cy.findAllByText('Revision ID').should('have.length', 2);
cy.contains(
'A unique identifying string for this particular revision to the ACL, used by clients to track events related to ACL update requests and enforcement. This defaults to a randomly generated string but can be edited if you prefer to specify your own string to use for tracking this change.'
).should('be.visible');
// Edit Revision ID
cy.findByLabelText('Revision ID').should(
'have.value',
mockACLOptions['revision-id']
);
cy.findByLabelText('Revision ID').clear().type(mockRevisionId);

// confirm Addresses section
cy.findByText('Addresses').should('be.visible');
cy.findByText(
"A list of allowed IPv4 and IPv6 addresses and CIDR ranges. This cluster's control plane will only be accessible from IP addresses within this list."
).should('be.visible');
cy.findByText('IPv4 Addresses or CIDRs').should('be.visible');
cy.findByText('Add IPv4 Address')
.should('be.visible')
.should('be.enabled');
// confirm current IPv4 value and enter new IP
// Addresses section: confirm current IPv4 value and enter new IP
cy.findByDisplayValue('10.0.3.0/24')
.should('be.visible')
.click()
.clear()
.type('10.0.0.0/24');
cy.findByText('IPv6 Addresses or CIDRs').should('be.visible');
cy.findByLabelText('IPv6 Addresses or CIDRs ip-address-0').should(
'be.visible'
);
cy.findByText('Add IPv6 Address')
.should('be.visible')
.should('be.enabled');

// submit
ui.button
Expand Down Expand Up @@ -1662,16 +1634,8 @@ describe('LKE ACL updates', () => {
.should('be.visible')
.should('not.be.enabled');

cy.contains(
"Control Plane ACL secures network access to your LKE cluster's control plane. Use this form to enable or disable the ACL on your LKE cluster, update the list of allowed IP addresses, and adjust other settings."
).should('be.visible');

// confirm Activation Status section and toggle off 'Enable'
// Activation Status section: toggle off 'Enable'
cy.contains('Activation Status').should('be.visible');
cy.contains(
'Enable or disable the Control Plane ACL. If the ACL is not enabled, any public IP address can be used to access your control plane. Once enabled, all network access is denied except for the IP addresses and CIDR ranges defined on the ACL.'
).should('be.visible');
cy.findByText('Enable Control Plane ACL');
ui.toggle
.find()
.should('have.attr', 'data-qa-toggle', 'true')
Expand All @@ -1684,23 +1648,13 @@ describe('LKE ACL updates', () => {
.should('be.visible')
.should('be.enabled');

// confirm Revision ID section exists
cy.findAllByText('Revision ID').should('have.length', 2);
cy.contains(
'A unique identifying string for this particular revision to the ACL, used by clients to track events related to ACL update requests and enforcement. This defaults to a randomly generated string but can be edited if you prefer to specify your own string to use for tracking this change.'
).should('be.visible');
// confirm Revision ID section
cy.findByLabelText('Revision ID').should(
'have.value',
mockACLOptions['revision-id']
);

// confirm Addresses section
cy.findByText('Addresses').should('be.visible');
cy.findByText(
"A list of allowed IPv4 and IPv6 addresses and CIDR ranges. This cluster's control plane will only be accessible from IP addresses within this list."
).should('be.visible');
cy.findByText('IPv4 Addresses or CIDRs').should('be.visible');
// update IPv4
// Addresses Section: update IPv4
cy.findByLabelText('IPv4 Addresses or CIDRs ip-address-0')
.should('be.visible')
.click()
Expand All @@ -1709,7 +1663,6 @@ describe('LKE ACL updates', () => {
.should('be.visible')
.should('be.enabled')
.click();
cy.findByText('IPv6 Addresses or CIDRs').should('be.visible');
// update IPv6
cy.findByLabelText('IPv6 Addresses or CIDRs ip-address-0')
.should('be.visible')
Expand Down Expand Up @@ -1808,35 +1761,24 @@ describe('LKE ACL updates', () => {
.findByTitle('Control Plane ACL')
.should('be.visible')
.within(() => {
// Confirm installation notice is displayed
cy.contains(
"Control Plane ACL secures network access to your LKE cluster's control plane. Use this form to enable or disable the ACL on your LKE cluster, update the list of allowed IP addresses, and adjust other settings."
'Control Plane ACL has not yet been installed on this cluster. During installation, it may take up to 15 minutes for the access control list to be fully enforced.'
).should('be.visible');

// Confirm Activation Status section and Enable ACL
cy.contains('Activation Status').should('be.visible');
cy.contains(
'Enable or disable the Control Plane ACL. If the ACL is not enabled, any public IP address can be used to access your control plane. Once enabled, all network access is denied except for the IP addresses and CIDR ranges defined on the ACL.'
).should('be.visible');
ui.toggle
.find()
.should('have.attr', 'data-qa-toggle', 'false')
.should('be.visible')
.click();

// Confirm revision ID section does not exist
// Revision ID section does not exist
cy.contains('Revision ID').should('not.exist');
cy.contains(
'A unique identifying string for this particular revision to the ACL, used by clients to track events related to ACL update requests and enforcement. This defaults to a randomly generated string but can be edited if you prefer to specify your own string to use for tracking this change.'
).should('not.exist');

// Confirm Addresses section and add IP addresses
// Addresses section: add IP addresses
cy.findByText('Addresses').should('be.visible');
cy.findByText(
"A list of allowed IPv4 and IPv6 addresses and CIDR ranges. This cluster's control plane will only be accessible from IP addresses within this list."
).should('be.visible');
cy.findByText('IPv4 Addresses or CIDRs').should('be.visible');
cy.findByText('IPv6 Addresses or CIDRs').should('be.visible');

cy.findByLabelText('IPv4 Addresses or CIDRs ip-address-0')
.should('be.visible')
.click()
Expand All @@ -1847,11 +1789,6 @@ describe('LKE ACL updates', () => {
.click()
.type('8e61:f9e9:8d40:6e0a:cbff:c97a:2692:827e');

// Confirm installation notice is displayed
cy.contains(
'Control Plane ACL has not yet been installed on this cluster. During installation, it may take up to 15 minutes for the access control list to be fully enforced.'
).should('be.visible');

// submit
ui.button
.findByTitle('Update')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import userEvent from '@testing-library/user-event';
import * as React from 'react';

import { renderWithTheme } from 'src/utilities/testHelpers';

import { ControlPlaneACLPane } from './ControlPlaneACLPane';

import type { ControlPlaneACLProps } from './ControlPlaneACLPane';

const props: ControlPlaneACLProps = {
enableControlPlaneACL: true,
errorText: undefined,
handleIPv4Change: vi.fn(),
handleIPv6Change: vi.fn(),
ipV4Addr: [{ address: '' }],
ipV6Addr: [{ address: '' }],
setControlPlaneACL: vi.fn(),
};

describe('ControlPlaneACLPane', () => {
it('renders all fields when enableControlPlaneACL is true', () => {
const { getByText } = renderWithTheme(<ControlPlaneACLPane {...props} />);

expect(getByText('Control Plane ACL')).toBeVisible();
expect(
getByText(
'Enable an access control list (ACL) on your LKE cluster to restrict access to your cluster’s control plane. When enabled, only the IP addresses and ranges you specify can connect to the control plane.'
)
).toBeVisible();
expect(getByText('Enable Control Plane ACL')).toBeVisible();
expect(getByText('IPv4 Addresses or CIDRs')).toBeVisible();
expect(getByText('Add IPv4 Address')).toBeVisible();
expect(getByText('IPv6 Addresses or CIDRs')).toBeVisible();
expect(getByText('Add IPv6 Address')).toBeVisible();
});

it('hides IP fields when enableControlPlaneACL is false', () => {
const { getByText, queryByText } = renderWithTheme(
<ControlPlaneACLPane {...props} enableControlPlaneACL={false} />
);

expect(getByText('Control Plane ACL')).toBeVisible();
expect(
getByText(
'Enable an access control list (ACL) on your LKE cluster to restrict access to your cluster’s control plane. When enabled, only the IP addresses and ranges you specify can connect to the control plane.'
)
).toBeVisible();
expect(getByText('Enable Control Plane ACL')).toBeVisible();
expect(queryByText('IPv4 Addresses or CIDRs')).not.toBeInTheDocument();
expect(queryByText('Add IPv4 Address')).not.toBeInTheDocument();
expect(queryByText('IPv6 Addresses or CIDRs')).not.toBeInTheDocument();
expect(queryByText('Add IPv6 Address')).not.toBeInTheDocument();
});

it('calls setControlPlaneACL when clicking the toggle', async () => {
const { getByText } = renderWithTheme(<ControlPlaneACLPane {...props} />);

const toggle = getByText('Enable Control Plane ACL');
await userEvent.click(toggle);

expect(props.setControlPlaneACL).toHaveBeenCalled();
});

it('handles IP changes', async () => {
const { getByLabelText } = renderWithTheme(
<ControlPlaneACLPane {...props} />
);

const ipv4 = getByLabelText('IPv4 Addresses or CIDRs ip-address-0');
await userEvent.type(ipv4, 'test');

expect(props.handleIPv4Change).toHaveBeenCalled();

const ipv6 = getByLabelText('IPv6 Addresses or CIDRs ip-address-0');
await userEvent.type(ipv6, 'test');

expect(props.handleIPv6Change).toHaveBeenCalled();
});
});
Loading

0 comments on commit 1a9d479

Please sign in to comment.