Skip to content
This repository was archived by the owner on Dec 25, 2025. It is now read-only.
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
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,10 @@
"@openally/config.eslint": "^1.0.0",
"@openally/config.typescript": "^1.0.3",
"@types/lodash.set": "^4.3.9",
"@types/mock-fs": "^4.13.4",
"@types/node": "^22.3.0",
"@types/pluralize": "^0.0.33",
"@types/sade": "^1.7.8",
"glob": "^11.0.0",
"mock-fs": "^5.2.0",
"rimraf": "^6.0.1",
"tsx": "^4.17.0",
"typescript": "^5.0.4"
Expand Down
40 changes: 10 additions & 30 deletions src/configuration/external/nodesecure/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
// Import Node.js Dependencies
import assert from "node:assert";
import { describe, it } from "node:test";

// Third-party Dependencies
import mock from "mock-fs";
import fs from "node:fs/promises";

// Internal Dependencies
import { IgnorePatterns, IgnoreWarningsPatterns } from "./ignore-file.js";

import { getIgnoreFile, kIgnoreFilePath } from "./index.js";
import { getIgnoreFile } from "./index.js";

describe("getIgnoreFile", () => {
const kDefaultIgnoreFileContent = IgnorePatterns.default();
Expand All @@ -19,70 +16,53 @@ describe("getIgnoreFile", () => {
assert.deepEqual(result, kDefaultIgnoreFileContent);
});

it("should return empty object if file format is invalid", async() => {
it("should return empty object if file format is invalid", async(ctx) => {
const invalidIgnoreFile = { foo: "bar" };
createFakeIgnoreFile(JSON.stringify(invalidIgnoreFile));
ctx.mock.method(fs, "readFile", () => Promise.resolve(JSON.stringify(invalidIgnoreFile)));

const result = await getIgnoreFile();

assert.deepEqual(result, kDefaultIgnoreFileContent);
mock.restore();
});

it("should return the ignore file if it's valid", async() => {
it("should return the ignore file if it's valid", async(ctx) => {
const validIgnoreFile = {
warnings: {
"unsafe-regex": ["negotiator"]
}
};
createFakeIgnoreFile(JSON.stringify(validIgnoreFile));
ctx.mock.method(fs, "readFile", () => Promise.resolve(JSON.stringify(validIgnoreFile)));

const result = await getIgnoreFile();

assert.ok(result instanceof IgnorePatterns);
assert.notDeepEqual(result, {});
mock.restore();
});

it("should return an IgnorePatterns warnings property", async() => {
it("should return an IgnorePatterns warnings property", async(ctx) => {
const validIgnoreFile = {
warnings: {
"unsafe-regex": ["negotiator"]
}
};
createFakeIgnoreFile(JSON.stringify(validIgnoreFile));
ctx.mock.method(fs, "readFile", () => Promise.resolve(JSON.stringify(validIgnoreFile)));

const { warnings } = await getIgnoreFile();

assert.ok(warnings instanceof IgnoreWarningsPatterns);
mock.restore();
});

it("should return an helper to check if a warning exist for a given pkg", async() => {
it("should return an helper to check if a warning exist for a given pkg", async(ctx) => {
const validIgnoreFile = {
warnings: {
"unsafe-regex": ["negotiator"]
}
};
createFakeIgnoreFile(JSON.stringify(validIgnoreFile));
ctx.mock.method(fs, "readFile", () => Promise.resolve(JSON.stringify(validIgnoreFile)));

const result = await getIgnoreFile();

assert.equal(result.warnings.has("unsafe-regex", "negotiator"), true);
assert.equal(result.warnings.has("unsafe-regex", "express"), false);
mock.restore();
});
});

/**
* HELPERS
*/

function createFakeIgnoreFile(fileContent: string): void {
mock(
{
[kIgnoreFilePath]: Buffer.from(fileContent)
},
{} as any
);
}
4 changes: 2 additions & 2 deletions src/configuration/external/nodesecure/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Node.Js Dependencies
import { readFile } from "fs/promises";
import fs from "fs/promises";
import { join } from "path";

// Import Third-party Dependencies
Expand Down Expand Up @@ -93,7 +93,7 @@ export async function getNodeSecureConfig(): Promise<
export async function getIgnoreFile(): Promise<IgnorePatterns> {
const highlightedFilename = log.highlight(".nodesecureignore").message;
try {
const ignoreFile = await readFile(kIgnoreFilePath, "utf8");
const ignoreFile = await fs.readFile(kIgnoreFilePath, "utf8");
const ignoreObject = JSON.parse(ignoreFile);
const { isValid, error } = validateIgnoreFile(ignoreObject);
if (!isValid) {
Expand Down
Loading