@@ -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