Repository navigation
test: refuse real SSH and HTTP connections in tests - #12833
Merged
Merged
Conversation
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
Contributor
Image size
Compressed is what |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.cloudandhttps://8.8.8.8from CI. These tests were slow, and their result depended on the network.Changes
tests/TestCase.phprefuses:Process::fake()handler matches (tests/Support/NoRealSshProcessFactory.php)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:
ssh -O check,ssh -O exit), which use only a local socketsshorscpin a directory undersys_get_temp_dir()onPATHFixed the 14 tests that reached a real server:
CrossTeamIdorServerProjectTestdeploy cancelCleanupCancelledDeploymentis removed.SshConnectionOptionsTest(2 tests)10.0.0.5ServerImageScanningTestprovider flowServerTransferApiTestrunning deploymenthttps://8.8.8.8GithubRunnerFlowTestserver deletionGitSourceHttpSafetyTest(7 tests),HttpConnectionRetryTest(1 test)MockHandlerand to their local socket serverAGENTS.mddescribes the rule and the two allowed cases.Limits
SftpConnectionstartssshwithproc_open(), not withProcess. The guard does not cover it. Its test uses a stub.Httpclient, for example a direct Guzzle client or an SDK, are not covered.Verification
Feature,Unit,Golden, 8 processes): 20,819 passed.scripts/test-ratchet: OK, 0 new failures.