mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
chore: update test parametrization
This commit is contained in:
parent
c53a7347e2
commit
b23ba9d9c4
2 changed files with 54 additions and 32 deletions
|
|
@ -232,12 +232,22 @@ describe("getMinimumPackageAgeHours", async () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const packageManager of ["npm", "pip"]) {
|
const { getNpmCustomRegistries, getPipCustomRegistries } = await import(
|
||||||
const fnName = `get${packageManager.charAt(0).toUpperCase()}${packageManager.slice(1)}CustomRegistries`;
|
"./configFile.js"
|
||||||
|
);
|
||||||
describe(fnName, async () => {
|
|
||||||
const fn = (await import("./configFile.js"))[fnName];
|
|
||||||
|
|
||||||
|
for (const { packageManager, getCustomRegistries } of [
|
||||||
|
{
|
||||||
|
packageManager: "npm",
|
||||||
|
getCustomRegistries: getNpmCustomRegistries,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
packageManager: "pip",
|
||||||
|
getCustomRegistries: getPipCustomRegistries,
|
||||||
|
},
|
||||||
|
])
|
||||||
|
{
|
||||||
|
describe(getCustomRegistries.name, async () => {
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
configFileContent = undefined;
|
configFileContent = undefined;
|
||||||
});
|
});
|
||||||
|
|
@ -245,7 +255,7 @@ for (const packageManager of ["npm", "pip"]) {
|
||||||
it("should return empty array when config file doesn't exist", () => {
|
it("should return empty array when config file doesn't exist", () => {
|
||||||
configFileContent = undefined;
|
configFileContent = undefined;
|
||||||
|
|
||||||
const registries = fn();
|
const registries = getCustomRegistries();
|
||||||
|
|
||||||
assert.deepStrictEqual(registries, []);
|
assert.deepStrictEqual(registries, []);
|
||||||
});
|
});
|
||||||
|
|
@ -253,7 +263,7 @@ for (const packageManager of ["npm", "pip"]) {
|
||||||
it(`should return empty array when ${packageManager} config is not set`, () => {
|
it(`should return empty array when ${packageManager} config is not set`, () => {
|
||||||
configFileContent = JSON.stringify({ scanTimeout: 5000 });
|
configFileContent = JSON.stringify({ scanTimeout: 5000 });
|
||||||
|
|
||||||
const registries = fn();
|
const registries = getCustomRegistries();
|
||||||
|
|
||||||
assert.deepStrictEqual(registries, []);
|
assert.deepStrictEqual(registries, []);
|
||||||
});
|
});
|
||||||
|
|
@ -263,7 +273,7 @@ for (const packageManager of ["npm", "pip"]) {
|
||||||
[packageManager]: { customRegistries: "not-an-array" },
|
[packageManager]: { customRegistries: "not-an-array" },
|
||||||
});
|
});
|
||||||
|
|
||||||
const registries = fn();
|
const registries = getCustomRegistries();
|
||||||
|
|
||||||
assert.deepStrictEqual(registries, []);
|
assert.deepStrictEqual(registries, []);
|
||||||
});
|
});
|
||||||
|
|
@ -275,7 +285,7 @@ for (const packageManager of ["npm", "pip"]) {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const registries = fn();
|
const registries = getCustomRegistries();
|
||||||
|
|
||||||
assert.deepStrictEqual(registries, [
|
assert.deepStrictEqual(registries, [
|
||||||
`${packageManager}.company.com`,
|
`${packageManager}.company.com`,
|
||||||
|
|
@ -297,7 +307,7 @@ for (const packageManager of ["npm", "pip"]) {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const registries = fn();
|
const registries = getCustomRegistries();
|
||||||
|
|
||||||
assert.deepStrictEqual(registries, [
|
assert.deepStrictEqual(registries, [
|
||||||
`${packageManager}.company.com`,
|
`${packageManager}.company.com`,
|
||||||
|
|
@ -310,7 +320,7 @@ for (const packageManager of ["npm", "pip"]) {
|
||||||
[packageManager]: { customRegistries: [] },
|
[packageManager]: { customRegistries: [] },
|
||||||
});
|
});
|
||||||
|
|
||||||
const registries = fn();
|
const registries = getCustomRegistries();
|
||||||
|
|
||||||
assert.deepStrictEqual(registries, []);
|
assert.deepStrictEqual(registries, []);
|
||||||
});
|
});
|
||||||
|
|
@ -318,7 +328,7 @@ for (const packageManager of ["npm", "pip"]) {
|
||||||
it("should handle malformed JSON and return empty array", () => {
|
it("should handle malformed JSON and return empty array", () => {
|
||||||
configFileContent = "{ invalid json";
|
configFileContent = "{ invalid json";
|
||||||
|
|
||||||
const registries = fn();
|
const registries = getCustomRegistries();
|
||||||
|
|
||||||
assert.deepStrictEqual(registries, []);
|
assert.deepStrictEqual(registries, []);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -11,13 +11,25 @@ mock.module("fs", {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const packageManager of ["npm", "pip"]) {
|
const { getNpmCustomRegistries, getPipCustomRegistries } = await import(
|
||||||
const fnName = `get${packageManager.charAt(0).toUpperCase()}${packageManager.slice(1)}CustomRegistries`;
|
"./settings.js"
|
||||||
const envVarName = `SAFE_CHAIN_${packageManager.toUpperCase()}_CUSTOM_REGISTRIES`;
|
);
|
||||||
|
|
||||||
describe(fnName, async () => {
|
for (const { packageManager, getCustomRegistries, envVarName } of [
|
||||||
|
{
|
||||||
|
packageManager: "npm",
|
||||||
|
getCustomRegistries: getNpmCustomRegistries,
|
||||||
|
envVarName: "SAFE_CHAIN_NPM_CUSTOM_REGISTRIES",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
packageManager: "pip",
|
||||||
|
getCustomRegistries: getPipCustomRegistries,
|
||||||
|
envVarName: "SAFE_CHAIN_PIP_CUSTOM_REGISTRIES",
|
||||||
|
},
|
||||||
|
])
|
||||||
|
{
|
||||||
|
describe(getCustomRegistries.name, async () => {
|
||||||
let originalEnv;
|
let originalEnv;
|
||||||
const fn = (await import("./settings.js"))[fnName];
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
originalEnv = process.env[envVarName];
|
originalEnv = process.env[envVarName];
|
||||||
|
|
@ -35,7 +47,7 @@ for (const packageManager of ["npm", "pip"]) {
|
||||||
it("should return empty array when no registries configured", () => {
|
it("should return empty array when no registries configured", () => {
|
||||||
configFileContent = undefined;
|
configFileContent = undefined;
|
||||||
|
|
||||||
const registries = fn();
|
const registries = getCustomRegistries();
|
||||||
|
|
||||||
assert.deepStrictEqual(registries, []);
|
assert.deepStrictEqual(registries, []);
|
||||||
});
|
});
|
||||||
|
|
@ -47,7 +59,7 @@ for (const packageManager of ["npm", "pip"]) {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const registries = fn();
|
const registries = getCustomRegistries();
|
||||||
|
|
||||||
assert.deepStrictEqual(registries, [
|
assert.deepStrictEqual(registries, [
|
||||||
`${packageManager}.company.com`,
|
`${packageManager}.company.com`,
|
||||||
|
|
@ -65,7 +77,7 @@ for (const packageManager of ["npm", "pip"]) {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const registries = fn();
|
const registries = getCustomRegistries();
|
||||||
|
|
||||||
assert.deepStrictEqual(registries, [
|
assert.deepStrictEqual(registries, [
|
||||||
`${packageManager}.company.com`,
|
`${packageManager}.company.com`,
|
||||||
|
|
@ -83,7 +95,7 @@ for (const packageManager of ["npm", "pip"]) {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const registries = fn();
|
const registries = getCustomRegistries();
|
||||||
|
|
||||||
assert.deepStrictEqual(registries, [
|
assert.deepStrictEqual(registries, [
|
||||||
`${packageManager}.company.com`,
|
`${packageManager}.company.com`,
|
||||||
|
|
@ -102,7 +114,7 @@ for (const packageManager of ["npm", "pip"]) {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const registries = fn();
|
const registries = getCustomRegistries();
|
||||||
|
|
||||||
assert.deepStrictEqual(registries, [
|
assert.deepStrictEqual(registries, [
|
||||||
`${packageManager}.company.com`,
|
`${packageManager}.company.com`,
|
||||||
|
|
@ -121,7 +133,7 @@ for (const packageManager of ["npm", "pip"]) {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const registries = fn();
|
const registries = getCustomRegistries();
|
||||||
|
|
||||||
assert.deepStrictEqual(registries, [
|
assert.deepStrictEqual(registries, [
|
||||||
`${packageManager}.company.com/custom/path`,
|
`${packageManager}.company.com/custom/path`,
|
||||||
|
|
@ -135,7 +147,7 @@ for (const packageManager of ["npm", "pip"]) {
|
||||||
"env1.registry.com,env2.registry.net";
|
"env1.registry.com,env2.registry.net";
|
||||||
configFileContent = undefined;
|
configFileContent = undefined;
|
||||||
|
|
||||||
const registries = fn();
|
const registries = getCustomRegistries();
|
||||||
|
|
||||||
assert.deepStrictEqual(registries, [
|
assert.deepStrictEqual(registries, [
|
||||||
"env1.registry.com",
|
"env1.registry.com",
|
||||||
|
|
@ -149,7 +161,7 @@ for (const packageManager of ["npm", "pip"]) {
|
||||||
" env1.registry.com , env2.registry.net ";
|
" env1.registry.com , env2.registry.net ";
|
||||||
configFileContent = undefined;
|
configFileContent = undefined;
|
||||||
|
|
||||||
const registries = fn();
|
const registries = getCustomRegistries();
|
||||||
|
|
||||||
assert.deepStrictEqual(registries, [
|
assert.deepStrictEqual(registries, [
|
||||||
"env1.registry.com",
|
"env1.registry.com",
|
||||||
|
|
@ -166,7 +178,7 @@ for (const packageManager of ["npm", "pip"]) {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const registries = fn();
|
const registries = getCustomRegistries();
|
||||||
|
|
||||||
assert.deepStrictEqual(registries, [
|
assert.deepStrictEqual(registries, [
|
||||||
"env1.registry.com",
|
"env1.registry.com",
|
||||||
|
|
@ -184,7 +196,7 @@ for (const packageManager of ["npm", "pip"]) {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const registries = fn();
|
const registries = getCustomRegistries();
|
||||||
|
|
||||||
assert.deepStrictEqual(registries, [
|
assert.deepStrictEqual(registries, [
|
||||||
`${packageManager}.company.com`,
|
`${packageManager}.company.com`,
|
||||||
|
|
@ -199,7 +211,7 @@ for (const packageManager of ["npm", "pip"]) {
|
||||||
"https://env1.registry.com,http://env2.registry.net";
|
"https://env1.registry.com,http://env2.registry.net";
|
||||||
configFileContent = undefined;
|
configFileContent = undefined;
|
||||||
|
|
||||||
const registries = fn();
|
const registries = getCustomRegistries();
|
||||||
|
|
||||||
assert.deepStrictEqual(registries, [
|
assert.deepStrictEqual(registries, [
|
||||||
"env1.registry.com",
|
"env1.registry.com",
|
||||||
|
|
@ -213,7 +225,7 @@ for (const packageManager of ["npm", "pip"]) {
|
||||||
"env1.registry.com,,env2.registry.net,";
|
"env1.registry.com,,env2.registry.net,";
|
||||||
configFileContent = undefined;
|
configFileContent = undefined;
|
||||||
|
|
||||||
const registries = fn();
|
const registries = getCustomRegistries();
|
||||||
|
|
||||||
assert.deepStrictEqual(registries, [
|
assert.deepStrictEqual(registries, [
|
||||||
"env1.registry.com",
|
"env1.registry.com",
|
||||||
|
|
@ -226,7 +238,7 @@ for (const packageManager of ["npm", "pip"]) {
|
||||||
process.env[envVarName] = "single.registry.com";
|
process.env[envVarName] = "single.registry.com";
|
||||||
configFileContent = undefined;
|
configFileContent = undefined;
|
||||||
|
|
||||||
const registries = fn();
|
const registries = getCustomRegistries();
|
||||||
|
|
||||||
assert.deepStrictEqual(registries, ["single.registry.com"]);
|
assert.deepStrictEqual(registries, ["single.registry.com"]);
|
||||||
});
|
});
|
||||||
|
|
@ -236,7 +248,7 @@ for (const packageManager of ["npm", "pip"]) {
|
||||||
process.env[envVarName] = "";
|
process.env[envVarName] = "";
|
||||||
configFileContent = undefined;
|
configFileContent = undefined;
|
||||||
|
|
||||||
const registries = fn();
|
const registries = getCustomRegistries();
|
||||||
|
|
||||||
assert.deepStrictEqual(registries, []);
|
assert.deepStrictEqual(registries, []);
|
||||||
});
|
});
|
||||||
|
|
@ -246,7 +258,7 @@ for (const packageManager of ["npm", "pip"]) {
|
||||||
process.env[envVarName] = " , , ";
|
process.env[envVarName] = " , , ";
|
||||||
configFileContent = undefined;
|
configFileContent = undefined;
|
||||||
|
|
||||||
const registries = fn();
|
const registries = getCustomRegistries();
|
||||||
|
|
||||||
assert.deepStrictEqual(registries, []);
|
assert.deepStrictEqual(registries, []);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue