Remove --safe-chain-malware-action flag

This commit is contained in:
Sander Declerck 2025-10-27 11:51:19 +01:00
parent 95d9cefcc9
commit ab3319a310
No known key found for this signature in database
6 changed files with 8 additions and 188 deletions

View file

@ -1,5 +1,4 @@
const state = {
malwareAction: undefined,
loggingLevel: undefined,
};
@ -7,7 +6,6 @@ const SAFE_CHAIN_ARG_PREFIX = "--safe-chain-";
export function initializeCliArguments(args) {
// Reset state on each call
state.malwareAction = undefined;
state.loggingLevel = undefined;
const safeChainArgs = [];
@ -21,22 +19,11 @@ export function initializeCliArguments(args) {
}
}
setMalwareAction(safeChainArgs);
setLoggingLevel(safeChainArgs);
return remainingArgs;
}
function setMalwareAction(args) {
const safeChainMalwareActionArg = SAFE_CHAIN_ARG_PREFIX + "malware-action=";
const action = getLastArgEqualsValue(args, safeChainMalwareActionArg);
if (!action) {
return;
}
state.malwareAction = action.toLowerCase();
}
function getLastArgEqualsValue(args, prefix) {
for (var i = args.length - 1; i >= 0; i--) {
const arg = args[i];
@ -48,10 +35,6 @@ function getLastArgEqualsValue(args, prefix) {
return undefined;
}
export function getMalwareAction() {
return state.malwareAction;
}
function setLoggingLevel(args) {
const safeChainLoggingArg = SAFE_CHAIN_ARG_PREFIX + "logging=";

View file

@ -1,10 +1,6 @@
import { describe, it } from "node:test";
import assert from "node:assert";
import {
initializeCliArguments,
getMalwareAction,
getLoggingLevel,
} from "./cliArguments.js";
import { initializeCliArguments, getLoggingLevel } from "./cliArguments.js";
describe("initializeCliArguments", () => {
it("should return all args when no safe-chain args are present", () => {
@ -61,55 +57,6 @@ describe("initializeCliArguments", () => {
assert.deepEqual(result, ["install", "my--safe-chain-package", "--save"]);
});
it("should not set malwareAction when no safe-chain arguments are passed", () => {
const args = ["install", "express", "--save"];
const result = initializeCliArguments(args);
assert.deepEqual(result, ["install", "express", "--save"]);
assert.strictEqual(getMalwareAction(), undefined);
});
it("should parse malware-action=block and set state", () => {
const args = ["--safe-chain-malware-action=block", "install", "package"];
const result = initializeCliArguments(args);
assert.deepEqual(result, ["install", "package"]);
assert.strictEqual(getMalwareAction(), "block");
});
it("should parse malware-action=prompt and set state", () => {
const args = ["--safe-chain-malware-action=prompt", "install", "package"];
const result = initializeCliArguments(args);
assert.deepEqual(result, ["install", "package"]);
assert.strictEqual(getMalwareAction(), "prompt");
});
it("should handle multiple malware-action args, using the last valid one", () => {
const args = [
"--safe-chain-malware-action=block",
"--safe-chain-malware-action=prompt",
"install",
];
const result = initializeCliArguments(args);
assert.deepEqual(result, ["install"]);
assert.strictEqual(getMalwareAction(), "prompt");
});
it("should handle malware-action with other safe-chain args", () => {
const args = [
"--safe-chain-debug",
"--safe-chain-malware-action=block",
"--safe-chain-verbose",
"install",
];
const result = initializeCliArguments(args);
assert.deepEqual(result, ["install"]);
assert.strictEqual(getMalwareAction(), "block");
});
it("should not set loggingLevel when no logging argument is passed", () => {
const args = ["install", "express", "--save"];
initializeCliArguments(args);
@ -170,6 +117,5 @@ describe("initializeCliArguments", () => {
assert.deepEqual(result, ["install"]);
assert.strictEqual(getLoggingLevel(), "silent");
assert.strictEqual(getMalwareAction(), "block");
});
});

View file

@ -1,15 +1,5 @@
import * as cliArguments from "./cliArguments.js";
export function getMalwareAction() {
const action = cliArguments.getMalwareAction();
if (action === MALWARE_ACTION_PROMPT) {
return MALWARE_ACTION_PROMPT;
}
return MALWARE_ACTION_BLOCK;
}
export function getLoggingLevel() {
const level = cliArguments.getLoggingLevel();
@ -20,8 +10,5 @@ export function getLoggingLevel() {
return LOGGING_NORMAL;
}
export const MALWARE_ACTION_BLOCK = "block";
export const MALWARE_ACTION_PROMPT = "prompt";
export const LOGGING_SILENT = "silent";
export const LOGGING_NORMAL = "normal";