From 852a05e8f10fbe7945cd5edde745eab24f0ad90a Mon Sep 17 00:00:00 2001 From: Jan Richter Date: Mon, 11 Mar 2024 13:29:27 +0100 Subject: [PATCH] [e2e-tests] Add security scan check to quay plugin suite (#1021) Co-authored-by: Joseph Kim --- .../playwright/e2e/plugins/quay/quay.spec.ts | 30 ++++++++++-- e2e-tests/playwright/utils/quay/quay.ts | 46 ++++++++++++++++++- 2 files changed, 71 insertions(+), 5 deletions(-) diff --git a/e2e-tests/playwright/e2e/plugins/quay/quay.spec.ts b/e2e-tests/playwright/e2e/plugins/quay/quay.spec.ts index 11083e722..544430697 100644 --- a/e2e-tests/playwright/e2e/plugins/quay/quay.spec.ts +++ b/e2e-tests/playwright/e2e/plugins/quay/quay.spec.ts @@ -1,23 +1,24 @@ -import { test } from '@playwright/test'; +import { expect, test } from '@playwright/test'; import { UIhelper } from '../../../utils/UIhelper'; import { Common } from '../../../utils/Common'; import { ImageRegistry } from '../../../utils/quay/quay'; test.describe('Test Quay.io plugin', () => { const QUAY_REPOSITORY = 'janus-idp/backstage-showcase'; + let uiHelper: UIhelper; test.beforeEach(async ({ page }) => { const common = new Common(page); await common.loginAsGuest(); - }); - test('Check if Image Registry is present', async ({ page }) => { - const uiHelper = new UIhelper(page); + uiHelper = new UIhelper(page); await uiHelper.openSidebar('Catalog'); await uiHelper.selectMuiBox('Kind', 'Component'); await uiHelper.clickLink('backstage-janus'); await uiHelper.clickTab('Image Registry'); + }); + test('Check if Image Registry is present', async () => { const allGridColumnsText = ImageRegistry.getAllGridColumnsText(); await uiHelper.verifyColumnHeading(allGridColumnsText); await uiHelper.verifyHeading(`Quay repository: ${QUAY_REPOSITORY}`); @@ -25,4 +26,25 @@ test.describe('Test Quay.io plugin', () => { const allCellsIdentifier = ImageRegistry.getAllCellsIdentifier(); await uiHelper.verifyCellsInTable(allCellsIdentifier); }); + + test('Check Security Scan details', async ({ page }) => { + const cell = await ImageRegistry.getScanCell(page); + const resultText = await cell.textContent(); + + if (resultText.includes('unsupported')) { + await expect(cell.getByRole('link')).toHaveCount(0); + } else { + await cell.getByRole('link').click(); + await uiHelper.verifyHeading('Vulnerabilities for sha256:'); + await uiHelper.verifyColumnHeading(ImageRegistry.getAllScanColumnsText()); + + if (resultText.includes('Passed')) { + await uiHelper.verifyCellsInTable(['No records to display']); + } else { + await uiHelper.verifyCellsInTable( + ImageRegistry.getScanCellsIdentifier(), + ); + } + } + }); }); diff --git a/e2e-tests/playwright/utils/quay/quay.ts b/e2e-tests/playwright/utils/quay/quay.ts index 59106c4de..d62fa6b69 100644 --- a/e2e-tests/playwright/utils/quay/quay.ts +++ b/e2e-tests/playwright/utils/quay/quay.ts @@ -1,3 +1,6 @@ +import { Page } from '@playwright/test'; +import { UIhelperPO } from '../../support/pageObjects/global-obj'; + export class ImageRegistry { static getAllCellsIdentifier() { //create a regex to verify if the string contains pr on it @@ -11,7 +14,15 @@ export class ImageRegistry { '^(Mon|Tue|Wed|Thu|Fri|Sat|Sun), \\d{1,2} (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \\d{4} \\d{1,2}:\\d{2}:\\d{2} [\\+\\-]\\d{4}$'; const expiresRegex = new RegExp(expires); const manifest = /sha256/; - return [tagText, lastModifiedDate, size, expiresRegex, manifest]; + + return [ + tagText, + lastModifiedDate, + this.securityScanRegex(), + size, + expiresRegex, + manifest, + ]; } static getAllGridColumnsText() { @@ -24,4 +35,37 @@ export class ImageRegistry { 'Manifest', ]; } + + static securityScanRegex() { + const securityScan = ['Critical', 'High', 'Medium', 'Low', 'Unknown'].map( + i => `(${i}:\\s\\d+[^\\w]*)`, + ); + return new RegExp(`^(Passed|unsupported|(?:${securityScan.join('|')})+)$`); + } + + static getAllScanColumnsText() { + return [ + 'Advisory', + 'Severity', + 'Package Name', + 'Current Version', + 'Fixed By', + ]; + } + + static getScanCellsIdentifier() { + const advisory = /^(CVE|RHSA)-.+/; + const severity = /Critical|High|Medium|Low|Unknown/; + const version = /^(\d+:)?\d+\.\d+/; + + return [advisory, severity, version]; + } + + static async getScanCell(page: Page) { + const locator = page + .locator(UIhelperPO.MuiTableCell) + .filter({ hasText: this.securityScanRegex() }); + await locator.first().waitFor(); + return locator.first(); + } }