-
-
Couldn't load subscription status.
- Fork 217
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
base: master
Are you sure you want to change the base?
Changes from all commits
d3afc75
89c2627
ee85a6f
068be9a
c3fc454
10c6f7c
9777208
ef52e56
a99782e
d6e797e
df3d26b
09a2613
24b69ca
e58f46d
a4efbe0
a0661b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| import { afterEach, assert, beforeEach, describe, it } from "poku"; | ||
| import quibble from "quibble"; | ||
| import sinon from "sinon"; | ||
|
|
||
| describe("CLI tests", () => { | ||
| describe("submitBom()", () => { | ||
| let gotStub; | ||
| let submitBom; | ||
|
|
||
| beforeEach(async () => { | ||
| // Create a sinon stub that mimics got() | ||
| const fakeGotResponse = { | ||
| json: sinon.stub().resolves({ success: true }), | ||
| }; | ||
|
|
||
| gotStub = sinon.stub().returns(fakeGotResponse); | ||
|
|
||
| // Attach extend to the function itself | ||
| gotStub.extend = sinon.stub().returns(gotStub); | ||
|
|
||
| // Replace the real 'got' module with our stub | ||
| await quibble.esm("got", { | ||
| default: gotStub, | ||
| }); | ||
|
|
||
| // Import the module under test AFTER quibble | ||
| ({ submitBom } = await import(`./index.js?update=${Date.now()}`)); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| await quibble.reset(); | ||
| sinon.reset(); | ||
| }); | ||
|
|
||
| it("should successfully report the SBOM with given project id, name, version and a single tag", async () => { | ||
| 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 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); | ||
| }); | ||
|
|
||
| it("should successfully report the SBOM with given parent project, name, version and multiple single tags", async () => { | ||
| const serverUrl = "https://dtrack.example.com"; | ||
| const projectName = "cdxgen-test-project"; | ||
| const projectVersion = "1.0.0"; | ||
| const projectTag = "tag1"; | ||
|
Comment on lines
+84
to
+88
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're doing such an awesome job, that I hate to bring this up: isn't this just a copy of the above test except now it has a parent set? I'm asking because the test-description says 'multiple' (although it also says 'single'), so I figured this would test with multiple tags... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, test is not ready yet... I'm massively struggling with test stubs (from ESM modules [got]) , which seems not to reset correctly between tests or/and affecting each other concerning expecations (call count). I've "consultated" various info sources (yes, even GPT and co.) but unfortunately without success. I'll dive deeper into this next week when I have some free time. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please take your time. It will be super cool to have such advanced tests! |
||
| const parentProjectId = "f7cb9f02-8041-4991-9101-b01fa07a6522"; | ||
| const bomContent = { | ||
| bom: "test", | ||
| }; | ||
| const apiKey = "TEST_API_KEY"; | ||
| const skipDtTlsCheck = false; | ||
|
|
||
| const expectedRequestPayload = { | ||
| autoCreate: "true", | ||
| bom: "eyJib20iOiJ0ZXN0In0=", // stringified and base64 encoded bomContent | ||
| parentUUID: parentProjectId, | ||
| projectName, | ||
| projectVersion, | ||
| projectTags: [{ name: projectTag }], | ||
| }; | ||
|
|
||
| await submitBom( | ||
| { | ||
| serverUrl, | ||
| parentProjectId, | ||
| 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 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); | ||
| }); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -139,6 +139,9 @@ | |
| "@npmcli/package-json": "7.0.1", | ||
| "@npmcli/query": "4.0.1", | ||
| "@npmcli/redact": "3.2.2", | ||
| "@sinonjs/commons": "3.0.1", | ||
| "@sinonjs/fake-timers": "13.0.5", | ||
| "@sinonjs/samsam": "8.0.3", | ||
| "abbrev": "4.0.0", | ||
| "ajv": "8.17.1", | ||
| "ajv-formats": "3.0.1", | ||
|
|
@@ -191,11 +194,13 @@ | |
| "promise-all-reject-late": "1.0.1", | ||
| "promise-call-limit": "3.0.2", | ||
| "properties-reader": "2.3.0", | ||
| "quibble": "0.9.2", | ||
| "read-package-json-fast": "4.0.0", | ||
| "responselike": "4.0.2", | ||
| "semver": "7.7.3", | ||
| "sequelize": "6.37.7", | ||
| "signal-exit": "4.1.0", | ||
| "sinon": "21.0.0", | ||
| "sprintf-js": "1.1.3", | ||
| "sqlite3": "npm:@appthreat/[email protected]", | ||
| "ssri": "12.0.0", | ||
|
|
@@ -273,6 +278,8 @@ | |
| "devDependencies": { | ||
| "@biomejs/biome": "2.2.6", | ||
| "poku": "3.0.2", | ||
| "quibble": "0.9.2", | ||
| "sinon": "21.0.0", | ||
| "typescript": "5.9.3" | ||
| }, | ||
| "optionalDependencies": { | ||
|
|
@@ -335,6 +342,9 @@ | |
| "@npmcli/package-json": "7.0.1", | ||
| "@npmcli/query": "4.0.1", | ||
| "@npmcli/redact": "3.2.2", | ||
| "@sinonjs/commons": "3.0.1", | ||
| "@sinonjs/fake-timers": "13.0.5", | ||
| "@sinonjs/samsam": "8.0.3", | ||
| "abbrev": "4.0.0", | ||
| "ajv": "8.17.1", | ||
| "ajv-formats": "3.0.1", | ||
|
|
@@ -387,11 +397,13 @@ | |
| "promise-all-reject-late": "1.0.1", | ||
| "promise-call-limit": "3.0.2", | ||
| "properties-reader": "2.3.0", | ||
| "quibble": "0.9.2", | ||
| "read-package-json-fast": "4.0.0", | ||
| "responselike": "4.0.2", | ||
| "semver": "7.7.3", | ||
| "sequelize": "6.37.7", | ||
| "signal-exit": "4.1.0", | ||
| "sinon": "21.0.0", | ||
| "sprintf-js": "1.1.3", | ||
| "sqlite3": "npm:@appthreat/[email protected]", | ||
| "ssri": "12.0.0", | ||
|
|
@@ -437,5 +449,9 @@ | |
| "onFail": "ignore" | ||
| } | ||
| ] | ||
| }, | ||
| "volta": { | ||
| "node": "22.21.0", | ||
| "pnpm": "10.19.0" | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.