Skip to content

Commit

Permalink
[e2e-tests] Add security scan check to quay plugin suite
Browse files Browse the repository at this point in the history
  • Loading branch information
jrichter1 committed Mar 5, 2024
1 parent 67f9c53 commit a2b88f4
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 6 deletions.
41 changes: 36 additions & 5 deletions e2e-tests/playwright/e2e/plugins/quay/quay.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
import { test } from '@playwright/test';
import { Page, test, chromium, firefox, expect } from '@playwright/test';
import { UIhelper } from '../../../utils/UIhelper';
import { Common } from '../../../utils/Common';
import { ImageRegistry } from '../../../utils/quay/quay';
import { UIhelperPO } from '../../../support/pageObjects/global-obj';

test.describe('Test Quay.io plugin', () => {
test.describe.serial('Test Quay.io plugin', () => {
let page: Page;
let uiHelper: UIhelper;
const QUAY_REPOSITORY = 'janus-idp/backstage-showcase';

test.beforeEach(async ({ page }) => {
test.beforeAll(async ({ browserName }) => {
const browserType = browserName === 'firefox' ? firefox : chromium;
const browser = await browserType.launch();
page = await browser.newPage();

uiHelper = new UIhelper(page);
const common = new Common(page);
await common.loginAsGuest();
});

test('Check if Image Registry is present', async ({ page }) => {
const uiHelper = new UIhelper(page);
test('Check if Image Registry is present', async () => {
await uiHelper.openSidebar('Catalog');
await uiHelper.selectMuiBox('Kind', 'Component');
await uiHelper.clickLink('backstage-janus');
Expand All @@ -25,4 +32,28 @@ test.describe('Test Quay.io plugin', () => {
const allCellsIdentifier = ImageRegistry.getAllCellsIdentifier();
await uiHelper.verifyCellsInTable(allCellsIdentifier);
});

test('Check Security Scan details', async () => {
const cell = page
.locator(UIhelperPO.MuiTableCell)
.filter({ hasText: ImageRegistry.securityScanRegex() })
.first();
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 expect(page.getByText('No records to display')).toBeVisible();
} else {
await uiHelper.verifyCellsInTable(
ImageRegistry.getScanCellsIdentifier(),
);
}
}
});
});
35 changes: 34 additions & 1 deletion e2e-tests/playwright/utils/quay/quay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,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() {
Expand All @@ -24,4 +32,29 @@ 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];
}
}

0 comments on commit a2b88f4

Please sign in to comment.