Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/installer-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ on:
- ".github/workflows/sync-catalog.yml"
- "tests/test_package_scripts.sh"
- "tests/test_cli_function_scope.sh"
- "tests/test_cli_arguments.sh"
- "debup-pkg/DEBIAN/**"
- "debup-pkg/usr/local/bin/**"
- ".github/workflows/apt-repo.yml"
Expand All @@ -35,6 +36,7 @@ on:
- ".github/workflows/sync-catalog.yml"
- "tests/test_package_scripts.sh"
- "tests/test_cli_function_scope.sh"
- "tests/test_cli_arguments.sh"
- "debup-pkg/DEBIAN/**"
- "debup-pkg/usr/local/bin/**"
- ".github/workflows/apt-repo.yml"
Expand Down Expand Up @@ -70,6 +72,7 @@ jobs:
bash -n debup-pkg/usr/local/share/debup/package_validation.sh
bash -n tests/test_package_scripts.sh
bash -n tests/test_cli_function_scope.sh
bash -n tests/test_cli_arguments.sh
bash -n debup-pkg/DEBIAN/postinst
bash -n debup-pkg/DEBIAN/postrm
bash -n debup-pkg/usr/local/bin/debup
Expand All @@ -88,6 +91,7 @@ jobs:
shellcheck --severity=error debup-pkg/usr/local/share/debup/package_validation.sh
shellcheck --severity=error tests/test_package_scripts.sh
shellcheck --severity=error tests/test_cli_function_scope.sh
shellcheck --severity=error tests/test_cli_arguments.sh
shellcheck --severity=error debup-pkg/DEBIAN/postinst
shellcheck --severity=error debup-pkg/DEBIAN/postrm
shellcheck --severity=error debup-pkg/usr/local/bin/debup
Expand All @@ -114,6 +118,9 @@ jobs:
- name: Test CLI function scope
run: bash tests/test_cli_function_scope.sh

- name: Test CLI argument regressions
run: bash tests/test_cli_arguments.sh

- name: Build and inspect Debian package
shell: bash
run: |
Expand Down Expand Up @@ -241,6 +248,7 @@ jobs:
bash -n tests/test_api_cache.sh
bash -n tests/test_package_scripts.sh
bash -n tests/test_cli_function_scope.sh
bash -n tests/test_cli_arguments.sh
bash -n debup-pkg/DEBIAN/postinst
bash -n debup-pkg/DEBIAN/postrm
bash -n debup-pkg/usr/local/bin/debup
Expand All @@ -259,6 +267,7 @@ jobs:
bash tests/test_sync_catalog.sh
bash tests/test_package_scripts.sh
bash tests/test_cli_function_scope.sh
bash tests/test_cli_arguments.sh
cmp -s debup-pkg/usr/local/bin/debup debup-pkg/usr/local/bin/dbp

- name: Build, install, and purge the DEB package
Expand Down Expand Up @@ -340,6 +349,7 @@ jobs:
bash -n tests/test_sync_catalog.sh
bash -n tests/test_package_scripts.sh
bash -n tests/test_cli_function_scope.sh
bash -n tests/test_cli_arguments.sh
bash -n debup-pkg/DEBIAN/postinst
bash -n debup-pkg/DEBIAN/postrm
bash -n debup-pkg/usr/local/bin/debup
Expand All @@ -351,6 +361,7 @@ jobs:
bash tests/test_sync_catalog.sh
bash tests/test_package_scripts.sh
bash tests/test_cli_function_scope.sh
bash tests/test_cli_arguments.sh
cmp -s debup-pkg/usr/local/bin/debup debup-pkg/usr/local/bin/dbp

work_dir="$(mktemp -d)"
Expand Down
100 changes: 100 additions & 0 deletions tests/test_cli_arguments.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/usr/bin/env bash
set -Eeuo pipefail
IFS=$'\n\t'

ROOT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd -P)"
TEST_DIR="$(mktemp -d)"
trap 'rm -rf -- "$TEST_DIR"' EXIT

mkdir -p "$TEST_DIR/mock-bin" "$TEST_DIR/home" "$TEST_DIR/etc"
export TEST_DIR
export TEST_CONF_DIR="$TEST_DIR/etc/debup"
export HOME="$TEST_DIR/home"
export XDG_CONFIG_HOME="$TEST_DIR/home/config"
export GITHUB_TOKEN=""
export DRY_RUN=false
export PATH="$TEST_DIR/mock-bin:$PATH"

