test(networking): remove live snyk.io call from Test_GetHTTPClient - #673
Open
rrama wants to merge 6 commits into
Open
test(networking): remove live snyk.io call from Test_GetHTTPClient#673rrama wants to merge 6 commits into
rrama wants to merge 6 commits into
Conversation
Test_GetHTTPClient made a real request to https://www.snyk.io and then asserted on the response with a non-fatal assert.Nil(t, err). When the request failed, execution continued to response.StatusCode and dereferenced a nil *http.Response, panicking the whole pkg/networking test binary and aborting every remaining test in it. Point the request at an httptest server instead, matching the ten other HTTP tests in this file, and use require.NoError so a transport failure fails this single test cleanly. TLS and CA handling stay covered by Test_GetHTTPClient_EmptyCAs, so no coverage is lost. The test now runs without network access and completes in 0.00s instead of ~0.4s. Co-authored-by: Cursor <cursoragent@cursor.com>
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
4 tasks
rrama
added a commit
that referenced
this pull request
Jul 30, 2026
Consolidates the duplicate cloud-setup notes into a single AGENTS.md, keeping the parallel branch's more precise diagnosis of the networking test: the live GET to www.snyk.io 301-redirects to the bare snyk.io apex, which is why it fails only when that apex is missing from the allowlist. Describes that test as network-gated rather than a product defect, and points at PR #673, which replaces the live call with an httptest server and makes the caveat moot. Replaces the fixed reachable/blocked host list with guidance to probe egress directly, since the allowlist changes between runs. Co-authored-by: Cursor <cursoragent@cursor.com>
4 tasks
Switch remaining response-dereference guards from non-fatal testify asserts to require, so transport failures can’t nil-deref and abort the pkg/networking test binary. Also close response bodies in the affected tests to keep behavior consistent with the rest of the file. Co-authored-by: Ben Durrans <Benjamin.Durrans@snyk.io>
Close response bodies in tests that previously ignored the returned *http.Response, to avoid leaking keep-alive connections until GC and to align with the new response-handling pattern in this file. Co-authored-by: Ben Durrans <Benjamin.Durrans@snyk.io>
Add t.Cleanup(server.Close) for httptest servers in the updated tests so listeners don’t stay open until process exit. Co-authored-by: Ben Durrans <Benjamin.Durrans@snyk.io>
rrama
commented
Aug 3, 2026
| } | ||
| }) | ||
| server := httptest.NewServer(handler) | ||
| t.Cleanup(server.Close) |
Contributor
Author
There was a problem hiding this comment.
I acknowledge that in Go 1.27 we can move to httptest.NewTestServer(t, handler) and this cleanup will be handled automatically. (Along with the other advantages NewTestServer brings)
But we aren't there just yet.
Use defer server.Close() in the touched networking tests to match existing server-cleanup style in this file. Co-authored-by: Ben Durrans <Benjamin.Durrans@snyk.io>
Use t.Cleanup(server.Close) consistently for httptest server lifecycle management within pkg/networking/networking_test.go. Co-authored-by: Ben Durrans <Benjamin.Durrans@snyk.io>
rrama
marked this pull request as ready for review
August 3, 2026 10:15
PR Reviewer Guide 🔍
|
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.
Description
Test_GetHTTPClientmade a real request tohttps://www.snyk.ioand then asserted on the response with a non-fatalassert.Nil(t, err):When the request fails,
responseisniland the next line dereferences it. That panics the entirepkg/networkingtest binary withinvalid memory address or nil pointer dereference, aborting every remaining test in the package rather than failing this one test.This reproduces deterministically anywhere
www.snyk.iois unreachable — restricted CI sandboxes, offline development, or a captive network. It was found by an agent running the suite in a network-restricted environment.Two problems, both fixed here:
require.NoErrornow stops the test at the point of failure, so a transport error fails this single test with a useful message and the rest of the package still runs.httptestserver, matching the ten other HTTP tests in this same file, all of which already usehttptest.NewServer.TLS and CA-trust behaviour remain covered by
Test_GetHTTPClient_EmptyCAs, which stands up its own TLS listener with a self-signed cert, so no coverage is lost. The test now needs no network and completes in 0.00s instead of ~0.4s.Verified that the failure mode is fixed by temporarily pointing the client at a closed port: the test now reports
FAIL ... connection refusedwith no panic, and the remaining tests in the binary still execute.Bonus: Did some similar housekeeping for other tests in the file.
Checklist
make test)pkg/networkingpasses at 89.7% coverage. One unrelated pre-existing failure exists on my machine:TestDetectProxyConfiginconnectivity_check_extension/connectivityinherits the ambientNODE_EXTRA_CA_CERTSinstead of isolating it, and passes with that variable unset. Untouched by this PR.make generate) — n/a, no mocks or API clients affectedmake lint) — 0 issuesMade with Cursor