-
-
Notifications
You must be signed in to change notification settings - Fork 219
feat: Dependency track tags reporting #2473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gschafra
wants to merge
27
commits into
CycloneDX:master
Choose a base branch
from
gschafra:dependency-track-tags-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+240
−0
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
d3afc75
feat: Dependency track tags reporting
89c2627
test(cli): Started implementing unit test for SBOM reporting params
gschafra ee85a6f
Merge branch 'master' into dependency-track-tags-support
gschafra 068be9a
docs(cli): Docs concerning tag feature on SBOM reporting
gschafra c3fc454
test(cli): First SBOM reporting test
gschafra 10c6f7c
build(deps): Package fixed versions and overrides
gschafra 9777208
build(deps): Package overrides
gschafra ef52e56
test(cli): Added another test case
gschafra a99782e
Merge branch 'master' into dependency-track-tags-support
gschafra d6e797e
style(cli): Biome fix/format
df3d26b
build(deps): Reverted overrides, only keeping direct packages
09a2613
test(utils): Adapted parsePnpmLock test
24b69ca
style: Biome fix/format
e58f46d
Merge branch 'master' into dependency-track-tags-support
gschafra a4efbe0
Merge remote-tracking branch 'origin/dependency-track-tags-support' i…
gschafra a0661b6
test(cli): Code style
gschafra a926aa6
Merge branch 'master' into dependency-track-tags-support
gschafra 5844f04
Merge branch 'master' into dependency-track-tags-support
gschafra 41b5824
Merge branch 'master' into dependency-track-tags-support
gschafra 7534f4a
Merge branch 'master' into dependency-track-tags-support
gschafra f531872
build(deps): Dependency lock fix
gschafra 13e5886
test(cli): Switched to esmock
gschafra 443b7d7
test(cli): Implemented cli sbom submission
gschafra 35d9bf7
chore: Removed obsolete overrides
gschafra 7e1cb13
chore: Removed volta config
gschafra 0bb74fd
chore: Review fixes
gschafra 1392d80
chore: Review fixes
gschafra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| import esmock from "esmock"; | ||
| import { assert, describe, it } from "poku"; | ||
| import sinon from "sinon"; | ||
|
|
||
| describe("CLI tests", () => { | ||
| describe("submitBom()", () => { | ||
| it("should successfully report the SBOM with given project id, name, version and a single tag", async () => { | ||
| const fakeGotResponse = { | ||
| json: sinon.stub().resolves({ success: true }), | ||
| }; | ||
|
|
||
| const gotStub = sinon.stub().returns(fakeGotResponse); | ||
| gotStub.extend = sinon.stub().returns(gotStub); | ||
|
|
||
| const { submitBom } = await esmock("./index.js", { | ||
| got: { default: gotStub }, | ||
| }); | ||
|
|
||
| const serverUrl = "https://dtrack.example.com"; | ||
| const projectId = "f7cb9f02-8041-4991-9101-b01fa07a6522"; | ||
| const projectName = "cdxgen-test-project"; | ||
| const projectVersion = "1.0.0"; | ||
| const projectTag = "tag1"; | ||
| const bomContent = { bom: "test" }; | ||
| const apiKey = "TEST_API_KEY"; | ||
| const skipDtTlsCheck = false; | ||
|
|
||
| const expectedRequestPayload = { | ||
| autoCreate: "true", | ||
| bom: "eyJib20iOiJ0ZXN0In0=", // stringified and base64 encoded bomContent | ||
| project: projectId, | ||
| projectName, | ||
| projectVersion, | ||
| projectTags: [{ name: projectTag }], | ||
| }; | ||
|
|
||
| await submitBom( | ||
| { | ||
| serverUrl, | ||
| projectId, | ||
| projectName, | ||
| projectVersion, | ||
| apiKey, | ||
| skipDtTlsCheck, | ||
| projectTag, | ||
| }, | ||
| bomContent, | ||
| ); | ||
|
|
||
| // Verify got was called exactly once | ||
| sinon.assert.calledOnce(gotStub); | ||
|
|
||
| // Grab call arguments | ||
| const [calledUrl, options] = gotStub.firstCall.args; | ||
|
|
||
| assert.equal(calledUrl, `${serverUrl}/api/v1/bom`); | ||
| assert.equal(options.method, "PUT"); | ||
| assert.equal(options.https.rejectUnauthorized, !skipDtTlsCheck); | ||
| assert.equal(options.headers["X-Api-Key"], apiKey); | ||
| assert.match(options.headers["user-agent"], /@CycloneDX\/cdxgen/); | ||
| assert.deepEqual(options.json, expectedRequestPayload); | ||
| }); | ||
|
|
||
| it("should successfully report the SBOM with given parent project, name, version and multiple tags", async () => { | ||
| const fakeGotResponse = { | ||
| json: sinon.stub().resolves({ success: true }), | ||
| }; | ||
|
|
||
| const gotStub = sinon.stub().returns(fakeGotResponse); | ||
| gotStub.extend = sinon.stub().returns(gotStub); | ||
|
|
||
| const { submitBom } = await esmock("./index.js", { | ||
| got: { default: gotStub }, | ||
| }); | ||
|
|
||
| const serverUrl = "https://dtrack.example.com"; | ||
| const projectName = "cdxgen-test-project"; | ||
| const projectVersion = "1.1.0"; | ||
| const projectTags = ["tag1", "tag2"]; | ||
| const parentProjectId = "5103b8b4-4ca3-46ea-8051-036a3b2ab17e"; | ||
| const bomContent = { | ||
| bom: "test2", | ||
| }; | ||
| const apiKey = "TEST_API_KEY"; | ||
| const skipDtTlsCheck = false; | ||
|
|
||
| const expectedRequestPayload = { | ||
| autoCreate: "true", | ||
| bom: "eyJib20iOiJ0ZXN0MiJ9", // stringified and base64 encoded bomContent | ||
| parentUUID: parentProjectId, | ||
| projectName, | ||
| projectVersion, | ||
| projectTags: [{ name: projectTags[0] }, { name: projectTags[1] }], | ||
| }; | ||
|
|
||
| await submitBom( | ||
| { | ||
| serverUrl, | ||
| parentProjectId, | ||
| projectName, | ||
| projectVersion, | ||
| apiKey, | ||
| skipDtTlsCheck, | ||
| projectTag: projectTags, | ||
| }, | ||
| bomContent, | ||
| ); | ||
|
|
||
| // Verify got was called exactly once | ||
| sinon.assert.calledOnce(gotStub); | ||
|
|
||
| // Grab call arguments | ||
| const [calledUrl, options] = gotStub.firstCall.args; | ||
|
|
||
| // Assert call arguments against expectations | ||
| assert.equal(calledUrl, `${serverUrl}/api/v1/bom`); | ||
| assert.equal(options.method, "PUT"); | ||
| assert.equal(options.https.rejectUnauthorized, !skipDtTlsCheck); | ||
| assert.equal(options.headers["X-Api-Key"], apiKey); | ||
| assert.match(options.headers["user-agent"], /@CycloneDX\/cdxgen/); | ||
| assert.deepEqual(options.json, expectedRequestPayload); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.