mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Fix WIndows shell + unit tests
This commit is contained in:
parent
1aef941d1c
commit
32c95dbb9d
14 changed files with 289 additions and 43 deletions
|
|
@ -142,19 +142,37 @@ function cygpathw(path) {
|
|||
}
|
||||
|
||||
function getManualTeardownInstructions() {
|
||||
return [
|
||||
`Remove the following line from your ~/.bashrc file:`,
|
||||
` source ~/.safe-chain/scripts/init-posix.sh`,
|
||||
`Then restart your terminal or run: source ~/.bashrc`,
|
||||
];
|
||||
const customDir = getSafeChainDir();
|
||||
const instructions = [`Remove the following line from your ~/.bashrc file:`];
|
||||
|
||||
if (customDir) {
|
||||
instructions.push(
|
||||
` export SAFE_CHAIN_DIR="${customDir}"`,
|
||||
` source ${path.join(getScriptsDir(), "init-posix.sh")}`,
|
||||
);
|
||||
} else {
|
||||
instructions.push(` source ~/.safe-chain/scripts/init-posix.sh`);
|
||||
}
|
||||
|
||||
instructions.push(`Then restart your terminal or run: source ~/.bashrc`);
|
||||
return instructions;
|
||||
}
|
||||
|
||||
function getManualSetupInstructions() {
|
||||
return [
|
||||
`Add the following line to your ~/.bashrc file:`,
|
||||
` source ~/.safe-chain/scripts/init-posix.sh`,
|
||||
`Then restart your terminal or run: source ~/.bashrc`,
|
||||
];
|
||||
const customDir = getSafeChainDir();
|
||||
const instructions = [`Add the following line to your ~/.bashrc file:`];
|
||||
|
||||
if (customDir) {
|
||||
instructions.push(
|
||||
` export SAFE_CHAIN_DIR="${customDir}"`,
|
||||
` source ${path.join(getScriptsDir(), "init-posix.sh")}`,
|
||||
);
|
||||
} else {
|
||||
instructions.push(` source ~/.safe-chain/scripts/init-posix.sh`);
|
||||
}
|
||||
|
||||
instructions.push(`Then restart your terminal or run: source ~/.bashrc`);
|
||||
return instructions;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -235,6 +235,17 @@ describe("Bash shell integration", () => {
|
|||
const content = fs.readFileSync(mockStartupFile, "utf-8");
|
||||
assert.ok(!content.includes("SAFE_CHAIN_DIR"));
|
||||
});
|
||||
|
||||
it("should show custom manual setup instructions when custom dir is set", () => {
|
||||
getSafeChainDirResult = "/custom/safe-chain";
|
||||
|
||||
assert.deepStrictEqual(bash.getManualSetupInstructions(), [
|
||||
"Add the following line to your ~/.bashrc file:",
|
||||
' export SAFE_CHAIN_DIR="/custom/safe-chain"',
|
||||
" source /test-home/.safe-chain/scripts/init-posix.sh",
|
||||
"Then restart your terminal or run: source ~/.bashrc",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("integration tests", () => {
|
||||
|
|
|
|||
|
|
@ -85,19 +85,45 @@ function getStartupFile() {
|
|||
}
|
||||
|
||||
function getManualTeardownInstructions() {
|
||||
return [
|
||||
const customDir = getSafeChainDir();
|
||||
const instructions = [
|
||||
`Remove the following line from your ~/.config/fish/config.fish file:`,
|
||||
` source ~/.safe-chain/scripts/init-fish.fish`,
|
||||
`Then restart your terminal or run: source ~/.config/fish/config.fish`,
|
||||
];
|
||||
|
||||
if (customDir) {
|
||||
instructions.push(
|
||||
` set -gx SAFE_CHAIN_DIR "${customDir}"`,
|
||||
` source ${path.join(getScriptsDir(), "init-fish.fish")}`,
|
||||
);
|
||||
} else {
|
||||
instructions.push(` source ~/.safe-chain/scripts/init-fish.fish`);
|
||||
}
|
||||
|
||||
instructions.push(
|
||||
`Then restart your terminal or run: source ~/.config/fish/config.fish`,
|
||||
);
|
||||
return instructions;
|
||||
}
|
||||
|
||||
function getManualSetupInstructions() {
|
||||
return [
|
||||
const customDir = getSafeChainDir();
|
||||
const instructions = [
|
||||
`Add the following line to your ~/.config/fish/config.fish file:`,
|
||||
` source ~/.safe-chain/scripts/init-fish.fish`,
|
||||
`Then restart your terminal or run: source ~/.config/fish/config.fish`,
|
||||
];
|
||||
|
||||
if (customDir) {
|
||||
instructions.push(
|
||||
` set -gx SAFE_CHAIN_DIR "${customDir}"`,
|
||||
` source ${path.join(getScriptsDir(), "init-fish.fish")}`,
|
||||
);
|
||||
} else {
|
||||
instructions.push(` source ~/.safe-chain/scripts/init-fish.fish`);
|
||||
}
|
||||
|
||||
instructions.push(
|
||||
`Then restart your terminal or run: source ~/.config/fish/config.fish`,
|
||||
);
|
||||
return instructions;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -187,6 +187,17 @@ describe("Fish shell integration", () => {
|
|||
const content = fs.readFileSync(mockStartupFile, "utf-8");
|
||||
assert.ok(!content.includes("SAFE_CHAIN_DIR"));
|
||||
});
|
||||
|
||||
it("should show custom manual setup instructions when custom dir is set", () => {
|
||||
getSafeChainDirResult = "/custom/safe-chain";
|
||||
|
||||
assert.deepStrictEqual(fish.getManualSetupInstructions(), [
|
||||
"Add the following line to your ~/.config/fish/config.fish file:",
|
||||
' set -gx SAFE_CHAIN_DIR "/custom/safe-chain"',
|
||||
" source /test-home/.safe-chain/scripts/init-fish.fish",
|
||||
"Then restart your terminal or run: source ~/.config/fish/config.fish",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("integration tests", () => {
|
||||
|
|
|
|||
|
|
@ -88,19 +88,41 @@ function getStartupFile() {
|
|||
}
|
||||
|
||||
function getManualTeardownInstructions() {
|
||||
return [
|
||||
const customDir = getSafeChainDir();
|
||||
const instructions = [
|
||||
`Remove the following line from your PowerShell profile (run "echo $PROFILE" to find its location):`,
|
||||
` . "$HOME\\.safe-chain\\scripts\\init-pwsh.ps1"`,
|
||||
`Then restart your terminal or run: . $PROFILE`,
|
||||
];
|
||||
|
||||
if (customDir) {
|
||||
instructions.push(
|
||||
` $env:SAFE_CHAIN_DIR = '${customDir}'`,
|
||||
` . "${path.join(getScriptsDir(), "init-pwsh.ps1")}"`,
|
||||
);
|
||||
} else {
|
||||
instructions.push(` . "$HOME\\.safe-chain\\scripts\\init-pwsh.ps1"`);
|
||||
}
|
||||
|
||||
instructions.push(`Then restart your terminal or run: . $PROFILE`);
|
||||
return instructions;
|
||||
}
|
||||
|
||||
function getManualSetupInstructions() {
|
||||
return [
|
||||
const customDir = getSafeChainDir();
|
||||
const instructions = [
|
||||
`Add the following line to your PowerShell profile (run "echo $PROFILE" to find its location):`,
|
||||
` . "$HOME\\.safe-chain\\scripts\\init-pwsh.ps1"`,
|
||||
`Then restart your terminal or run: . $PROFILE`,
|
||||
];
|
||||
|
||||
if (customDir) {
|
||||
instructions.push(
|
||||
` $env:SAFE_CHAIN_DIR = '${customDir}'`,
|
||||
` . "${path.join(getScriptsDir(), "init-pwsh.ps1")}"`,
|
||||
);
|
||||
} else {
|
||||
instructions.push(` . "$HOME\\.safe-chain\\scripts\\init-pwsh.ps1"`);
|
||||
}
|
||||
|
||||
instructions.push(`Then restart your terminal or run: . $PROFILE`);
|
||||
return instructions;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -241,6 +241,17 @@ describe("PowerShell Core shell integration", () => {
|
|||
const content = fs.readFileSync(mockStartupFile, "utf-8");
|
||||
assert.ok(!content.includes("SAFE_CHAIN_DIR"));
|
||||
});
|
||||
|
||||
it("should show custom manual setup instructions when custom dir is set", () => {
|
||||
getSafeChainDirResult = "C:\\custom\\safe-chain";
|
||||
|
||||
assert.deepStrictEqual(powershell.getManualSetupInstructions(), [
|
||||
'Add the following line to your PowerShell profile (run "echo $PROFILE" to find its location):',
|
||||
" $env:SAFE_CHAIN_DIR = 'C:\\custom\\safe-chain'",
|
||||
' . "/test-home/.safe-chain/scripts/init-pwsh.ps1"',
|
||||
"Then restart your terminal or run: . $PROFILE",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("execution policy", () => {
|
||||
|
|
|
|||
|
|
@ -88,19 +88,41 @@ function getStartupFile() {
|
|||
}
|
||||
|
||||
function getManualTeardownInstructions() {
|
||||
return [
|
||||
const customDir = getSafeChainDir();
|
||||
const instructions = [
|
||||
`Remove the following line from your PowerShell profile (run "echo $PROFILE" to find its location):`,
|
||||
` . "$HOME\\.safe-chain\\scripts\\init-pwsh.ps1"`,
|
||||
`Then restart your terminal or run: . $PROFILE`,
|
||||
];
|
||||
|
||||
if (customDir) {
|
||||
instructions.push(
|
||||
` $env:SAFE_CHAIN_DIR = '${customDir}'`,
|
||||
` . "${path.join(getScriptsDir(), "init-pwsh.ps1")}"`,
|
||||
);
|
||||
} else {
|
||||
instructions.push(` . "$HOME\\.safe-chain\\scripts\\init-pwsh.ps1"`);
|
||||
}
|
||||
|
||||
instructions.push(`Then restart your terminal or run: . $PROFILE`);
|
||||
return instructions;
|
||||
}
|
||||
|
||||
function getManualSetupInstructions() {
|
||||
return [
|
||||
const customDir = getSafeChainDir();
|
||||
const instructions = [
|
||||
`Add the following line to your PowerShell profile (run "echo $PROFILE" to find its location):`,
|
||||
` . "$HOME\\.safe-chain\\scripts\\init-pwsh.ps1"`,
|
||||
`Then restart your terminal or run: . $PROFILE`,
|
||||
];
|
||||
|
||||
if (customDir) {
|
||||
instructions.push(
|
||||
` $env:SAFE_CHAIN_DIR = '${customDir}'`,
|
||||
` . "${path.join(getScriptsDir(), "init-pwsh.ps1")}"`,
|
||||
);
|
||||
} else {
|
||||
instructions.push(` . "$HOME\\.safe-chain\\scripts\\init-pwsh.ps1"`);
|
||||
}
|
||||
|
||||
instructions.push(`Then restart your terminal or run: . $PROFILE`);
|
||||
return instructions;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -241,6 +241,17 @@ describe("Windows PowerShell shell integration", () => {
|
|||
const content = fs.readFileSync(mockStartupFile, "utf-8");
|
||||
assert.ok(!content.includes("SAFE_CHAIN_DIR"));
|
||||
});
|
||||
|
||||
it("should show custom manual teardown instructions when custom dir is set", () => {
|
||||
getSafeChainDirResult = "C:\\custom\\safe-chain";
|
||||
|
||||
assert.deepStrictEqual(windowsPowershell.getManualTeardownInstructions(), [
|
||||
'Remove the following line from your PowerShell profile (run "echo $PROFILE" to find its location):',
|
||||
" $env:SAFE_CHAIN_DIR = 'C:\\custom\\safe-chain'",
|
||||
' . "/test-home/.safe-chain/scripts/init-pwsh.ps1"',
|
||||
"Then restart your terminal or run: . $PROFILE",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("execution policy", () => {
|
||||
|
|
|
|||
|
|
@ -85,19 +85,37 @@ function getStartupFile() {
|
|||
}
|
||||
|
||||
function getManualTeardownInstructions() {
|
||||
return [
|
||||
`Remove the following line from your ~/.zshrc file:`,
|
||||
` source ~/.safe-chain/scripts/init-posix.sh`,
|
||||
`Then restart your terminal or run: source ~/.zshrc`,
|
||||
];
|
||||
const customDir = getSafeChainDir();
|
||||
const instructions = [`Remove the following line from your ~/.zshrc file:`];
|
||||
|
||||
if (customDir) {
|
||||
instructions.push(
|
||||
` export SAFE_CHAIN_DIR="${customDir}"`,
|
||||
` source ${path.join(getScriptsDir(), "init-posix.sh")}`,
|
||||
);
|
||||
} else {
|
||||
instructions.push(` source ~/.safe-chain/scripts/init-posix.sh`);
|
||||
}
|
||||
|
||||
instructions.push(`Then restart your terminal or run: source ~/.zshrc`);
|
||||
return instructions;
|
||||
}
|
||||
|
||||
function getManualSetupInstructions() {
|
||||
return [
|
||||
`Add the following line to your ~/.zshrc file:`,
|
||||
` source ~/.safe-chain/scripts/init-posix.sh`,
|
||||
`Then restart your terminal or run: source ~/.zshrc`,
|
||||
];
|
||||
const customDir = getSafeChainDir();
|
||||
const instructions = [`Add the following line to your ~/.zshrc file:`];
|
||||
|
||||
if (customDir) {
|
||||
instructions.push(
|
||||
` export SAFE_CHAIN_DIR="${customDir}"`,
|
||||
` source ${path.join(getScriptsDir(), "init-posix.sh")}`,
|
||||
);
|
||||
} else {
|
||||
instructions.push(` source ~/.safe-chain/scripts/init-posix.sh`);
|
||||
}
|
||||
|
||||
instructions.push(`Then restart your terminal or run: source ~/.zshrc`);
|
||||
return instructions;
|
||||
}
|
||||
|
||||
export default {
|
||||
|
|
|
|||
|
|
@ -206,6 +206,17 @@ describe("Zsh shell integration", () => {
|
|||
const content = fs.readFileSync(mockStartupFile, "utf-8");
|
||||
assert.ok(!content.includes("SAFE_CHAIN_DIR"));
|
||||
});
|
||||
|
||||
it("should show custom manual teardown instructions when custom dir is set", () => {
|
||||
getSafeChainDirResult = "/custom/safe-chain";
|
||||
|
||||
assert.deepStrictEqual(zsh.getManualTeardownInstructions(), [
|
||||
"Remove the following line from your ~/.zshrc file:",
|
||||
' export SAFE_CHAIN_DIR="/custom/safe-chain"',
|
||||
" source /test-home/.safe-chain/scripts/init-posix.sh",
|
||||
"Then restart your terminal or run: source ~/.zshrc",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("integration tests", () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue