diff --git a/.circleci/scripts/run_integration.sh b/.circleci/scripts/run_integration.sh index 00b3c5f8fdd..1380b07de53 100644 --- a/.circleci/scripts/run_integration.sh +++ b/.circleci/scripts/run_integration.sh @@ -1,14 +1,14 @@ #!/usr/bin/env bash set -euo pipefail -if [ "${GITHUB_ACTIONS:-}" = true ]; then - echo "Integration contracts are owned by CircleCI" >&2 - exit 1 -fi - suite="${1:?integration suite required}" mode="${2:-standard}" side="${3:-}" +requested_workers="${INTEGRATION_WORKERS:-}" +license_env=() +if [ -n "${LITELLM_LICENSE:-}" ]; then + license_env=("LITELLM_LICENSE=$LITELLM_LICENSE") +fi if [ "$mode" = replica ]; then results="test-results/integration-${suite}-replica" elif [ "$mode" = parity ]; then @@ -84,7 +84,7 @@ if [ "$suite" = browser ]; then export LITELLM_UI_PATH="$PWD/ui/litellm-dashboard/out" test -f "$LITELLM_UI_PATH/index.html" fi -export INTEGRATION_SEED="$(.venv/bin/python -c 'import hashlib,os; print(int(hashlib.sha256((os.environ.get("CIRCLE_SHA1", "local") + os.environ.get("CIRCLE_WORKFLOW_ID", "local")).encode()).hexdigest()[:8],16))')" +export INTEGRATION_SEED="$(.venv/bin/python -c 'import hashlib,os; print(int(hashlib.sha256(((os.environ.get("CIRCLE_SHA1") or os.environ.get("GITHUB_SHA") or "local") + (os.environ.get("CIRCLE_WORKFLOW_ID") or os.environ.get("GITHUB_RUN_ID") or "local")).encode()).hexdigest()[:8],16))')" export INTEGRATION_ORDER_SEED="$INTEGRATION_SEED" uv run --no-sync prisma generate --schema litellm/proxy/schema.prisma > "$results/prisma-generate.log" 2>&1 @@ -107,7 +107,7 @@ sudo iptables -N integration_only guard_created=true sudo iptables -A integration_only -o lo -j ACCEPT sudo iptables -A integration_only -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT -for service in postgres-db redis-cache; do +for service in "${INTEGRATION_POSTGRES_CONTAINER:-postgres-db}" "${INTEGRATION_REDIS_CONTAINER:-redis-cache}"; do address="$(docker inspect --format '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$service")" sudo iptables -A integration_only -d "$address" -j ACCEPT done @@ -145,6 +145,9 @@ fi if [ "$suite" = mcp ]; then export INTEGRATION_WORKERS=2 INTEGRATION_COVERAGE=1 fi +if [ -n "$requested_workers" ]; then + export INTEGRATION_WORKERS="$requested_workers" +fi isolated_workers=false if [ "${INTEGRATION_WORKERS:-1}" -gt 1 ]; then isolated_workers=true @@ -185,7 +188,7 @@ start_proxy() { "${database_env[@]}" REDIS_HOST="$REDIS_HOST" REDIS_PORT="$REDIS_PORT" \ INTEGRATION_UPSTREAM_URL="$INTEGRATION_UPSTREAM_URL" \ LITELLM_MASTER_KEY="$LITELLM_MASTER_KEY" LITELLM_SALT_KEY="$LITELLM_SALT_KEY" LITELLM_UI_PATH="$LITELLM_UI_PATH" PROXY_BASE_URL="http://127.0.0.1:$port" \ - LITELLM_LICENSE="${LITELLM_LICENSE:-}" \ + "${license_env[@]}" \ LITELLM_MODE=PRODUCTION STORE_MODEL_IN_DB=True LITELLM_ENABLE_MCP_STDIO=true "${cost_map_env[@]}" \ AWS_EC2_METADATA_DISABLED=true DO_NOT_TRACK=1 COVERAGE_FILE="$coverage_data" \ "${proxy_command[@]}" --config tests/integration/proxy_config.yaml \ @@ -257,7 +260,7 @@ env -i PATH="$PATH" HOME="$HOME" PYTHONPATH="$PYTHONPATH" \ "${shared_services[@]}" "${worker_coverage[@]}" \ INTEGRATION_WORKERS="${INTEGRATION_WORKERS:-1}" \ LITELLM_MODE=PRODUCTION \ - LITELLM_LICENSE="${LITELLM_LICENSE:-}" \ + "${license_env[@]}" \ INTEGRATION_SEED="$INTEGRATION_SEED" \ INTEGRATION_ORDER_SEED="$INTEGRATION_ORDER_SEED" \ INTEGRATION_CASE_SHARDS="${CIRCLE_NODE_TOTAL:-1}" INTEGRATION_CASE_SHARD_INDEX="${CIRCLE_NODE_INDEX:-0}" \ diff --git a/.github/scripts/assert_secret_absent.py b/.github/scripts/assert_secret_absent.py new file mode 100644 index 00000000000..2d001e833ac --- /dev/null +++ b/.github/scripts/assert_secret_absent.py @@ -0,0 +1,119 @@ +import base64 +import io +import os +import sys +import urllib.parse +import zipfile +from collections.abc import Callable, Iterator, Mapping +from dataclasses import dataclass +from functools import reduce +from itertools import chain +from pathlib import Path +from types import MappingProxyType +from typing import Final, TextIO + +SECRET_VARIABLE: Final = "SCANNED_SECRET" +MIN_ENCODED_LENGTH: Final = 12 +MAX_ARCHIVE_DEPTH: Final = 3 +MASK: Final = "***" + +Forms = tuple[tuple[str, str], ...] + + +@dataclass(frozen=True, slots=True) +class Hit: + location: str + form: str + + +def _aligned_encodings(raw: bytes, name: str, encode: Callable[[bytes], bytes]) -> Iterator[tuple[str, str]]: + for offset in range(3): + chunk: Final = raw[offset:] + yield f"{name} offset {offset}", encode(chunk[: len(chunk) - len(chunk) % 3]).decode() + + +def secret_forms(secret: str) -> Forms: + encoded: Final = ( + ("url-encoded", urllib.parse.quote(secret, safe="")), + *_aligned_encodings(secret.encode(), "base64", base64.b64encode), + *_aligned_encodings(secret.encode(), "base64url", base64.urlsafe_b64encode), + ) + by_value: Final = MappingProxyType( + {value: name for name, value in encoded if value != secret and len(value) >= MIN_ENCODED_LENGTH} + ) + return (("raw", secret), *((name, value) for value, name in by_value.items())) + + +def mask(text: str, forms: Forms) -> str: + return reduce(lambda masked, form: masked.replace(form[1], MASK), forms, text) + + +def _name_hits(location: str, name: str, forms: Forms) -> Iterator[Hit]: + for form, value in forms: + if value in name: + yield Hit(mask(location, forms), f"{form} in name") + + +def _content_hits(location: str, data: bytes, forms: Forms, depth: int) -> Iterator[Hit]: + for form, value in forms: + if value.encode() in data: + yield Hit(mask(location, forms), form) + if depth >= MAX_ARCHIVE_DEPTH or not zipfile.is_zipfile(io.BytesIO(data)): + return + with zipfile.ZipFile(io.BytesIO(data)) as archive: + for member in archive.infolist(): + if member.is_dir(): + continue + yield from _content_hits(f"{location}!{member.filename}", archive.read(member), forms, depth + 1) + + +def _walk(root: Path) -> Iterator[tuple[Path, bool]]: + for directory, subdirectories, files in os.walk(root): + yield from ((Path(directory, name), True) for name in subdirectories if Path(directory, name).is_symlink()) + yield from ((Path(directory, name), False) for name in files) + + +def _path_hits(root: Path, path: Path, linked_directory: bool, forms: Forms) -> Iterator[Hit]: + location: Final = str(path.relative_to(root)) + if linked_directory: + yield Hit(mask(location, forms), "directory symlink, not scanned") + return + yield from _name_hits(location, location, forms) + yield from _content_hits(location, path.read_bytes(), forms, 0) + + +def scan(root: Path, secret: str) -> tuple[int, tuple[Hit, ...]]: + forms: Final = secret_forms(secret) + entries: Final = tuple(_walk(root)) + hits: Final = tuple(chain.from_iterable(_path_hits(root, path, linked, forms) for path, linked in entries)) + return len(entries), hits + + +def main(argv: tuple[str, ...], environ: Mapping[str, str], out: TextIO) -> int: + if len(argv) != 1: + print(f"usage: assert_secret_absent.py , with the secret in ${SECRET_VARIABLE}", file=out) + return 2 + secret: Final = environ.get(SECRET_VARIABLE, "") + root: Final = Path(argv[0]) + if not secret: + print(f"{SECRET_VARIABLE} is empty, nothing to scan for", file=out) + return 0 + if not root.is_dir(): + print(f"{root} is not a directory, nothing to scan", file=out) + return 0 + try: + scanned, hits = scan(root, secret) + except Exception as error: + print(f"scan failed with {type(error).__name__}, treating the results as unsafe", file=out) + return 1 + for hit in hits: + print(f"secret found: {hit.location} ({hit.form})", file=out) + if hits: + print(f"{len(hits)} copies of the secret under {root}, refusing to upload", file=out) + return 1 + print(f"no copy of the secret in {scanned} files under {root}", file=out) + return 0 + + +if __name__ == "__main__": + sys.exit(main(tuple(sys.argv[1:]), os.environ, sys.stdout)) diff --git a/.github/workflows/test-integration.yml b/.github/workflows/test-integration.yml new file mode 100644 index 00000000000..0c5b70a67fe --- /dev/null +++ b/.github/workflows/test-integration.yml @@ -0,0 +1,199 @@ +name: integration + +on: + pull_request: + types: [labeled] + schedule: + - cron: "5 8-20/3 * * 1-6" + timezone: America/Los_Angeles + workflow_dispatch: + inputs: + suite: + description: Integration group to run + type: choice + options: + - all + - providers + - extensions + - accounting + - management + - management-replica + - database + - database-replica + - mcp + - security + - cost + - sdk + - browser + default: all + workers: + description: Workers per group, blank keeps each group's default + type: string + default: "" + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-${{ github.event.label.name }}-${{ inputs.suite }}-${{ inputs.workers }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +jobs: + integration: + name: integration ${{ matrix.suite }} + if: github.event_name != 'pull_request' || github.event.label.name == 'run-ci' + environment: integration-license + runs-on: ${{ fromJSON('{"providers":"ubuntu-latest-64-cores","extensions":"ubuntu-latest-64-cores","accounting":"ubuntu-latest-32-cores","management":"ubuntu-latest-32-cores","management-replica":"ubuntu-latest-32-cores"}')[matrix.suite] || 'ubuntu-latest-16-cores' }} + timeout-minutes: 60 + strategy: + fail-fast: false + matrix: + suite: ${{ fromJSON((inputs.suite || 'all') == 'all' && '["providers","extensions","accounting","management","management-replica","database","database-replica","mcp","security","cost","sdk","browser"]' || format('["{0}"]', inputs.suite)) }} + env: + UV_PYTHON: "3.12" + INTEGRATION_WORKERS: ${{ inputs.workers || fromJSON('{"providers":"32","extensions":"32","accounting":"16","management":"16","management-replica":"16","cost":"16","mcp":"8","security":"8","database":"4","database-replica":"4"}')[matrix.suite] || '' }} + services: + postgres: + image: postgres:16@sha256:e17e86066e5ef83e0952a9347f5c792b7ece00972e2aa787a6986f471b3dd3d5 + command: -c max_connections=1000 -c shared_preload_libraries=pg_stat_statements -c pg_stat_statements.track=all -c pg_stat_statements.max=20000 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: circle_test + ports: + - 5432:5432 + options: >- + --shm-size 1g + --health-cmd "pg_isready -U postgres" + --health-interval 5s + --health-timeout 5s + --health-retries 20 + redis: + image: redis:7-alpine@sha256:7aec734b2bb298a1d769fd8729f13b8514a41bf90fcdd1f38ec52267fbaa8ee6 + ports: + - 6379:6379 + options: >- + --health-cmd "redis-cli ping" + --health-interval 5s + --health-timeout 5s + --health-retries 20 + steps: + - uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0 + with: + persist-credentials: false + + - name: Set up Python + timeout-minutes: 3 + uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0 + with: + python-version: ${{ env.UV_PYTHON }} + + - name: Set up uv + timeout-minutes: 3 + uses: ./.github/actions/setup-uv-with-retries + with: + version: "0.10.9" + + - name: Cache the Rust build + timeout-minutes: 5 + uses: ./.github/actions/cache-cargo-build + + - name: Cache Prisma binaries + timeout-minutes: 5 + uses: ./.github/actions/cache-prisma-binaries + + - name: Install dependencies + timeout-minutes: 20 + run: .github/scripts/uv_sync_with_retries.sh --frozen --all-groups --all-extras + + - name: Install redis-server 7.2.16 + timeout-minutes: 3 + run: | + mkdir -p "$RUNNER_TEMP/redis-bin" + cid="$(docker create redis:7.2.16@sha256:0637954999d01b7c9ce9167db2da50656e2590d3b884f1c600c5f63bb6e6773c)" + docker cp "${cid}:/usr/local/bin/redis-server" "$RUNNER_TEMP/redis-bin/redis-server" + docker rm "$cid" + "$RUNNER_TEMP/redis-bin/redis-server" --version | grep -q 'v=7.2.16' + echo "$RUNNER_TEMP/redis-bin" >> "$GITHUB_PATH" + + - name: Install MCP SDK1 peer + if: matrix.suite == 'mcp' + timeout-minutes: 5 + run: | + uv venv --python 3.12 .venv-mcp-peer + uv pip install --no-config --exclude-newer "3 days" --python .venv-mcp-peer 'mcp==1.28.1' 'langchain-mcp-adapters==0.2.1' + echo "MCP_TEST_PEER_PYTHON=$PWD/.venv-mcp-peer/bin/python" >> "$GITHUB_ENV" + + - name: Set up Node.js + if: matrix.suite == 'browser' + timeout-minutes: 5 + uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0 + with: + node-version-file: ui/litellm-dashboard/.nvmrc + cache: "npm" + cache-dependency-path: | + ui/litellm-dashboard/package-lock.json + tests/e2e/ui/package-lock.json + + - name: Install browser dependencies and build the dashboard + if: matrix.suite == 'browser' + timeout-minutes: 20 + run: | + (cd ui/litellm-dashboard && npm ci) + (cd tests/e2e/ui && npm ci) + sudo env PATH="$PATH" DEBIAN_FRONTEND=noninteractive \ + node tests/e2e/ui/node_modules/@playwright/test/cli.js install-deps chromium + node tests/e2e/ui/node_modules/@playwright/test/cli.js install chromium + (cd ui/litellm-dashboard && NEXT_TELEMETRY_DISABLED=1 npm run build) + + - name: Run integration contracts + timeout-minutes: 45 + env: + SUITE: ${{ matrix.suite }} + INTEGRATION_POSTGRES_CONTAINER: ${{ job.services.postgres.id }} + INTEGRATION_REDIS_CONTAINER: ${{ job.services.redis.id }} + LITELLM_LICENSE: ${{ secrets.LITELLM_LICENSE }} + run: | + case "$SUITE" in + *-replica) bash .circleci/scripts/run_integration.sh "${SUITE%-replica}" replica ;; + *) bash .circleci/scripts/run_integration.sh "$SUITE" ;; + esac + + - name: Verify every case ran exactly once + if: ${{ !cancelled() && matrix.suite != 'browser' }} + timeout-minutes: 2 + run: | + record="$(find test-results -mindepth 2 -maxdepth 2 -name execution.json -print -quit)" + test -n "$record" + mkdir -p "$RUNNER_TEMP/shards/0" + cp "$record" "$RUNNER_TEMP/shards/0/execution.json" + .venv/bin/python -m tests.integration._support.sharding "$RUNNER_TEMP/shards" --shards 1 + + - name: Report MCP coverage + if: ${{ !cancelled() && matrix.suite == 'mcp' }} + timeout-minutes: 5 + run: | + coverage_dir=test-results/integration-mcp/coverage + test -f "$coverage_dir/coverage.txt" && exit 0 + export COVERAGE_FILE="$PWD/$coverage_dir/data" + .venv/bin/python -m coverage combine --rcfile=tests/integration/mcp_coverage.toml + .venv/bin/python -m coverage report --rcfile=tests/integration/mcp_coverage.toml > "$coverage_dir/coverage.txt" + .venv/bin/python -m coverage html --rcfile=tests/integration/mcp_coverage.toml -d "$coverage_dir/html" + tail -n 1 "$coverage_dir/coverage.txt" + + - name: Check results for the license + id: secret-scan + if: ${{ !cancelled() }} + timeout-minutes: 5 + env: + SCANNED_SECRET: ${{ secrets.LITELLM_LICENSE }} + run: python .github/scripts/assert_secret_absent.py test-results + + - name: Upload results + if: ${{ !cancelled() && steps.secret-scan.outcome == 'success' }} + timeout-minutes: 10 + uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4.6.1 + with: + name: integration-${{ matrix.suite }}-${{ github.run_id }}-${{ github.run_attempt }} + path: test-results/ + retention-days: 14 diff --git a/tests/integration/AGENTS.md b/tests/integration/AGENTS.md index 5bdc538b2d9..e5068d24e88 100644 --- a/tests/integration/AGENTS.md +++ b/tests/integration/AGENTS.md @@ -27,8 +27,11 @@ tests. A product bug the test exposes is `pytest.skip("BUG: ")` at the fix in the test and not a deletion. Needs no network, proxy, DB or Redis: `tests/unit` CircleCI's integration groups run every file here except the OCI and sandbox tests, which no CI runs, and -the files in `GITHUB_FILES` in `run.py`. CircleCI runs on main, not on pull requests, so a new file here -first runs after its PR merges. Wanting a file to run before merge is no reason to change CI, and a new +the files in `GITHUB_FILES` in `run.py`. `test-integration.yml` runs the same groups through the same +`run_integration.sh` on GitHub Actions, on main every three hours from 8am to 8pm Pacific Monday to Saturday, +and on a pull request when someone adds the `run-ci` label. Neither runs every pull request, so a new file here +first runs on main after its PR merges, or earlier if the PR gets `run-ci`. Wanting a file to run before merge +is no reason to change CI, and a new dedicated workflow for it is the same mistake as a shared shard. Write the file, leave `GITHUB_FILES` and every workflow alone, and tell the user it first runs on main. `GITHUB_FILES` is only for a file that needs what CircleCI's groups cannot give it, like the images `image-scan.yml` builds or the plain pytest diff --git a/tests/integration/README.md b/tests/integration/README.md index c32fda2f944..c5d52922de6 100644 --- a/tests/integration/README.md +++ b/tests/integration/README.md @@ -1,6 +1,6 @@ # Integration contracts -These tests exercise a running gateway, PostgreSQL and Redis with an owned local upstream. CircleCI owns this suite. Tests are grouped by behavior, with no automatic test retries or fallback to paid provider calls +These tests exercise a running gateway, PostgreSQL and Redis with an owned local upstream. CircleCI owns this suite, and `.github/workflows/test-integration.yml` runs the same groups through `run_integration.sh` on GitHub Actions for `run-ci` pull requests and scheduled main runs. Tests are grouped by behavior, with no automatic test retries or fallback to paid provider calls The ROI database contracts in `database/test_roi_observed.py` run as plain pytest outside `run_integration.sh` in CircleCI's `roi-database` Postgres job. The job uploads coverage with the `roi-postgres` flag. These contracts own temporary databases and script only the external provider transport diff --git a/tests/unit/test_assert_secret_absent.py b/tests/unit/test_assert_secret_absent.py new file mode 100644 index 00000000000..240229c01dc --- /dev/null +++ b/tests/unit/test_assert_secret_absent.py @@ -0,0 +1,124 @@ +import base64 +import importlib.util +import io +import sys +import urllib.parse +import zipfile +from collections.abc import Callable, Mapping +from itertools import chain, product +from pathlib import Path +from types import MappingProxyType +from typing import Final + +import pytest + +_REPO_ROOT: Final = Path(__file__).resolve().parents[2] +_MODULE_PATH: Final = _REPO_ROOT / ".github" / "scripts" / "assert_secret_absent.py" +_spec: Final = importlib.util.spec_from_file_location("assert_secret_absent", _MODULE_PATH) +scanner: Final = importlib.util.module_from_spec(_spec) +sys.modules[_spec.name] = scanner +_spec.loader.exec_module(scanner) + +SECRET: Final = "lic/ense+KEY:9f8e~~??>>~?7d6c5b4a3210-zz" +PREFIXES: Final = ("", "x", "xy") +ENCODERS: Final = (base64.b64encode, base64.urlsafe_b64encode) + + +def _zip(members: Mapping[str, bytes], compression: int = zipfile.ZIP_DEFLATED) -> bytes: + buffer: Final = io.BytesIO() + with zipfile.ZipFile(buffer, "w", compression) as archive: + for name, data in members.items(): + archive.writestr(name, data) + return buffer.getvalue() + + +def _blob(prefix: str) -> bytes: + return f"{prefix}{SECRET}tail".encode() + + +def _planted_forms() -> tuple[str, ...]: + encoded: Final = tuple(encode(_blob(prefix)).decode() for encode, prefix in product(ENCODERS, PREFIXES)) + return (SECRET, urllib.parse.quote(SECRET, safe=""), *encoded) + + +def _assert_nothing_leaked(output: str) -> None: + windows: Final = frozenset( + chain.from_iterable((form[i : i + 8] for i in range(len(form) - 7)) for form in _planted_forms()) + ) + assert not [window for window in windows if window in output] + + +def _run(root: Path, secret: str = SECRET) -> tuple[int, str]: + out: Final = io.StringIO() + code: Final = scanner.main((str(root),), {scanner.SECRET_VARIABLE: secret}, out) + return code, out.getvalue() + + +def _encoded_blob(prefix: str, encode: Callable[[bytes], bytes]) -> bytes: + return b"trace " + encode(_blob(prefix)) + b" end" + + +QUOTED: Final = urllib.parse.quote(SECRET, safe="") +PLACEMENTS: Final = MappingProxyType( + { + "raw in a log": {"proxy.log": f"boot with key {SECRET} ok".encode()}, + "url-encoded in a url": {"upstream.log": f"GET /verify_license/{QUOTED}".encode()}, + "base64 aligned": {"a.json": _encoded_blob("", base64.b64encode)}, + "base64 one byte in": {"a.json": _encoded_blob("x", base64.b64encode)}, + "base64 two bytes in": {"a.json": _encoded_blob("xy", base64.b64encode)}, + "base64url two bytes in": {"a.json": _encoded_blob("xy", base64.urlsafe_b64encode)}, + "inside a zip member": {"trace.zip": _zip({"network.json": f'{{"auth": "{SECRET}"}}'.encode()})}, + "inside a nested zip": {"outer.zip": _zip({"inner.zip": _zip({"env.txt": SECRET.encode()})})}, + "named after it in a nested zip": { + "outer.zip": _zip({"inner.zip": _zip({f"dump-{QUOTED}.txt": SECRET.encode()})}) + }, + "in a file name": {f"run-{QUOTED}.log": b"nothing inside"}, + } +) + + +@pytest.mark.parametrize("placement", PLACEMENTS) +def test_every_planted_copy_blocks_the_upload_without_printing_the_secret(tmp_path: Path, placement: str) -> None: + worker: Final = tmp_path / "gw0" + worker.mkdir() + for name, data in PLACEMENTS[placement].items(): + (worker / name).write_bytes(data) + code, output = _run(tmp_path) + assert code == 1 + assert "secret found:" in output + _assert_nothing_leaked(output) + + +def test_clean_results_pass_and_count_every_file(tmp_path: Path) -> None: + (tmp_path / "junit.xml").write_text("") + (tmp_path / "gw0").mkdir() + (tmp_path / "gw0" / "proxy.log").write_text("LITELLM_LICENSE is not set") + code, output = _run(tmp_path) + assert code == 0 + assert "no copy of the secret in 2 files" in output + + +def test_an_unset_secret_has_nothing_to_find(tmp_path: Path) -> None: + (tmp_path / "proxy.log").write_text(SECRET) + assert _run(tmp_path, secret="")[0] == 0 + + +def test_a_symlinked_directory_fails_closed(tmp_path: Path) -> None: + outside: Final = tmp_path / "outside" + outside.mkdir() + results: Final = tmp_path / "results" + results.mkdir() + (results / "linked").symlink_to(outside, target_is_directory=True) + code, output = _run(results) + assert code == 1 + assert "directory symlink" in output + + +def test_an_unreadable_archive_fails_without_echoing_its_contents(tmp_path: Path) -> None: + archive: Final = _zip({"env.txt": f"LITELLM_LICENSE={SECRET}".encode()}, zipfile.ZIP_STORED) + at: Final = archive.index(SECRET.encode()) + (tmp_path / "trace.zip").write_bytes(archive[:at] + bytes([archive[at] ^ 0xFF]) + archive[at + 1 :]) + code, output = _run(tmp_path) + assert code == 1 + assert "scan failed with BadZipFile" in output + _assert_nothing_leaked(output)