-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathlicense-export_cdx.step.ts
More file actions
205 lines (177 loc) · 6.48 KB
/
license-export_cdx.step.ts
File metadata and controls
205 lines (177 loc) · 6.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import { createBdd } from "playwright-bdd";
import * as fs from "node:fs";
import { test } from "../../fixtures";
import { expect } from "../../assertions";
import { SbomListPage } from "../../pages/sbom-list/SbomListPage";
import { SbomDetailsPage } from "../../pages/sbom-details/SbomDetailsPage";
import { DetailsPage } from "../../helpers/DetailsPage";
import { SearchPage } from "../../helpers/SearchPage";
import { clickAndVerifyDownload } from "../../pages/Helpers";
import {
downloadLicenseReport,
extractLicenseReport,
findCsvWithHeader,
} from "../../pages/LicenseExportHelpers";
export const { Given, When, Then } = createBdd(test);
let downloadedFilename: string;
let downloadedFilePath: string;
let extractionPath: string;
let packageLicenseFilePath: string;
let licenseReferenceFilePath: string;
Given(
"User Searches for CycloneDX SBOM {string} using Search Text box",
async ({ page }, sbomName: string) => {
const listPage = await SbomListPage.build(page);
const toolbar = await listPage.getToolbar();
await toolbar.applyFilter({ "Filter text": sbomName });
},
);
Given(
"User Searches for CycloneDX SBOM {string} using Search Text box and Navigates to Search results page",
async ({ page }, sbomName: string) => {
const searchPage = new SearchPage(page, "Search");
await searchPage.generalSearch("SBOMs", sbomName);
},
);
When(
"User Selects CycloneDX SBOM {string} from the Search Results",
async ({ page }, sbomName: string) => {
const listPage = await SbomListPage.fromCurrentPage(page);
const table = await listPage.getTable();
await table.waitUntilDataIsLoaded();
await expect(table).toHaveColumnWithValue("Name", sbomName);
},
);
When(
"User Clicks on SBOM name hyperlink from the Search Results",
async ({ page }) => {
const listPage = await SbomListPage.fromCurrentPage(page);
const table = await listPage.getTable();
const rows = await table.getRows();
await rows.first().getByRole("link").click();
},
);
Then("Application Navigates to SBOM Explorer page", async ({ page }) => {
await expect(page).toHaveURL(/\/sboms\/[^/]+/);
});
When('User Clicks "Action" button', async ({ page }) => {
const detailsPage = new DetailsPage(page);
await detailsPage.openActionsMenu();
});
Then('"Download License Report" Option should be visible', async ({ page }) => {
const detailsPage = new DetailsPage(page);
await expect(detailsPage).toHaveVisibleAction("Download License Report");
});
When('Selects "Download License Report" option', async ({ page }) => {
const detailsPage = new DetailsPage(page);
downloadedFilename = await clickAndVerifyDownload(
page,
async () =>
await detailsPage.page
.getByRole("menuitem", { name: "Download License Report" })
.click(),
);
});
Then(
"Licenses associated with the SBOM should be downloaded in TAR.GZ format using the SBOM name",
async ({ page }) => {
const sbomName = await page.getByRole("heading").first().innerText();
expect(downloadedFilename).toContain(sbomName);
expect(downloadedFilename.endsWith(".tar.gz")).toBeTruthy();
},
);
Given(
"User is on SBOM Explorer page for the CycloneDX SBOM {string}",
async ({ page }, sbomName: string) => {
await SbomDetailsPage.build(page, sbomName);
},
);
When('User Clicks on "Download License Report" button', async ({ page }) => {
const detailsPage = new DetailsPage(page);
await detailsPage.openActionsMenu();
downloadedFilename = await clickAndVerifyDownload(
page,
async () =>
await detailsPage.page
.getByRole("menuitem", { name: "Download License Report" })
.click(),
);
});
Given(
"User has Downloaded the License information for CycloneDX SBOM {string}",
async ({ page }, sbomName: string) => {
await SbomDetailsPage.build(page, sbomName);
downloadedFilePath = await downloadLicenseReport(page);
},
);
When("User extracts the Downloaded license TAR.GZ file", async () => {
extractionPath = await extractLicenseReport(downloadedFilePath);
});
Then(
"Extracted files should contain two CSVs, one for Package license information and another one for License reference",
async () => {
const files = fs.readdirSync(extractionPath);
const csvFiles = files.filter((file) => file.endsWith(".csv"));
expect(csvFiles.length).toBe(2);
},
);
Given(
"User extracted the CycloneDX SBOM {string} license compressed file",
async ({ page }, sbomName: string) => {
await SbomDetailsPage.build(page, sbomName);
downloadedFilePath = await downloadLicenseReport(page);
extractionPath = await extractLicenseReport(downloadedFilePath);
},
);
When("User Opens the package license information file", async () => {
packageLicenseFilePath = findCsvWithHeader(
extractionPath,
"SBOM name",
"Package license information file",
);
});
Then(
"The file should have the following headers - SBOM name, SBOM id, package name, package group, package version, package purl, package cpe and license",
async () => {
const content = fs.readFileSync(packageLicenseFilePath, "utf-8");
const headers = content.split("\n")[0].trim();
const expectedHeaders =
'"SBOM name"\t"SBOM id"\t"package name"\t"package group"\t"package version"\t"package purl"\t"package cpe"\t"license"\t"license type"';
expect(headers).toBe(expectedHeaders);
},
);
When("User Opens the license reference file", async () => {
licenseReferenceFilePath = findCsvWithHeader(
extractionPath,
"licenseId",
"License reference file",
);
});
Then(
"The file should have the following headers - licenseId, name, extracted text and comment",
async () => {
const content = fs.readFileSync(licenseReferenceFilePath, "utf-8");
const headers = content.split("\n")[0].trim();
const expectedHeaders = '"licenseId"\t"name"\t"extracted text"\t"comment"';
expect(headers).toBe(expectedHeaders);
},
);
Given(
"User is on license reference {string} file",
async ({ page }, sbomName: string) => {
await SbomDetailsPage.build(page, sbomName);
downloadedFilePath = await downloadLicenseReport(page);
extractionPath = await extractLicenseReport(downloadedFilePath);
licenseReferenceFilePath = findCsvWithHeader(
extractionPath,
"licenseId",
"License reference file",
);
},
);
Then("The License reference CSV should be empty", async () => {
const content = fs.readFileSync(licenseReferenceFilePath, "utf-8");
const lines = content.trim().split("\n");
// Only header should be present
expect(lines.length).toBe(1);
});