8000 Fix Dependency Track Hook by p4trickweiss · Pull Request #3290 · secureCodeBox/secureCodeBox · GitHub
[go: up one dir, main page]

Skip to content
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
11 changes: 10 additions & 1 deletion hooks/persistence-dependencytrack/hook/hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@ export async function handle({
return;
}

const result = await getRawResults();
const rawResult = await getRawResults();

let result;
try {
result = JSON.parse(rawResult);
} catch {
console.log("Response is not a valid json object.");
return;
}

if (result.bomFormat !== "CycloneDX") {
// Not a CycloneDX SBOM, cannot be handled by Dependency-Track, ignore
console.log(
Expand Down
16 changes: 12 additions & 4 deletions hooks/persistence-dependencytrack/hook/hook.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ beforeEach(() => {
test("should not send a post request if not an SBOM scan", async () => {
const result = {};

const getRawResults = async () => result;
const stringResult = JSON.stringify(result);

const getRawResults = async () => stringResult;

const scan = {
metadata: {
Expand Down Expand Up @@ -53,7 +55,9 @@ test("should not send a post request if not a CycloneDX SBOM", async () => {
},
};

const getRawResults = async () => result;
const stringResult = JSON.stringify(result);

const getRawResults = async () => stringResult;

// technically we're saying here that this scan is a CycloneDX scan even though we're then sending something looking like an SPDX SBOM
const scan = {
Expand Down Expand Up @@ -84,7 +88,9 @@ test("should send a post request to the url when fired", async () => {
},
};

const getRawResults = async () => result;
const stringResult = JSON.stringify(result);

const getRawResults = async () => stringResult;

const scan = {
metadata: {
Expand Down Expand Up @@ -169,7 +175,9 @@ test.each([
},
};

const getRawResults = async () => result;
const stringResult = JSON.stringify(result);

const getRawResults = async () => stringResult;

const scan = {
metadata: {
Expand Down
Loading
0