Skip to content

Commit

Permalink
[e2e-tests] Add security scan check to quay plugin suite (janus-idp#1021
Browse files Browse the repository at this point in the history
)

Co-authored-by: Joseph Kim <joskim@redhat.com>
  • Loading branch information
jrichter1 and josephca committed Mar 11, 2024
1 parent 928aa4a commit 852a05e
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 5 deletions.
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');
});

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();
}
}

0 comments on commit 852a05e

Please sign in to comment.