mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Some more cleanup
This commit is contained in:
parent
d064d46668
commit
031c9683b1
23 changed files with 55 additions and 864 deletions
|
|
@ -34,19 +34,13 @@ function teardown(tools) {
|
|||
);
|
||||
}
|
||||
|
||||
// Marker comment ensures only safe-chain-added lines are removed, not user's own source statements
|
||||
// Removes the line that sources the safe-chain bash initialization script.
|
||||
removeLinesMatchingPattern(
|
||||
startupFile,
|
||||
/^source\s+.*init-posix\.sh.*#\s*Safe-chain/,
|
||||
eol
|
||||
);
|
||||
|
||||
removeLinesMatchingPattern(
|
||||
startupFile,
|
||||
/^export\s+SAFE_CHAIN_DIR=.*#\s*Safe-chain/,
|
||||
eol
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -131,19 +125,20 @@ function cygpathw(path) {
|
|||
}
|
||||
}
|
||||
|
||||
/** @param {string} preamble */
|
||||
function buildManualInstructions(preamble) {
|
||||
const instructions = [preamble, ` source ${path.join(getScriptsDir(), "init-posix.sh")}`];
|
||||
instructions.push(`Then restart your terminal or run: source ~/.bashrc`);
|
||||
return instructions;
|
||||
}
|
||||
|
||||
function getManualTeardownInstructions() {
|
||||
return buildManualInstructions(`Remove the following line from your ~/.bashrc file:`);
|
||||
return [
|
||||
`Remove the following line from your ~/.bashrc file:`,
|
||||
` source ${path.join(getScriptsDir(), "init-posix.sh")}`,
|
||||
`Then restart your terminal or run: source ~/.bashrc`,
|
||||
];
|
||||
}
|
||||
|
||||
function getManualSetupInstructions() {
|
||||
return buildManualInstructions(`Add the following line to your ~/.bashrc file:`);
|
||||
return [
|
||||
`Add the following line to your ~/.bashrc file:`,
|
||||
` source ${path.join(getScriptsDir(), "init-posix.sh")}`,
|
||||
`Then restart your terminal or run: source ~/.bashrc`,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -200,40 +200,6 @@ describe("Bash shell integration", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("custom install dir", () => {
|
||||
it("writes only the source line to the rc file", () => {
|
||||
bash.setup();
|
||||
|
||||
const content = fs.readFileSync(mockStartupFile, "utf-8");
|
||||
assert.ok(
|
||||
content.includes("source /test-home/.safe-chain/scripts/init-posix.sh")
|
||||
);
|
||||
assert.ok(!content.includes("SAFE_CHAIN_DIR"));
|
||||
});
|
||||
|
||||
it("removes legacy export lines on teardown", () => {
|
||||
const initialContent = [
|
||||
'#!/bin/bash',
|
||||
'export SAFE_CHAIN_DIR="/custom/safe-chain" # Safe-chain installation directory',
|
||||
'source /test-home/.safe-chain/scripts/init-posix.sh # Safe-chain bash initialization script',
|
||||
].join("\n");
|
||||
|
||||
fs.writeFileSync(mockStartupFile, initialContent, "utf-8");
|
||||
|
||||
bash.teardown(knownAikidoTools);
|
||||
const content = fs.readFileSync(mockStartupFile, "utf-8");
|
||||
assert.ok(!content.includes("SAFE_CHAIN_DIR"));
|
||||
});
|
||||
|
||||
it("shows source-only manual setup instructions", () => {
|
||||
assert.deepStrictEqual(bash.getManualSetupInstructions(), [
|
||||
"Add the following line to your ~/.bashrc file:",
|
||||
" source /test-home/.safe-chain/scripts/init-posix.sh",
|
||||
"Then restart your terminal or run: source ~/.bashrc",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("integration tests", () => {
|
||||
it("should handle complete setup and teardown cycle", () => {
|
||||
const tools = [
|
||||
|
|
|
|||
|
|
@ -33,19 +33,13 @@ function teardown(tools) {
|
|||
);
|
||||
}
|
||||
|
||||
// Removes the line that sources the safe-chain fish initialization script (any path, requires safe-chain comment)
|
||||
// Removes the line that sources the safe-chain fish initialization script.
|
||||
removeLinesMatchingPattern(
|
||||
startupFile,
|
||||
/^source\s+.*init-fish\.fish.*#\s*Safe-chain/,
|
||||
eol
|
||||
);
|
||||
|
||||
removeLinesMatchingPattern(
|
||||
startupFile,
|
||||
/^set\s+-gx\s+SAFE_CHAIN_DIR\s+.*#\s*Safe-chain/,
|
||||
eol
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -74,21 +68,20 @@ function getStartupFile() {
|
|||
}
|
||||
}
|
||||
|
||||
/** @param {string} preamble */
|
||||
function buildManualInstructions(preamble) {
|
||||
const instructions = [preamble, ` source ${path.join(getScriptsDir(), "init-fish.fish")}`];
|
||||
instructions.push(
|
||||
`Then restart your terminal or run: source ~/.config/fish/config.fish`,
|
||||
);
|
||||
return instructions;
|
||||
}
|
||||
|
||||
function getManualTeardownInstructions() {
|
||||
return buildManualInstructions(`Remove the following line from your ~/.config/fish/config.fish file:`);
|
||||
return [
|
||||
`Remove the following line from your ~/.config/fish/config.fish file:`,
|
||||
` source ${path.join(getScriptsDir(), "init-fish.fish")}`,
|
||||
`Then restart your terminal or run: source ~/.config/fish/config.fish`,
|
||||
];
|
||||
}
|
||||
|
||||
function getManualSetupInstructions() {
|
||||
return buildManualInstructions(`Add the following line to your ~/.config/fish/config.fish file:`);
|
||||
return [
|
||||
`Add the following line to your ~/.config/fish/config.fish file:`,
|
||||
` source ${path.join(getScriptsDir(), "init-fish.fish")}`,
|
||||
`Then restart your terminal or run: source ~/.config/fish/config.fish`,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -153,39 +153,6 @@ describe("Fish shell integration", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("custom install dir", () => {
|
||||
it("writes only the source line to the config file", () => {
|
||||
fish.setup();
|
||||
|
||||
const content = fs.readFileSync(mockStartupFile, "utf-8");
|
||||
assert.ok(
|
||||
content.includes("source /test-home/.safe-chain/scripts/init-fish.fish")
|
||||
);
|
||||
assert.ok(!content.includes("SAFE_CHAIN_DIR"));
|
||||
});
|
||||
|
||||
it("removes legacy set lines on teardown", () => {
|
||||
const initialContent = [
|
||||
'set -gx SAFE_CHAIN_DIR "/custom/safe-chain" # Safe-chain installation directory',
|
||||
"source /test-home/.safe-chain/scripts/init-fish.fish # Safe-chain Fish initialization script",
|
||||
].join("\n");
|
||||
|
||||
fs.writeFileSync(mockStartupFile, initialContent, "utf-8");
|
||||
|
||||
fish.teardown(knownAikidoTools);
|
||||
const content = fs.readFileSync(mockStartupFile, "utf-8");
|
||||
assert.ok(!content.includes("SAFE_CHAIN_DIR"));
|
||||
});
|
||||
|
||||
it("shows source-only manual setup instructions", () => {
|
||||
assert.deepStrictEqual(fish.getManualSetupInstructions(), [
|
||||
"Add the following line to your ~/.config/fish/config.fish file:",
|
||||
" source /test-home/.safe-chain/scripts/init-fish.fish",
|
||||
"Then restart your terminal or run: source ~/.config/fish/config.fish",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("integration tests", () => {
|
||||
it("should handle complete setup and teardown cycle", () => {
|
||||
const tools = [
|
||||
|
|
|
|||
|
|
@ -32,17 +32,12 @@ function teardown(tools) {
|
|||
);
|
||||
}
|
||||
|
||||
// Remove the line that sources the safe-chain PowerShell initialization script (any path, requires safe-chain comment)
|
||||
// Removes the line that sources the safe-chain PowerShell initialization script.
|
||||
removeLinesMatchingPattern(
|
||||
startupFile,
|
||||
/^\.\s+["']?.*init-pwsh\.ps1["']?.*#\s*Safe-chain/,
|
||||
);
|
||||
|
||||
removeLinesMatchingPattern(
|
||||
startupFile,
|
||||
/^\$env:SAFE_CHAIN_DIR\s*=.*#\s*Safe-chain/,
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -78,19 +73,20 @@ function getStartupFile() {
|
|||
}
|
||||
}
|
||||
|
||||
/** @param {string} preamble */
|
||||
function buildManualInstructions(preamble) {
|
||||
const instructions = [preamble, ` . "${path.join(getScriptsDir(), "init-pwsh.ps1")}"`];
|
||||
instructions.push(`Then restart your terminal or run: . $PROFILE`);
|
||||
return instructions;
|
||||
}
|
||||
|
||||
function getManualTeardownInstructions() {
|
||||
return buildManualInstructions(`Remove the following line from your PowerShell profile (run "echo $PROFILE" to find its location):`);
|
||||
return [
|
||||
`Remove the following line from your PowerShell profile (run "echo $PROFILE" to find its location):`,
|
||||
` . "${path.join(getScriptsDir(), "init-pwsh.ps1")}"`,
|
||||
`Then restart your terminal or run: . $PROFILE`,
|
||||
];
|
||||
}
|
||||
|
||||
function getManualSetupInstructions() {
|
||||
return buildManualInstructions(`Add the following line to your PowerShell profile (run "echo $PROFILE" to find its location):`);
|
||||
return [
|
||||
`Add the following line to your PowerShell profile (run "echo $PROFILE" to find its location):`,
|
||||
` . "${path.join(getScriptsDir(), "init-pwsh.ps1")}"`,
|
||||
`Then restart your terminal or run: . $PROFILE`,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -206,40 +206,6 @@ describe("PowerShell Core shell integration", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("custom install dir", () => {
|
||||
it("writes only the source line to the profile", async () => {
|
||||
await powershell.setup();
|
||||
|
||||
const content = fs.readFileSync(mockStartupFile, "utf-8");
|
||||
assert.ok(
|
||||
content.includes('. "/test-home/.safe-chain/scripts/init-pwsh.ps1"')
|
||||
);
|
||||
assert.ok(!content.includes("SAFE_CHAIN_DIR"));
|
||||
});
|
||||
|
||||
it("removes legacy env lines on teardown", () => {
|
||||
const initialContent = [
|
||||
"# PowerShell profile",
|
||||
"$env:SAFE_CHAIN_DIR = 'C:\\custom\\safe-chain' # Safe-chain installation directory",
|
||||
'. "/test-home/.safe-chain/scripts/init-pwsh.ps1" # Safe-chain PowerShell initialization script',
|
||||
].join("\n");
|
||||
|
||||
fs.writeFileSync(mockStartupFile, initialContent, "utf-8");
|
||||
|
||||
powershell.teardown(knownAikidoTools);
|
||||
const content = fs.readFileSync(mockStartupFile, "utf-8");
|
||||
assert.ok(!content.includes("SAFE_CHAIN_DIR"));
|
||||
});
|
||||
|
||||
it("shows source-only manual setup instructions", () => {
|
||||
assert.deepStrictEqual(powershell.getManualSetupInstructions(), [
|
||||
'Add the following line to your PowerShell profile (run "echo $PROFILE" to find its location):',
|
||||
' . "/test-home/.safe-chain/scripts/init-pwsh.ps1"',
|
||||
"Then restart your terminal or run: . $PROFILE",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("execution policy", () => {
|
||||
it(`should throw for restricted policies`, async () => {
|
||||
executionPolicyResult = {
|
||||
|
|
|
|||
|
|
@ -32,17 +32,12 @@ function teardown(tools) {
|
|||
);
|
||||
}
|
||||
|
||||
// Match any installation path but require the Safe-chain marker to avoid removing unrelated user scripts
|
||||
// Removes the line that sources the safe-chain PowerShell initialization script.
|
||||
removeLinesMatchingPattern(
|
||||
startupFile,
|
||||
/^\.\s+["']?.*init-pwsh\.ps1["']?.*#\s*Safe-chain/,
|
||||
);
|
||||
|
||||
removeLinesMatchingPattern(
|
||||
startupFile,
|
||||
/^\$env:SAFE_CHAIN_DIR\s*=.*#\s*Safe-chain/,
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -78,19 +73,20 @@ function getStartupFile() {
|
|||
}
|
||||
}
|
||||
|
||||
/** @param {string} preamble */
|
||||
function buildManualInstructions(preamble) {
|
||||
const instructions = [preamble, ` . "${path.join(getScriptsDir(), "init-pwsh.ps1")}"`];
|
||||
instructions.push(`Then restart your terminal or run: . $PROFILE`);
|
||||
return instructions;
|
||||
}
|
||||
|
||||
function getManualTeardownInstructions() {
|
||||
return buildManualInstructions(`Remove the following line from your PowerShell profile (run "echo $PROFILE" to find its location):`);
|
||||
return [
|
||||
`Remove the following line from your PowerShell profile (run "echo $PROFILE" to find its location):`,
|
||||
` . "${path.join(getScriptsDir(), "init-pwsh.ps1")}"`,
|
||||
`Then restart your terminal or run: . $PROFILE`,
|
||||
];
|
||||
}
|
||||
|
||||
function getManualSetupInstructions() {
|
||||
return buildManualInstructions(`Add the following line to your PowerShell profile (run "echo $PROFILE" to find its location):`);
|
||||
return [
|
||||
`Add the following line to your PowerShell profile (run "echo $PROFILE" to find its location):`,
|
||||
` . "${path.join(getScriptsDir(), "init-pwsh.ps1")}"`,
|
||||
`Then restart your terminal or run: . $PROFILE`,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -206,40 +206,6 @@ describe("Windows PowerShell shell integration", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("custom install dir", () => {
|
||||
it("writes only the source line to the profile", async () => {
|
||||
await windowsPowershell.setup();
|
||||
|
||||
const content = fs.readFileSync(mockStartupFile, "utf-8");
|
||||
assert.ok(
|
||||
content.includes('. "/test-home/.safe-chain/scripts/init-pwsh.ps1"')
|
||||
);
|
||||
assert.ok(!content.includes("SAFE_CHAIN_DIR"));
|
||||
});
|
||||
|
||||
it("removes legacy env lines on teardown", () => {
|
||||
const initialContent = [
|
||||
"# Windows PowerShell profile",
|
||||
"$env:SAFE_CHAIN_DIR = 'C:\\custom\\safe-chain' # Safe-chain installation directory",
|
||||
'. "/test-home/.safe-chain/scripts/init-pwsh.ps1" # Safe-chain PowerShell initialization script',
|
||||
].join("\n");
|
||||
|
||||
fs.writeFileSync(mockStartupFile, initialContent, "utf-8");
|
||||
|
||||
windowsPowershell.teardown(knownAikidoTools);
|
||||
const content = fs.readFileSync(mockStartupFile, "utf-8");
|
||||
assert.ok(!content.includes("SAFE_CHAIN_DIR"));
|
||||
});
|
||||
|
||||
it("shows source-only manual teardown instructions", () => {
|
||||
assert.deepStrictEqual(windowsPowershell.getManualTeardownInstructions(), [
|
||||
'Remove the following line from your PowerShell profile (run "echo $PROFILE" to find its location):',
|
||||
' . "/test-home/.safe-chain/scripts/init-pwsh.ps1"',
|
||||
"Then restart your terminal or run: . $PROFILE",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("execution policy", () => {
|
||||
it(`should throw for restricted policies`, async () => {
|
||||
executionPolicyResult = {
|
||||
|
|
|
|||
|
|
@ -33,19 +33,13 @@ function teardown(tools) {
|
|||
);
|
||||
}
|
||||
|
||||
// Remove init script source line to uninstall shell integration; marker ensures only safe-chain-added lines are removed
|
||||
// Removes the line that sources the safe-chain zsh initialization script.
|
||||
removeLinesMatchingPattern(
|
||||
startupFile,
|
||||
/^source\s+.*init-posix\.sh.*#\s*Safe-chain/,
|
||||
eol
|
||||
);
|
||||
|
||||
removeLinesMatchingPattern(
|
||||
startupFile,
|
||||
/^export\s+SAFE_CHAIN_DIR=.*#\s*Safe-chain/,
|
||||
eol
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -74,19 +68,20 @@ function getStartupFile() {
|
|||
}
|
||||
}
|
||||
|
||||
/** @param {string} preamble */
|
||||
function buildManualInstructions(preamble) {
|
||||
const instructions = [preamble, ` source ${path.join(getScriptsDir(), "init-posix.sh")}`];
|
||||
instructions.push(`Then restart your terminal or run: source ~/.zshrc`);
|
||||
return instructions;
|
||||
}
|
||||
|
||||
function getManualTeardownInstructions() {
|
||||
return buildManualInstructions(`Remove the following line from your ~/.zshrc file:`);
|
||||
return [
|
||||
`Remove the following line from your ~/.zshrc file:`,
|
||||
` source ${path.join(getScriptsDir(), "init-posix.sh")}`,
|
||||
`Then restart your terminal or run: source ~/.zshrc`,
|
||||
];
|
||||
}
|
||||
|
||||
function getManualSetupInstructions() {
|
||||
return buildManualInstructions(`Add the following line to your ~/.zshrc file:`);
|
||||
return [
|
||||
`Add the following line to your ~/.zshrc file:`,
|
||||
` source ${path.join(getScriptsDir(), "init-posix.sh")}`,
|
||||
`Then restart your terminal or run: source ~/.zshrc`,
|
||||
];
|
||||
}
|
||||
|
||||
export default {
|
||||
|
|
|
|||
|
|
@ -171,40 +171,6 @@ describe("Zsh shell integration", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("custom install dir", () => {
|
||||
it("writes only the source line to the rc file", () => {
|
||||
zsh.setup();
|
||||
|
||||
const content = fs.readFileSync(mockStartupFile, "utf-8");
|
||||
assert.ok(
|
||||
content.includes("source /test-home/.safe-chain/scripts/init-posix.sh")
|
||||
);
|
||||
assert.ok(!content.includes("SAFE_CHAIN_DIR"));
|
||||
});
|
||||
|
||||
it("removes legacy export lines on teardown", () => {
|
||||
const initialContent = [
|
||||
"#!/bin/zsh",
|
||||
'export SAFE_CHAIN_DIR="/custom/safe-chain" # Safe-chain installation directory',
|
||||
"source /test-home/.safe-chain/scripts/init-posix.sh # Safe-chain Zsh initialization script",
|
||||
].join("\n");
|
||||
|
||||
fs.writeFileSync(mockStartupFile, initialContent, "utf-8");
|
||||
|
||||
zsh.teardown(knownAikidoTools);
|
||||
const content = fs.readFileSync(mockStartupFile, "utf-8");
|
||||
assert.ok(!content.includes("SAFE_CHAIN_DIR"));
|
||||
});
|
||||
|
||||
it("shows source-only manual teardown instructions", () => {
|
||||
assert.deepStrictEqual(zsh.getManualTeardownInstructions(), [
|
||||
"Remove the following line from your ~/.zshrc file:",
|
||||
" source /test-home/.safe-chain/scripts/init-posix.sh",
|
||||
"Then restart your terminal or run: source ~/.zshrc",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("integration tests", () => {
|
||||
it("should handle complete setup and teardown cycle", () => {
|
||||
const tools = [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue