mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 20:20:49 +00:00
Some cleanup
This commit is contained in:
parent
24af6f21eb
commit
b0f392522b
19 changed files with 286 additions and 8 deletions
|
|
@ -9,6 +9,7 @@ describe("PowerShell Core shell integration", () => {
|
|||
let mockStartupFile;
|
||||
let powershell;
|
||||
let executionPolicyResult;
|
||||
let getSafeChainDirResult = undefined;
|
||||
|
||||
beforeEach(async () => {
|
||||
// Create temporary startup file for testing
|
||||
|
|
@ -26,6 +27,7 @@ describe("PowerShell Core shell integration", () => {
|
|||
mock.module("../helpers.js", {
|
||||
namedExports: {
|
||||
doesExecutableExistOnSystem: () => true,
|
||||
getSafeChainDir: () => getSafeChainDirResult,
|
||||
addLineToFile: (filePath, line) => {
|
||||
if (!fs.existsSync(filePath)) {
|
||||
fs.writeFileSync(filePath, "", "utf-8");
|
||||
|
|
@ -63,6 +65,7 @@ describe("PowerShell Core shell integration", () => {
|
|||
|
||||
// Reset mocks
|
||||
mock.reset();
|
||||
getSafeChainDirResult = undefined;
|
||||
});
|
||||
|
||||
describe("isInstalled", () => {
|
||||
|
|
@ -206,6 +209,40 @@ describe("PowerShell Core shell integration", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("SAFE_CHAIN_DIR", () => {
|
||||
it("should write $env:SAFE_CHAIN_DIR line to profile when custom dir is set", async () => {
|
||||
getSafeChainDirResult = "C:\\custom\\safe-chain";
|
||||
await powershell.setup();
|
||||
|
||||
const content = fs.readFileSync(mockStartupFile, "utf-8");
|
||||
assert.ok(
|
||||
content.includes("$env:SAFE_CHAIN_DIR = 'C:\\custom\\safe-chain' # Safe-chain installation directory")
|
||||
);
|
||||
});
|
||||
|
||||
it("should not write $env:SAFE_CHAIN_DIR line when no custom dir is set", async () => {
|
||||
getSafeChainDirResult = undefined;
|
||||
await powershell.setup();
|
||||
|
||||
const content = fs.readFileSync(mockStartupFile, "utf-8");
|
||||
assert.ok(!content.includes("SAFE_CHAIN_DIR"));
|
||||
});
|
||||
|
||||
it("should remove $env:SAFE_CHAIN_DIR line 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"));
|
||||
});
|
||||
});
|
||||
|
||||
describe("execution policy", () => {
|
||||
it(`should throw for restricted policies`, async () => {
|
||||
executionPolicyResult = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue