Skip to content

Commit c57b3be

Browse files
committed
Implement hasPublicVulnerabilityDisclosure check for OSPS-VM-04
- Added function to check if security advisory publishing is enabled - Uses SecurityAdvisories != nil to detect feature availability - Added comprehensive test coverage with HTTP mocking - Positioned SecurityAdvisory struct below RestData per code review Signed-off-by: Zohayb Bhatti <zohayb23@gmail.com>
1 parent daf8479 commit c57b3be

File tree

3 files changed

+39
-49
lines changed

3 files changed

+39
-49
lines changed

data/rest-data.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,6 @@ type HttpClient interface {
1919
Do(req *http.Request) (*http.Response, error)
2020
}
2121

22-
type SecurityAdvisory struct {
23-
GhsaId string `json:"ghsa_id"`
24-
CveId string `json:"cve_id"`
25-
Summary string `json:"summary"`
26-
Severity string `json:"severity"`
27-
State string `json:"state"`
28-
PublishedAt string `json:"published_at"`
29-
}
30-
3122
type RestData struct {
3223
owner string
3324
repo string
@@ -76,6 +67,15 @@ type WorkflowPermissions struct {
7667
CanApprovePullRequest bool `json:"can_approve_pull_request_reviews"`
7768
}
7869

70+
type SecurityAdvisory struct {
71+
GhsaId string `json:"ghsa_id"`
72+
CveId string `json:"cve_id"`
73+
Summary string `json:"summary"`
74+
Severity string `json:"severity"`
75+
State string `json:"state"`
76+
PublishedAt string `json:"published_at"`
77+
}
78+
7979
var APIBase = "https://api.github.com"
8080

8181
func (r *RestData) Setup() error {

evaluation_plans/osps/vuln_management/steps.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package vuln_management
22

33
import (
4-
"fmt"
54
"slices"
65

76
"github.com/ossf/gemara/layer4"
@@ -68,15 +67,11 @@ func hasPublicVulnerabilityDisclosure(payloadData any, _ map[string]*layer4.Chan
6867
return layer4.Unknown, message
6968
}
7069

71-
advisoryCount := len(data.SecurityAdvisories)
72-
if advisoryCount > 0 {
73-
if advisoryCount == 1 {
74-
return layer4.Passed, "Found 1 published security advisory"
75-
}
76-
return layer4.Passed, fmt.Sprintf("Found %d published security advisories", advisoryCount)
70+
if data.SecurityAdvisories != nil {
71+
return layer4.Passed, "Security advisory publishing is enabled"
7772
}
7873

79-
return layer4.Failed, "No published security advisories found"
74+
return layer4.Failed, "Security advisory publishing is not enabled"
8075
}
8176

8277
func hasPrivateVulnerabilityReporting(payloadData any, _ map[string]*layer4.Change) (result layer4.Result, message string) {

evaluation_plans/osps/vuln_management/steps_test.go

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -169,67 +169,57 @@ func TestHasPublicVulnerabilityDisclosure(t *testing.T) {
169169
tests := []struct {
170170
name string
171171
payloadData any
172+
apiResponse []byte
173+
apiError error
172174
expectedResult layer4.Result
173175
expectedMessage string
174176
}{
175177
{
176-
name: "One published security advisory",
178+
name: "Security advisory publishing is enabled with advisories",
177179
expectedResult: layer4.Passed,
178-
expectedMessage: "Found 1 published security advisory",
180+
expectedMessage: "Security advisory publishing is enabled",
179181
payloadData: data.Payload{
180182
RestData: &data.RestData{
181183
SecurityAdvisories: []data.SecurityAdvisory{
182184
{
183-
GhsaId: "GHSA-xxxx-xxxx-xxxx",
184-
Summary: "Test advisory",
185-
State: "published",
186-
PublishedAt: "2024-01-01T00:00:00Z",
185+
GhsaId: "GHSA-1234-5678-9012",
186+
CveId: "CVE-2024-12345",
187+
Summary: "Test advisory",
188+
Severity: "high",
189+
State: "published",
187190
},
188191
},
189192
},
190193
GraphqlRepoData: &data.GraphqlRepoData{},
191194
},
195+
apiResponse: []byte(`[{"ghsa_id":"GHSA-1234-5678-9012","cve_id":"CVE-2024-12345","summary":"Test advisory","severity":"high","state":"published","published_at":"2024-01-01T00:00:00Z"}]`),
196+
apiError: nil,
192197
},
193198
{
194-
name: "Multiple published security advisories",
199+
name: "Security advisory publishing is enabled with no advisories",
195200
expectedResult: layer4.Passed,
196-
expectedMessage: "Found 3 published security advisories",
201+
expectedMessage: "Security advisory publishing is enabled",
197202
payloadData: data.Payload{
198203
RestData: &data.RestData{
199-
SecurityAdvisories: []data.SecurityAdvisory{
200-
{
201-
GhsaId: "GHSA-xxxx-xxxx-xxxx",
202-
Summary: "First advisory",
203-
State: "published",
204-
PublishedAt: "2024-01-01T00:00:00Z",
205-
},
206-
{
207-
GhsaId: "GHSA-yyyy-yyyy-yyyy",
208-
Summary: "Second advisory",
209-
State: "published",
210-
PublishedAt: "2024-02-01T00:00:00Z",
211-
},
212-
{
213-
GhsaId: "GHSA-zzzz-zzzz-zzzz",
214-
Summary: "Third advisory",
215-
State: "published",
216-
PublishedAt: "2024-03-01T00:00:00Z",
217-
},
218-
},
204+
SecurityAdvisories: []data.SecurityAdvisory{},
219205
},
220206
GraphqlRepoData: &data.GraphqlRepoData{},
221207
},
208+
apiResponse: []byte(`[]`),
209+
apiError: nil,
222210
},
223211
{
224-
name: "No published security advisories",
212+
name: "Security advisory publishing is not enabled",
225213
expectedResult: layer4.Failed,
226-
expectedMessage: "No published security advisories found",
214+
expectedMessage: "Security advisory publishing is not enabled",
227215
payloadData: data.Payload{
228216
RestData: &data.RestData{
229-
SecurityAdvisories: []data.SecurityAdvisory{},
217+
SecurityAdvisories: nil,
230218
},
231219
GraphqlRepoData: &data.GraphqlRepoData{},
232220
},
221+
apiResponse: []byte(`[]`),
222+
apiError: nil,
233223
},
234224
{
235225
name: "Invalid payload",
@@ -241,6 +231,11 @@ func TestHasPublicVulnerabilityDisclosure(t *testing.T) {
241231

242232
for _, test := range tests {
243233
t.Run(test.name, func(t *testing.T) {
234+
if payload, ok := test.payloadData.(data.Payload); ok {
235+
payload = data.NewPayloadWithHTTPMock(payload, test.apiResponse, 200, test.apiError)
236+
test.payloadData = payload
237+
}
238+
244239
result, message := hasPublicVulnerabilityDisclosure(test.payloadData, nil)
245240
assert.Equal(t, test.expectedResult, result)
246241
assert.Equal(t, test.expectedMessage, message)
@@ -370,4 +365,4 @@ func TestHasPrivateVulnerabilityReporting(t *testing.T) {
370365
assert.Equal(t, test.expectedMessage, message)
371366
})
372367
}
373-
}
368+
}

0 commit comments

Comments
 (0)