Skip to content

Commit cc28ed9

Browse files
committed
wip
1 parent 192dc64 commit cc28ed9

File tree

3 files changed

+95
-23
lines changed

3 files changed

+95
-23
lines changed

playwright/Customizations/OpenSCAP.spec.ts

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expect } from '@playwright/test';
22
import { v4 as uuidv4 } from 'uuid';
33

44
import { test } from '../fixtures/cleanup';
5-
import { isHosted } from '../helpers/helpers';
5+
import { isHosted, getHostDistro } from '../helpers/helpers';
66
import { ensureAuthenticated } from '../helpers/login';
77
import { ibFrame, navigateToLandingPage } from '../helpers/navHelpers';
88
import {
@@ -171,9 +171,67 @@ test('Create a blueprint with OpenSCAP customization', async ({
171171
.click();
172172
});
173173

174-
// This is for hosted service only as these features are not available in cockpit plugin
175174
await test.step('Export BP', async () => {
176-
await exportBlueprint(page, blueprintName);
175+
await exportBlueprint(frame, blueprintName, JSON.stringify(
176+
{
177+
"name": blueprintName,
178+
"description": "",
179+
"distribution": isHosted() ? "rhel-9" : getHostDistro(),
180+
"image_requests": [
181+
{
182+
"architecture": "x86_64",
183+
"image_type": "guest-image",
184+
"upload_request": {
185+
"type": "aws.s3",
186+
"options": {}
187+
}
188+
}
189+
],
190+
"customizations": {
191+
"filesystem": [
192+
{
193+
"min_size": 1073741824,
194+
"mountpoint": "/tmp"
195+
}
196+
],
197+
"kernel": {
198+
"append": ""
199+
},
200+
"openscap": {
201+
"profile_description": "This profile defines a baseline that aligns to the \"Level 1 - Server\" configuration from the Center for Internet Security® Red Hat Enterprise Linux 9 Benchmark™, v2.0.0, released 2024-06-20. This profile includes Center for Internet Security® Red Hat Enterprise Linux 9 CIS Benchmarks™ content.",
202+
"profile_id": "xccdf_org.ssgproject.content_profile_cis_server_l1",
203+
"profile_name": "CIS Red Hat Enterprise Linux 9 Benchmark for Level 1 - Server"
204+
},
205+
"packages": [
206+
"aide",
207+
"sudo",
208+
"libpwquality",
209+
"systemd-journal-remote",
210+
"firewalld",
211+
"nftables",
212+
"libselinux",
213+
"cronie",
214+
"chrony"
215+
],
216+
"services": {
217+
"enabled": [
218+
"crond",
219+
"firewalld",
220+
"systemd-journald"
221+
],
222+
"masked": [
223+
"cups",
224+
"nfs-server",
225+
"rpcbind",
226+
"avahi-daemon",
227+
"autofs",
228+
"bluetooth",
229+
"nftables"
230+
]
231+
}
232+
}
233+
}
234+
));
177235
});
178236

179237
await test.step('Import BP', async () => {

playwright/helpers/helpers.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ const ON_PREM_RELEASES = new Map([
5959
['rhel-10', 'Red Hat Enterprise Linux (RHEL) 10'],
6060
]);
6161

62-
/* eslint-disable @typescript-eslint/no-explicit-any */
63-
export const getHostDistroName = (): string => {
62+
63+
export const getHostDistro = (): string => {
6464
const osRelData = readFileSync('/etc/os-release');
6565
const lines = osRelData
6666
.toString('utf-8')
@@ -72,19 +72,22 @@ export const getHostDistroName = (): string => {
7272
const lineData = l.split('=');
7373
(osRel as any)[lineData[0]] = lineData[1].replace(/"/g, '');
7474
}
75+
return `${(osRel as any)['ID']}-${(osRel as any)['VERSION_ID'].split('.')[0]}`
76+
}
77+
78+
/* eslint-disable @typescript-eslint/no-explicit-any */
79+
export const getHostDistroName = (): string => {
80+
const distro = getHostDistro();
7581

7682
// strip minor version from rhel
77-
const distro = ON_PREM_RELEASES.get(
78-
`${(osRel as any)['ID']}-${(osRel as any)['VERSION_ID'].split('.')[0]}`,
79-
);
83+
const distroName = ON_PREM_RELEASES.get(distro);
8084

81-
if (distro === undefined) {
85+
if (distroName === undefined) {
8286
/* eslint-disable no-console */
83-
console.error('getHostDistroName failed, os-release config:', osRel);
87+
console.error('getHostDistroName failed, host distro:', distro);
8488
throw new Error('getHostDistroName failed, distro undefined');
8589
}
86-
87-
return distro;
90+
return distroName;
8891
};
8992

9093
export const getHostArch = (): string => {

playwright/helpers/wizardHelpers.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as fs from 'fs';
22
import * as path from 'path';
3+
import * as os from 'os';
34

45
import { expect, FrameLocator, type Page, test } from '@playwright/test';
56

@@ -110,18 +111,28 @@ export const deleteBlueprint = async (page: Page, blueprintName: string) => {
110111

111112
/**
112113
* Export the blueprint
113-
* This function executes only on the hosted service
114-
* @param page - the page object
114+
* @param page - the page or frame object
115+
* @param expectedContents - the expected contents of the exported blueprint file
115116
*/
116-
export const exportBlueprint = async (page: Page, blueprintName: string) => {
117-
if (isHosted()) {
118-
await page.getByRole('button', { name: 'Menu toggle' }).click();
119-
const downloadPromise = page.waitForEvent('download');
120-
await page
121-
.getByRole('menuitem', { name: 'Download blueprint (.json)' })
122-
.click();
123-
const download = await downloadPromise;
124-
await download.saveAs('../../downloads/' + blueprintName + '.json');
117+
export const exportBlueprint = async (page: Page | FrameLocator, expectedContents: string) => {
118+
const downloadPromise = frame.waitForEvent('download');
119+
await frame.getByRole('button', { name: 'blueprint menu toggle' }).click();
120+
await frame.getByRole('menuitem', { name: isHosted() ? 'Download blueprint (.toml)' : 'Download blueprint (.json)' }).click();
121+
const download = await downloadPromise;
122+
if expectedContents == "" {
123+
return
124+
}
125+
126+
try {
127+
const temp = await fs.mkdtempDisposable(join(os.tmpdir(), 'export-bp-'));
128+
const path = path.join(temp.path, download.suggestedFilename());
129+
await download.saveAs(path);
130+
const contents = fs.readFileSync(path);
131+
expect(content).toEqual(expectedContents);
132+
} catch (err) {
133+
console.error('unable to read exported blueprint file and compare contents: ', err)
134+
} finally {
135+
await temp.remove();
125136
}
126137
};
127138

0 commit comments

Comments
 (0)