Add e2e test for malware blocking + python3 fix

This commit is contained in:
Reinier Criel 2025-10-28 08:46:07 -07:00
parent 3c109fb5fd
commit c2e632ead2
6 changed files with 115 additions and 16 deletions

View file

@ -82,6 +82,7 @@ function python
if test (count $argv) -ge 2; and test $argv[1] = "-m"; and string match -qr '^pip(3)?$' -- $argv[2]
set mod $argv[2]
set args $argv[3..-1]
# python -m pip → aikido-pip, python -m pip3 → aikido-pip3
if test $mod = "pip3"
wrapSafeChainCommand "pip3" "aikido-pip3" $args
else
@ -95,13 +96,9 @@ end
# `python3 -m pip`, `python3 -m pip3'.
function python3
if test (count $argv) -ge 2; and test $argv[1] = "-m"; and string match -qr '^pip(3)?$' -- $argv[2]
set mod $argv[2]
set args $argv[3..-1]
if test $mod = "pip3"
wrapSafeChainCommand "pip3" "aikido-pip3" $args
else
wrapSafeChainCommand "pip" "aikido-pip" $args
end
# python3 always uses pip3, regardless of whether user types `pip` or `pip3`
wrapSafeChainCommand "pip3" "aikido-pip3" $args
else
command python3 $argv
end

View file

@ -74,6 +74,7 @@ function python() {
if [[ "$1" == "-m" && "$2" == pip* ]]; then
local mod="$2"
shift 2
# python -m pip → aikido-pip, python -m pip3 → aikido-pip3
if [[ "$mod" == "pip3" ]]; then
wrapSafeChainCommand "pip3" "aikido-pip3" "$@"
else
@ -87,13 +88,9 @@ function python() {
# `python3 -m pip`, `python3 -m pip3'.
function python3() {
if [[ "$1" == "-m" && "$2" == pip* ]]; then
local mod="$2"
shift 2
if [[ "$mod" == "pip3" ]]; then
wrapSafeChainCommand "pip3" "aikido-pip3" "$@"
else
wrapSafeChainCommand "pip" "aikido-pip" "$@"
fi
# python3 always uses pip3, regardless of whether user types `pip` or `pip3`
wrapSafeChainCommand "pip3" "aikido-pip3" "$@"
else
command python3 "$@"
fi

View file

@ -99,6 +99,7 @@ function pip3 {
function python {
param([Parameter(ValueFromRemainingArguments=$true)]$Args)
if ($Args.Length -ge 2 -and $Args[0] -eq '-m' -and $Args[1] -match '^pip(3)?$') {
# python -m pip → aikido-pip, python -m pip3 → aikido-pip3
$pipArgs = if ($Args.Length -gt 2) { $Args | Select-Object -Skip 2 } else { @() }
if ($Args[1] -eq 'pip3') { Invoke-WrappedCommand 'pip3' 'aikido-pip3' $pipArgs }
else { Invoke-WrappedCommand 'pip' 'aikido-pip' $pipArgs }
@ -112,9 +113,9 @@ function python {
function python3 {
param([Parameter(ValueFromRemainingArguments=$true)]$Args)
if ($Args.Length -ge 2 -and $Args[0] -eq '-m' -and $Args[1] -match '^pip(3)?$') {
# python3 always uses pip3, regardless of whether user types `pip` or `pip3`
$pipArgs = if ($Args.Length -gt 2) { $Args | Select-Object -Skip 2 } else { @() }
if ($Args[1] -eq 'pip3') { Invoke-WrappedCommand 'pip3' 'aikido-pip3' $pipArgs }
else { Invoke-WrappedCommand 'pip' 'aikido-pip' $pipArgs }
Invoke-WrappedCommand 'pip3' 'aikido-pip3' $pipArgs
}
else {
Invoke-RealCommand 'python3' $Args

View file

@ -126,6 +126,15 @@ export async function safeSpawnPy(command, args, options = {}) {
});
child.on("error", (error) => {
// When stdio is inherited and spawn fails (e.g., command not found),
// we need to write the error to stderr manually since there's no child process
if (options.stdio === "inherit") {
if (error.code === "ENOENT") {
process.stderr.write(`Error: Command '${command}' not found. Please ensure it is installed and available in your PATH.\n`);
} else {
process.stderr.write(`Error: ${error.message}\n`);
}
}
resolve({ status: 1, stdout: "", stderr: error.message || String(error) });
});
});