Skip to content

Commit b467877

Browse files
leodidoona-agent
andcommitted
fix(lint): check error return values in signing package
- Check json.Encoder.Encode errors in test mock servers - Explicitly ignore resp.Body.Close error in defer context Co-authored-by: Ona <no-reply@ona.com>
1 parent ddea58c commit b467877

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

pkg/leeway/signing/attestation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ func fetchGitHubOIDCToken(ctx context.Context, audience string) (string, error)
497497
if err != nil {
498498
return "", fmt.Errorf("failed to fetch token: %w", err)
499499
}
500-
defer resp.Body.Close()
500+
defer func() { _ = resp.Body.Close() }()
501501

502502
// Check response status
503503
if resp.StatusCode != http.StatusOK {

pkg/leeway/signing/attestation_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,9 @@ func TestFetchGitHubOIDCToken(t *testing.T) {
11221122
t.Error("Missing or invalid Authorization header")
11231123
}
11241124
w.WriteHeader(http.StatusOK)
1125-
_ = json.NewEncoder(w).Encode(map[string]string{"value": "test-token-12345"})
1125+
if err := json.NewEncoder(w).Encode(map[string]string{"value": "test-token-12345"}); err != nil {
1126+
t.Errorf("Failed to encode response: %v", err)
1127+
}
11261128
}))
11271129
},
11281130
audience: "sigstore",
@@ -1155,7 +1157,9 @@ func TestFetchGitHubOIDCToken(t *testing.T) {
11551157
mockServer: func(t *testing.T) *httptest.Server {
11561158
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
11571159
w.WriteHeader(http.StatusOK)
1158-
_ = json.NewEncoder(w).Encode(map[string]string{"value": ""})
1160+
if err := json.NewEncoder(w).Encode(map[string]string{"value": ""}); err != nil {
1161+
t.Errorf("Failed to encode response: %v", err)
1162+
}
11591163
}))
11601164
},
11611165
audience: "sigstore",

0 commit comments

Comments
 (0)