mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
109 lines
3.5 KiB
JavaScript
109 lines
3.5 KiB
JavaScript
import { describe, it, before, beforeEach, afterEach } from "node:test";
|
|
import { DockerTestContainer } from "./DockerTestContainer.js";
|
|
import assert from "node:assert";
|
|
|
|
describe("E2E: pip coverage", () => {
|
|
let container;
|
|
|
|
before(async () => {
|
|
DockerTestContainer.buildImage();
|
|
});
|
|
|
|
beforeEach(async () => {
|
|
// Run a new Docker container for each test
|
|
container = new DockerTestContainer();
|
|
await container.start();
|
|
|
|
const installationShell = await container.openShell("zsh");
|
|
await installationShell.runCommand("safe-chain setup");
|
|
});
|
|
|
|
afterEach(async () => {
|
|
// Stop and clean up the container after each test
|
|
if (container) {
|
|
await container.stop();
|
|
container = null;
|
|
}
|
|
});
|
|
|
|
it(`successfully installs known safe packages with pip3`, async () => {
|
|
const shell = await container.openShell("zsh");
|
|
const result = await shell.runCommand("pip3 install requests");
|
|
|
|
assert.ok(
|
|
result.output.includes("no malicious packages found."),
|
|
`Output did not include expected text. Output was:\n${result.output}`
|
|
);
|
|
});
|
|
|
|
it(`pip3 download`, async () => {
|
|
const shell = await container.openShell("zsh");
|
|
const result = await shell.runCommand("pip3 download requests");
|
|
|
|
assert.ok(
|
|
result.output.includes("no malicious packages found."),
|
|
`Output did not include expected text. Output was:\n${result.output}`
|
|
);
|
|
});
|
|
|
|
it(`pip3 .whl`, async () => {
|
|
const shell = await container.openShell("zsh");
|
|
const result = await shell.runCommand("pip3 wheel requests");
|
|
|
|
assert.ok(
|
|
result.output.includes("no malicious packages found."),
|
|
`Output did not include expected text. Output was:\n${result.output}`
|
|
);
|
|
});
|
|
|
|
it(`pip3 install --dry-run is respected by scanner`, async () => {
|
|
const shell = await container.openShell("zsh");
|
|
const result = await shell.runCommand("pip3 install --dry-run requests");
|
|
|
|
assert.ok(
|
|
result.output.includes("no malicious packages found."),
|
|
`Output did not include expected text. Output was:\n${result.output}`
|
|
);
|
|
});
|
|
|
|
it(`pip3 install with extras such as requests[socks]`, async () => {
|
|
const shell = await container.openShell("zsh");
|
|
const result = await shell.runCommand('pip3 install "requests[socks]==2.32.3"');
|
|
|
|
assert.ok(
|
|
result.output.includes("no malicious packages found."),
|
|
`Output did not include expected text. Output was:\n${result.output}`
|
|
);
|
|
});
|
|
|
|
it(`pip3 install with range version specifier`, async () => {
|
|
const shell = await container.openShell("zsh");
|
|
const result = await shell.runCommand('pip3 install "Jinja2>=3.1,<3.2"');
|
|
|
|
assert.ok(
|
|
result.output.includes("no malicious packages found."),
|
|
`Output did not include expected text. Output was:\n${result.output}`
|
|
);
|
|
});
|
|
|
|
it(`python3 -m pip install routes through safe-chain`, async () => {
|
|
const shell = await container.openShell("zsh");
|
|
const result = await shell.runCommand('python3 -m pip install requests');
|
|
|
|
assert.ok(
|
|
result.output.includes("no malicious packages found."),
|
|
`Output did not include expected text. Output was:\n${result.output}`
|
|
);
|
|
});
|
|
|
|
it(`python3 -m pip download routes through safe-chain`, async () => {
|
|
const shell = await container.openShell("zsh");
|
|
const result = await shell.runCommand('python3 -m pip download requests');
|
|
|
|
assert.ok(
|
|
result.output.includes("no malicious packages found."),
|
|
`Output did not include expected text. Output was:\n${result.output}`
|
|
);
|
|
});
|
|
|
|
});
|