mirror of
https://github.com/tw93/Mole.git
synced 2026-02-04 17:24:45 +00:00
Code optimization as a whole
This commit is contained in:
@@ -115,3 +115,73 @@ EOF
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "decode_file_list validates base64 encoding" {
|
||||
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc << 'EOF'
|
||||
set -euo pipefail
|
||||
source "$PROJECT_ROOT/lib/common.sh"
|
||||
source "$PROJECT_ROOT/lib/uninstall_batch.sh"
|
||||
|
||||
# Valid base64 encoded path list
|
||||
valid_data=$(printf '/path/one\n/path/two' | base64)
|
||||
result=$(decode_file_list "$valid_data" "TestApp")
|
||||
[[ -n "$result" ]] || exit 1
|
||||
EOF
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "decode_file_list rejects invalid base64" {
|
||||
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc << 'EOF'
|
||||
set -euo pipefail
|
||||
source "$PROJECT_ROOT/lib/common.sh"
|
||||
source "$PROJECT_ROOT/lib/uninstall_batch.sh"
|
||||
|
||||
# Invalid base64 - function should return empty and fail
|
||||
if result=$(decode_file_list "not-valid-base64!!!" "TestApp" 2>/dev/null); then
|
||||
# If decode succeeded, result should be empty
|
||||
[[ -z "$result" ]]
|
||||
else
|
||||
# Function returned error, which is expected
|
||||
true
|
||||
fi
|
||||
EOF
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "decode_file_list handles empty input" {
|
||||
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc << 'EOF'
|
||||
set -euo pipefail
|
||||
source "$PROJECT_ROOT/lib/common.sh"
|
||||
source "$PROJECT_ROOT/lib/uninstall_batch.sh"
|
||||
|
||||
# Empty base64
|
||||
empty_data=$(printf '' | base64)
|
||||
result=$(decode_file_list "$empty_data" "TestApp" 2>/dev/null) || true
|
||||
# Empty result is acceptable
|
||||
[[ -z "$result" ]]
|
||||
EOF
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "decode_file_list rejects non-absolute paths" {
|
||||
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc << 'EOF'
|
||||
set -euo pipefail
|
||||
source "$PROJECT_ROOT/lib/common.sh"
|
||||
source "$PROJECT_ROOT/lib/uninstall_batch.sh"
|
||||
|
||||
# Relative path - function should reject it
|
||||
bad_data=$(printf 'relative/path' | base64)
|
||||
if result=$(decode_file_list "$bad_data" "TestApp" 2>/dev/null); then
|
||||
# Should return empty string
|
||||
[[ -z "$result" ]]
|
||||
else
|
||||
# Or return error code
|
||||
true
|
||||
fi
|
||||
EOF
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user