# The CLI requires root for its system configuration setup. Report root only
# for the effective-UID check; preserve normal id behavior for other calls.
cat > "$TEST_DIR/mock-bin/id" <<'MOCK_ID'
#!/usr/bin/env bash
if [[ "$*" == "-ru" ]]; then
printf '0\n'
else
exec /usr/bin/id "$@"
fi
MOCK_ID

# Stub external package/network tools. Argument-validation failures must happen
# before any transaction; the log lets the test assert dry-run stays inert.
for command_name in curl jq apt apt-get apt-cache apt-mark dpkg dpkg-deb sha256sum; do
cat > "$TEST_DIR/mock-bin/$command_name" <<'MOCK_COMMAND'
#!/usr/bin/env bash
if [[ "$(basename "$0")" == "dpkg" && "$1" == "--print-architecture" ]]; then
printf 'amd64\n'
else
printf '%s %s\n' "$(basename "$0")" "$*" >> "$TEST_DIR/commands.log"
fi
exit 0
MOCK_COMMAND
chmod 0755 "$TEST_DIR/mock-bin/$command_name"
done
chmod 0755 "$TEST_DIR/mock-bin/id"

# Copy the real package tree and redirect only the hard-coded system config
# directory into this test's temporary sandbox.
cp -a "$ROOT_DIR/debup-pkg" "$TEST_DIR/debup-pkg"
sed "s|^CONF_DIR=\"/etc/debup\"$|CONF_DIR=\"$TEST_CONF_DIR\"|" \
"$TEST_DIR/debup-pkg/usr/local/bin/debup" > "$TEST_DIR/debup-pkg/usr/local/bin/debup.test"
mv "$TEST_DIR/debup-pkg/usr/local/bin/debup.test" "$TEST_DIR/debup-pkg/usr/local/bin/debup"
cp "$TEST_DIR/debup-pkg/usr/local/bin/debup" "$TEST_DIR/debup-pkg/usr/local/bin/dbp"
chmod 0755 "$TEST_DIR/debup-pkg/usr/local/bin/debup" "$TEST_DIR/debup-pkg/usr/local/bin/dbp"
DEBUP="$TEST_DIR/debup-pkg/usr/local/bin/debup"

fail() {
printf 'FAIL: %s\n' "$*" >&2
exit 1
}

expect_rejected() {
local label="$1"
shift
local status=0
if "$DEBUP" "$@" >"$TEST_DIR/stdout" 2>"$TEST_DIR/stderr"; then
fail "$label was accepted (args: $*)"
else
status=$?
fi
[[ "$status" -ne 0 ]] || fail "$label returned success"
}

expect_rejected "add with multiple targets" add package-one package-two
expect_rejected "add with unknown option" add --not-a-real-option package-one
expect_rejected "remove with multiple packages" remove package-one package-two
expect_rejected "remove with unknown option" remove --not-a-real-option package-one
expect_rejected "upgrade with unknown option" upgrade --not-a-real-option
expect_rejected "upgrade with positional target" upgrade package-one
expect_rejected "pin without a package" pin
expect_rejected "pin with multiple packages" pin package-one package-two
expect_rejected "unpin without a package" unpin
expect_rejected "unpin with multiple packages" unpin package-one package-two

# Supported confirmation flags remain accepted, and dry-run must not reach
# apt-mark for pin/unpin or apt-get for remove.
: > "$TEST_DIR/commands.log"
"$DEBUP" --dry-run remove --yes package-one >"$TEST_DIR/stdout" 2>"$TEST_DIR/stderr" ||
fail "remove --dry-run --yes <package> was rejected"
"$DEBUP" --dry-run pin package-one >"$TEST_DIR/stdout" 2>"$TEST_DIR/stderr" ||
fail "pin --dry-run <package> was rejected"
"$DEBUP" --dry-run unpin package-one >"$TEST_DIR/stdout" 2>"$TEST_DIR/stderr" ||
fail "unpin --dry-run <package> was rejected"

if [[ -s "$TEST_DIR/commands.log" ]]; then
fail "dry-run invoked an external package/network command: $(cat "$TEST_DIR/commands.log")"
fi

cmp -s "$TEST_DIR/debup-pkg/usr/local/bin/debup" "$TEST_DIR/debup-pkg/usr/local/bin/dbp" ||
fail "packaged debup/dbp launchers differ"

printf 'PASS: strict CLI argument rejection, supported flags, dry-run safety, and launcher parity.\n'
Loading