Skip to content

test: refuse real SSH and HTTP connections in tests - #12833

Merged
andrasbacsai merged 1 commit into
mainfrom
fix/block-real-ssh-http-in-tests
Dec 5, 2026
Merged

andrasbacsai merged 1 commit into
mainfrom
fix/block-real-ssh-http-in-tests

Conversation

@andrasbacsai

Copy link
Copy Markdown
Member

Why

Some tests connected to real servers. They waited for SSH timeouts, scanned host keys of random IP addresses, and sent requests to api.hetzner.cloud and https://8.8.8.8 from CI. These tests were slow, and their result depended on the network.

Changes

  • tests/TestCase.php refuses:

    • each SSH or SCP command that no Process::fake() handler matches (tests/Support/NoRealSshProcessFactory.php)
    • each HTTP request that no Http::fake() stub matches (Http::preventStrayRequests())
  • A test also fails when the code under test catches the refused connection (assertPostConditions()). Without this, the app code caught the error and the test passed.

  • These commands stay allowed, because they do not leave the machine:

    • multiplexing control commands (ssh -O check, ssh -O exit), which use only a local socket
    • a stub ssh or scp in a directory under sys_get_temp_dir() on PATH
  • Fixed the 14 tests that reached a real server:

    Test Fix CI before Local after
    CrossTeamIdorServerProjectTest deploy cancel Fakes the remote commands. Asserts that a command reaches the deployment server and that no command reaches the build server of the other team. This check fails when the team scope of CleanupCancelledDeployment is removed. 76.4 s 0.2 s
    SshConnectionOptionsTest (2 tests) Turns off host key checking, so that building the command does not scan the host key of 10.0.0.5 30.4 s 0.6 s
    ServerImageScanningTest provider flow Fakes the Hetzner status request and the SSH validation 20.4 s 0.3 s
    ServerTransferApiTest running deployment Fakes the import check of the target instead of a request to https://8.8.8.8 - -
    GithubRunnerFlowTest server deletion Fakes the cleanup commands - -
    GitSourceHttpSafetyTest (7 tests), HttpConnectionRetryTest (1 test) Allows the requests to their MockHandler and to their local socket server - -
  • AGENTS.md describes the rule and the two allowed cases.

Limits

  • SftpConnection starts ssh with proc_open(), not with Process. The guard does not cover it. Its test uses a stub.
  • HTTP clients that do not use the Laravel Http client, for example a direct Guzzle client or an SDK, are not covered.

Verification

  • Full SQLite suite (Feature,Unit,Golden, 8 processes): 20,819 passed. scripts/test-ratchet: OK, 0 new failures.
  • First run with the guard: 130 failures. Then I allowed the multiplexing control commands and the stubs: 14 failures, all fixed here.

The base test case now refuses each SSH or SCP command that no
Process::fake() handler matches, and each HTTP request that no
Http::fake() stub matches. A test also fails when the code under test
catches the refused connection. Multiplexing control commands
(ssh -O check, ssh -O exit) and stub ssh binaries in a temporary
directory on PATH stay allowed, because they do not leave the machine.

Fix the 14 tests that reached a real server:
- deploy cancel IDOR test: fake the remote commands and assert that a
  command reaches the deployment server and none reaches the build
  server of the other team (76 s to 0.2 s)
- SSH option tests: turn off host key checking, so that building the
  command does not scan the host key of 10.0.0.5 (30 s to 0.6 s)
- provider flow image scan test: fake the Hetzner status request and
  the SSH validation (20 s to 0.3 s)
- server transfer test: fake the import check of the target instead of
  a request to https://8.8.8.8
- GitHub runner deletion test: fake the cleanup commands
- Git source redirect tests and the timeout retry test: allow the
  requests to their MockHandler and local socket server
@github-actions

github-actions Bot commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

Image size

pr-12833 compared with latest (4.7.10).

Platform Compressed pr-12833 Compressed latest Change On disk pr-12833 On disk latest Change
linux/amd64 170.32 MB 166.69 MB +3.62 MB (+2.2 %) 875.83 MB 863.20 MB +12.63 MB (+1.5 %)
linux/arm64 167.73 MB 163.79 MB +3.95 MB (+2.4 %) 875.37 MB 862.22 MB +13.15 MB (+1.5 %)

Compressed is what docker pull downloads, the CONTENT SIZE of the platform in docker image ls --tree. On disk adds the unpacked files in 4 KiB blocks of ext4, the DISK USAGE that Docker Desktop shows, as the containerd image store keeps both. Neither counts the SBOM and provenance attestations.

@andrasbacsai
andrasbacsai merged commit 245cfc6 into main Dec 5, 2026
15 checks passed
@andrasbacsai
andrasbacsai deleted the fix/block-real-ssh-http-in-tests branch December 5, 2026 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant