From 774714cb9978ff8eb483ea1c5eee994376c76e54 Mon Sep 17 00:00:00 2001 From: Katarina Sieklova Date: Tue, 29 Apr 2025 14:53:24 +0200 Subject: [PATCH] Wizard: add Firewall test --- playwright/Customizations/Firewall.spec.ts | 139 +++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 playwright/Customizations/Firewall.spec.ts diff --git a/playwright/Customizations/Firewall.spec.ts b/playwright/Customizations/Firewall.spec.ts new file mode 100644 index 00000000..e2fa5481 --- /dev/null +++ b/playwright/Customizations/Firewall.spec.ts @@ -0,0 +1,139 @@ +import { expect } from '@playwright/test'; +import { v4 as uuidv4 } from 'uuid'; + +import { test } from '../fixtures/cleanup'; +import { isHosted } from '../helpers/helpers'; +import { login } from '../helpers/login'; +import { navigateToOptionalSteps, ibFrame } from '../helpers/navHelpers'; +import { + registerLater, + fillInDetails, + createBlueprint, + fillInImageOutputGuest, + deleteBlueprint, + exportBlueprint, + importBlueprint, +} from '../helpers/wizardHelpers'; + +test('Create a blueprint with Firewall customization', async ({ + page, + cleanup, +}) => { + const blueprintName = 'test-' + uuidv4(); + + // Delete the blueprint after the run fixture + await cleanup.add(() => deleteBlueprint(page, blueprintName)); + + // Login, navigate to IB and get the frame + await login(page); + const frame = await ibFrame(page); + + await test.step('Navigate to optional steps in Wizard', async () => { + await navigateToOptionalSteps(frame); + await registerLater(frame); + }); + + await test.step('Select and correctly fill the ports in Firewall step', async () => { + await frame.getByRole('button', { name: 'Firewall' }).click(); + await frame.getByPlaceholder('Add ports').fill('80:tcp'); + await frame.getByRole('button', { name: 'Add ports' }).click(); + await expect(frame.getByText('80:tcp')).toBeVisible(); + }); + + await test.step('Select and correctly fill the disabled services in Firewall step', async () => { + await frame + .getByPlaceholder('Add disabled service') + .fill('disabled_service'); + await frame.getByRole('button', { name: 'Add disabled service' }).click(); + await expect(frame.getByText('disabled_service')).toBeVisible(); + }); + + await test.step('Select and correctly fill the enabled services in Firewall step', async () => { + await frame.getByPlaceholder('Add enabled service').fill('enabled_service'); + await frame.getByRole('button', { name: 'Add enabled service' }).click(); + await expect(frame.getByText('enabled_service')).toBeVisible(); + }); + + await test.step('Select and incorrectly fill the ports in Firewall step', async () => { + await frame.getByPlaceholder('Add ports').fill('x'); + await frame.getByRole('button', { name: 'Add ports' }).click(); + await expect(frame.getByText('Invalid format.').nth(0)).toBeVisible(); + }); + + await test.step('Select and incorrectly fill the disabled services in Firewall step', async () => { + await frame.getByPlaceholder('Add disabled service').fill('1'); + await frame.getByRole('button', { name: 'Add disabled service' }).click(); + await expect(frame.getByText('Invalid format.').nth(1)).toBeVisible(); + }); + + await test.step('Select and incorrectly fill the enabled services in Firewall step', async () => { + await frame.getByPlaceholder('Add enabled service').fill('ťčš'); + await frame.getByRole('button', { name: 'Add enabled service' }).click(); + await expect(frame.getByText('Invalid format.').nth(2)).toBeVisible(); + }); + + await test.step('Fill the BP details', async () => { + await frame.getByRole('button', { name: 'Review and finish' }).click(); + await fillInDetails(frame, blueprintName); + }); + + await test.step('Create BP', async () => { + await createBlueprint(frame, blueprintName); + }); + + await test.step('Edit BP', async () => { + await frame.getByRole('button', { name: 'Edit blueprint' }).click(); + await frame.getByLabel('Revisit Firewall step').click(); + + await frame.getByPlaceholder('Add ports').fill('90:tcp'); + await frame.getByRole('button', { name: 'Add ports' }).click(); + await frame.getByPlaceholder('Add disabled service').fill('x'); + await frame.getByRole('button', { name: 'Add disabled service' }).click(); + await frame.getByPlaceholder('Add enabled service').fill('y'); + await frame.getByRole('button', { name: 'Add enabled service' }).click(); + + await frame.getByRole('button', { name: 'Close 80:tcp' }).click(); + await frame.getByRole('button', { name: 'Close enabled_service' }).click(); + await frame.getByRole('button', { name: 'Close disabled_service' }).click(); + + await expect(frame.getByText('90:tcp')).toBeVisible(); + await expect(frame.getByText('x').nth(0)).toBeVisible(); + await expect(frame.getByText('y').nth(0)).toBeVisible(); + + await expect(frame.getByText('80:tcp')).toBeHidden(); + await expect(frame.getByText('disabled_service')).toBeHidden(); + await expect(frame.getByText('enabled_service')).toBeHidden(); + + await frame.getByRole('button', { name: 'Review and finish' }).click(); + await frame + .getByRole('button', { name: 'Save changes to blueprint' }) + .click(); + }); + + // This is for hosted service only as these features are not available in cockpit plugin + await test.step('Export BP', async (step) => { + step.skip(!isHosted(), 'Exporting is not available in the plugin'); + await exportBlueprint(page, blueprintName); + }); + + await test.step('Import BP', async (step) => { + step.skip(!isHosted(), 'Importing is not available in the plugin'); + await importBlueprint(page, blueprintName); + }); + + await test.step('Review imported BP', async (step) => { + step.skip(!isHosted(), 'Importing is not available in the plugin'); + await fillInImageOutputGuest(page); + await page.getByRole('button', { name: 'Firewall' }).click(); + + await expect(frame.getByText('90:tcp')).toBeVisible(); + await expect(frame.getByText('x').nth(0)).toBeVisible(); + await expect(frame.getByText('y').nth(0)).toBeVisible(); + + await expect(frame.getByText('80:tcp')).toBeHidden(); + await expect(frame.getByText('disabled_service')).toBeHidden(); + await expect(frame.getByText('enabled_service')).toBeHidden(); + + await page.getByRole('button', { name: 'Cancel' }).click(); + }); +});