Merge pull request #14 from lseppala/lsep/purl-qualifiers
Fix encoding of PURL qualifiers
This commit is contained in:
@@ -1,20 +1,53 @@
|
|||||||
import ComponentDetection from './componentDetection';
|
import ComponentDetection from "./componentDetection";
|
||||||
import fs from 'fs';
|
import fs from "fs";
|
||||||
|
|
||||||
test('Downloads CLI', async () => {
|
test("Downloads CLI", async () => {
|
||||||
await ComponentDetection.downloadLatestRelease();
|
await ComponentDetection.downloadLatestRelease();
|
||||||
expect(fs.existsSync(ComponentDetection.componentDetectionPath));
|
expect(fs.existsSync(ComponentDetection.componentDetectionPath));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Runs CLI', async () => {
|
test("Runs CLI", async () => {
|
||||||
await ComponentDetection.downloadLatestRelease();
|
await ComponentDetection.downloadLatestRelease();
|
||||||
await ComponentDetection.runComponentDetection('./test');
|
await ComponentDetection.runComponentDetection("./test");
|
||||||
expect(fs.existsSync(ComponentDetection.outputPath));
|
expect(fs.existsSync(ComponentDetection.outputPath));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Parses CLI output', async () => {
|
test("Parses CLI output", async () => {
|
||||||
await ComponentDetection.downloadLatestRelease();
|
await ComponentDetection.downloadLatestRelease();
|
||||||
await ComponentDetection.runComponentDetection('./test');
|
await ComponentDetection.runComponentDetection("./test");
|
||||||
var manifests = await ComponentDetection.getManifestsFromResults();
|
var manifests = await ComponentDetection.getManifestsFromResults();
|
||||||
expect(manifests?.length == 2);
|
expect(manifests?.length == 2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("ComponentDetection.makePackageUrl", () => {
|
||||||
|
test("returns a valid package url from saturated object", () => {
|
||||||
|
const packageUrl = ComponentDetection.makePackageUrl({
|
||||||
|
Scheme: "pkg",
|
||||||
|
Type: "npm",
|
||||||
|
Namespace: "github",
|
||||||
|
Name: "component-detection-action",
|
||||||
|
Version: "0.0.2",
|
||||||
|
Qualifiers: {
|
||||||
|
arch: "amd64",
|
||||||
|
os: "linux",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expect(packageUrl).toBe(
|
||||||
|
"pkg:npm/github/[email protected]?arch=amd64&os=linux"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("returns valid package url without dangling ? with empty qualifers", () => {
|
||||||
|
const packageUrl = ComponentDetection.makePackageUrl({
|
||||||
|
Scheme: "pkg",
|
||||||
|
Type: "npm",
|
||||||
|
Namespace: "github",
|
||||||
|
Name: "component-detection-action",
|
||||||
|
Version: "0.0.2",
|
||||||
|
Qualifiers: { },
|
||||||
|
});
|
||||||
|
expect(packageUrl).toBe(
|
||||||
|
"pkg:npm/github/[email protected]"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ export default class ComponentDetection {
|
|||||||
return pkg.isDevelopmentDependency ? 'development' : 'runtime'
|
return pkg.isDevelopmentDependency ? 'development' : 'runtime'
|
||||||
}
|
}
|
||||||
|
|
||||||
private static makePackageUrl(packageUrlJson: any): string {
|
public static makePackageUrl(packageUrlJson: any): string {
|
||||||
var packageUrl = `${packageUrlJson.Scheme}:${packageUrlJson.Type}/`;
|
var packageUrl = `${packageUrlJson.Scheme}:${packageUrlJson.Type}/`;
|
||||||
if (packageUrlJson.Namespace) {
|
if (packageUrlJson.Namespace) {
|
||||||
packageUrl += `${packageUrlJson.Namespace.replaceAll("@", "%40")}/`;
|
packageUrl += `${packageUrlJson.Namespace.replaceAll("@", "%40")}/`;
|
||||||
@@ -128,8 +128,13 @@ export default class ComponentDetection {
|
|||||||
if (packageUrlJson.Version) {
|
if (packageUrlJson.Version) {
|
||||||
packageUrl += `@${packageUrlJson.Version}`;
|
packageUrl += `@${packageUrlJson.Version}`;
|
||||||
}
|
}
|
||||||
if (packageUrlJson.Qualifiers) {
|
if (typeof packageUrlJson.Qualifiers === "object"
|
||||||
packageUrl += `?${packageUrlJson.Qualifiers}`;
|
&& packageUrlJson.Qualifiers !== null
|
||||||
|
&& Object.keys(packageUrlJson.Qualifiers).length > 0) {
|
||||||
|
const qualifierString = Object.entries(packageUrlJson.Qualifiers)
|
||||||
|
.map(([key, value]) => `${key}=${value}`)
|
||||||
|
.join("&");
|
||||||
|
packageUrl += `?${qualifierString}`;
|
||||||
}
|
}
|
||||||
return packageUrl;
|
return packageUrl;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -8,6 +8,6 @@ export default class ComponentDetection {
|
|||||||
private static getComponentDetectionParameters;
|
private static getComponentDetectionParameters;
|
||||||
static getManifestsFromResults(): Promise<Manifest[] | undefined>;
|
static getManifestsFromResults(): Promise<Manifest[] | undefined>;
|
||||||
private static getDependencyScope;
|
private static getDependencyScope;
|
||||||
private static makePackageUrl;
|
static makePackageUrl(packageUrlJson: any): string;
|
||||||
private static getLatestReleaseURL;
|
private static getLatestReleaseURL;
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-2
@@ -23425,8 +23425,13 @@ class ComponentDetection {
|
|||||||
if (packageUrlJson.Version) {
|
if (packageUrlJson.Version) {
|
||||||
packageUrl += `@${packageUrlJson.Version}`;
|
packageUrl += `@${packageUrlJson.Version}`;
|
||||||
}
|
}
|
||||||
if (packageUrlJson.Qualifiers) {
|
if (typeof packageUrlJson.Qualifiers === "object"
|
||||||
packageUrl += `?${packageUrlJson.Qualifiers}`;
|
&& packageUrlJson.Qualifiers !== null
|
||||||
|
&& Object.keys(packageUrlJson.Qualifiers).length > 0) {
|
||||||
|
const qualifierString = Object.entries(packageUrlJson.Qualifiers)
|
||||||
|
.map(([key, value]) => `${key}=${value}`)
|
||||||
|
.join("&");
|
||||||
|
packageUrl += `?${qualifierString}`;
|
||||||
}
|
}
|
||||||
return packageUrl;
|
return packageUrl;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user