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

[e2e-tests] Add security scan check to quay plugin suite #1021

Merged
merged 2 commits into from
Mar 11, 2024
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
30 changes: 26 additions & 4 deletions e2e-tests/playwright/e2e/plugins/quay/quay.spec.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,50 @@
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');
});

jrichter1 marked this conversation as resolved.
Show resolved Hide resolved
test('Check if Image Registry is present', async () => {
const allGridColumnsText = ImageRegistry.getAllGridColumnsText();
await uiHelper.verifyColumnHeading(allGridColumnsText);
await uiHelper.verifyHeading(`Quay repository: ${QUAY_REPOSITORY}`);

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(),
);
}
}
});
});
46 changes: 45 additions & 1 deletion e2e-tests/playwright/utils/quay/quay.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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() {
Expand All @@ -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();
}
}
Loading