mirror of
https://github.com/shankar0123/certctl.git
synced 2026-06-07 16:21:30 +00:00
Bundle J follow-up: fix CI staticcheck QF1002 in acme_failure_test.go
CI on the Bundle J merge (18e46f0) failed at golangci-lint:
internal/connector/issuer/acme/acme_failure_test.go:244:3:
QF1002: could use tagged switch on r.URL.Path (staticcheck)
TestGetRenewalInfo_ARI5xx had a switch{} with case r.URL.Path == ...
which staticcheck QF1002 flags as a quick-fix candidate (use tagged
switch instead). The function also accumulated dead ts/ts2/ts3 setup
from earlier iteration — only ts3 was actually used by the assertion.
This commit:
- Collapses the 3-server scaffold into a single ts using if/return
instead of switch (sidesteps QF1002 entirely + removes ~25 LoC of
dead code)
- Verifies via 'staticcheck -checks all' (which includes QF*) that
the package is clean except for pre-existing ST1000 hits in
acme.go/ari.go/dns.go/profile.go (out of scope for this fix)
Verification:
staticcheck -checks all internal/connector/issuer/acme/... clean
(excluding 4 pre-existing ST1000 'missing package comment')
go vet ./internal/connector/issuer/acme/... clean
go test -short ./internal/connector/issuer/acme/... PASS
Coverage unchanged at 55.6% (the test logic was already correct;
this commit only removes lint friction).
This commit is contained in:
@@ -238,16 +238,17 @@ func TestGetRenewalInfo_DirectoryUnreachable(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestGetRenewalInfo_ARI5xx pins the non-2xx (other than 404) branch.
|
||||
// TestGetRenewalInfo_ARI5xx pins the non-2xx (other than 404) branch. The
|
||||
// directory handler emits an absolute URL pointing back at the same test
|
||||
// server's /renewalInfo path, which 5xx's all requests.
|
||||
func TestGetRenewalInfo_ARI5xx(t *testing.T) {
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch {
|
||||
case r.URL.Path == "/directory":
|
||||
if r.URL.Path == "/directory" {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = io.WriteString(w, `{"renewalInfo":"/acme/renewalInfo"}`)
|
||||
default:
|
||||
http.Error(w, "boom", http.StatusInternalServerError)
|
||||
fmt.Fprintf(w, `{"renewalInfo":%q}`, "http://"+r.Host+"/renewalInfo")
|
||||
return
|
||||
}
|
||||
http.Error(w, "boom", http.StatusInternalServerError)
|
||||
}))
|
||||
defer ts.Close()
|
||||
|
||||
@@ -257,37 +258,8 @@ func TestGetRenewalInfo_ARI5xx(t *testing.T) {
|
||||
ChallengeType: "http-01",
|
||||
ARIEnabled: true,
|
||||
})
|
||||
// Rewrite the renewalInfo URL to point at the test server so the relative
|
||||
// path "/acme/renewalInfo" resolves against ts.URL.
|
||||
c.config.DirectoryURL = ts.URL + "/directory"
|
||||
certPEM := makeTestCertPEM(t)
|
||||
|
||||
// Override the directory response to advertise an absolute URL on ts.
|
||||
ts.Close()
|
||||
ts2 := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch {
|
||||
case strings.HasSuffix(r.URL.Path, "/directory"):
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
fmt.Fprintf(w, `{"renewalInfo":%q}`, r.Host) // bogus but parseable
|
||||
// Better: emit absolute URL pointing at our own /renewalInfo.
|
||||
}
|
||||
}))
|
||||
ts2.Close()
|
||||
|
||||
// Simpler approach: have the directory handler return an absolute URL
|
||||
// pointing at ts3 (which 5xx's all renewalInfo requests).
|
||||
ts3 := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
// Catch-all 500 for any path other than /directory
|
||||
if r.URL.Path == "/directory" {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
fmt.Fprintf(w, `{"renewalInfo":%q}`, "http://"+r.Host+"/renewalInfo")
|
||||
return
|
||||
}
|
||||
http.Error(w, "boom", http.StatusInternalServerError)
|
||||
}))
|
||||
defer ts3.Close()
|
||||
c.config.DirectoryURL = ts3.URL + "/directory"
|
||||
|
||||
_, err := c.GetRenewalInfo(context.Background(), certPEM)
|
||||
if err == nil {
|
||||
t.Fatal("expected ARI 5xx to error")
|
||||
|
||||
Reference in New Issue
Block a user