Skip to content

Commit 4688ae8

Browse files
eran132claude
andcommitted
fix: address review feedback on VEX status code error
- Replace the misleading "did not receive 2xx status code" message with "unexpected status code %d from %s" using vexUrl.Redacted(), per maintainer suggestion. Avoids the 200-vs-2xx wording confusion and redacts any credentials in the URL. - Simplify the test to a single string-typed wantErr field (matching the pkg/x/json test style) instead of separate wantErr/wantErrMsg fields, and assert the error message for the incompatible-VEX case too. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 21ddd76 commit 4688ae8

2 files changed

Lines changed: 11 additions & 18 deletions

File tree

pkg/vex/sbomref.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func retrieveExternalVEXDocument(ctx context.Context, vexUrl *url.URL, report *t
8484
defer res.Body.Close()
8585

8686
if res.StatusCode != http.StatusOK {
87-
return nil, xerrors.Errorf("did not receive 2xx status code: %d", res.StatusCode)
87+
return nil, xerrors.Errorf("unexpected status code %d from %s", res.StatusCode, vexUrl.Redacted())
8888
}
8989

9090
val, err := io.ReadAll(res.Body)

pkg/vex/sbomref_test.go

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -79,45 +79,38 @@ func TestRetrieveExternalVEXDocuments(t *testing.T) {
7979
t.Cleanup(s.Close)
8080

8181
tests := []struct {
82-
name string
83-
input *types.Report
84-
wantVEXes int
85-
wantErr bool
86-
wantErrMsg string
82+
name string
83+
input *types.Report
84+
wantVEXes int
85+
wantErr string
8786
}{
8887
{
8988
name: "external vex retrieval",
9089
input: setupTestReport(s, vexExternalRef),
9190
wantVEXes: 1,
92-
wantErr: false,
9391
},
9492
{
9593
name: "incompatible external vex",
9694
input: setupTestReport(s, vexUnknown),
97-
wantErr: true,
95+
wantErr: "unable to load VEX from external reference",
9896
},
9997
{
100-
name: "vex not found",
101-
input: setupTestReport(s, vexNotFound),
102-
wantErr: true,
103-
wantErrMsg: "did not receive 2xx status code: 404",
98+
name: "vex not found",
99+
input: setupTestReport(s, vexNotFound),
100+
wantErr: "unexpected status code 404",
104101
},
105102
{
106103
name: "no external reference",
107104
input: setupEmptyTestReport(),
108105
wantVEXes: 0,
109-
wantErr: false,
110106
},
111107
}
112108

113109
for _, tt := range tests {
114110
t.Run(tt.name, func(t *testing.T) {
115111
got, err := vex.NewSBOMReferenceSet(tt.input)
116-
if tt.wantErr {
117-
require.Error(t, err)
118-
if tt.wantErrMsg != "" {
119-
require.ErrorContains(t, err, tt.wantErrMsg)
120-
}
112+
if tt.wantErr != "" {
113+
require.ErrorContains(t, err, tt.wantErr)
121114
return
122115
}
123116
require.NoError(t, err)

0 commit comments

Comments
 (0)