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
File renamed without changes.
44 changes: 44 additions & 0 deletions test/plugins/nodesecure.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Import Node.js Dependencies
import { after, describe, it } from "node:test";
import assert from "node:assert";

// Import Third-party Dependencies
import { MockAgent, setGlobalDispatcher } from "undici";

// Import Internal Dependencies
import { execute } from "../../src/plugins/nodesecure";

const kApiUrl = "https://api.securityscorecards.dev";

describe("execute()", async() => {
const mockAgent = new MockAgent();
mockAgent.disableNetConnect();

const mockPool = mockAgent.get(kApiUrl);

setGlobalDispatcher(mockAgent);

after(async() => {
await mockAgent.close();
});

it("should not add plugin", async() => {
mockPool.intercept({ path: "/projects/github.com/NodeSecure/ossf-scorecard-sdk" }).reply(404).times(1);

const repo: any = { name: "ossf-scorecard-sdk", plugins: {}, package_name: null };

await execute("NodeSecure", repo);
assert.equal(repo.package_name, null);
});

it("should add plugin", async() => {
mockPool.intercept({ path: "/projects/github.com/NodeSecure/ossf-scorecard-sdk" }).reply(200, { foo: "bar" }, {
headers: { "Content-Type": "application/json" }
}).times(1);

const repo: any = { name: "cli", plugins: {}, package_name: "@nodesecure/cli" };

await execute("NodeSecure", repo);
assert.equal(repo.plugins.nodesecure.foo, "bar");
});
});
46 changes: 46 additions & 0 deletions test/plugins/scorecard.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Import Node.js Dependencies
import { after, describe, it } from "node:test";
import assert from "node:assert";

// Import Third-party Dependencies
import { MockAgent, setGlobalDispatcher } from "undici";

// Import Internal Dependencies
import { execute } from "../../src/plugins/scorecard";

const kApiUrl = "https://api.securityscorecards.dev";

describe("execute()", async() => {
const mockAgent = new MockAgent();
mockAgent.disableNetConnect();

const mockPool = mockAgent.get(kApiUrl);

setGlobalDispatcher(mockAgent);

after(async() => {
await mockAgent.close();
});

it("should fetch scorecard", async() => {
mockPool.intercept({ path: "/projects/github.com/NodeSecure/ossf-scorecard-sdk" }).reply(200, { foo: "bar" }, {
headers: { "Content-Type": "application/json" }
}).times(1);

const repo: any = { name: "ossf-scorecard-sdk", plugins: {} };

await execute("NodeSecure", repo);
assert.equal(repo.plugins.scorecard.foo, "bar");
});

it("should return null", async() => {
mockPool.intercept({ path: "/projects/github.com/NodeSecure/cli" }).reply(404).times(1);

const repo: any = { name: "cli", plugins: {} };

await execute("NodeSecure", repo);
assert.equal(repo.plugins.scorecard, null);
});
});