Skip to content

Commit 5af994c

Browse files
committed
Merge remote-tracking branch 'origin/dev'
2 parents 4673286 + 8b1e76d commit 5af994c

File tree

11 files changed

+348
-26
lines changed

11 files changed

+348
-26
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@
181181
- [Get Violations Report Content](#get-violations-report-content)
182182
- [Delete Violations Report](#delete-violations-report)
183183
- [Get Artifact Summary](#get-artifact-summary)
184+
- [Get Artifact Scan Status](#get-artifact-scan-status)
184185
- [Get Entitlement info](#get-entitlement-info)
185186
- [XSC APIs](#xsc-apis)
186187
- [Creating XSC Service Manager](#creating-xray-service-manager)
@@ -2644,6 +2645,23 @@ artifactSummaryRequest := services.ArtifactSummaryParams{
26442645
artifactSummary, err := xrayManager.ArtifactSummary(artifactSummaryRequest)
26452646
```
26462647
2648+
#### Get Artifact Scan Status
2649+
```go
2650+
// Get the scan status of an artifact in a specific repository
2651+
repo := "example-repository"
2652+
path := "path/to/artifact"
2653+
artifactStatus, err := xrayManager.GetArtifactStatus(repo, path)
2654+
2655+
// The response contains overall status and detailed status for different scan types
2656+
if err == nil {
2657+
fmt.Printf("Overall scan status: %s\n", artifactStatus.Overall.Status)
2658+
fmt.Printf("SCA scan status: %s\n", artifactStatus.Details.Sca.Status)
2659+
fmt.Printf("Contextual Analysis status: %s\n", artifactStatus.Details.ContextualAnalysis.Status)
2660+
fmt.Printf("Exposures scan status: %s\n", artifactStatus.Details.Exposures.Status)
2661+
fmt.Printf("Violations status: %s\n", artifactStatus.Details.Violations.Status)
2662+
}
2663+
```
2664+
26472665
#### Get Entitlement Info
26482666
26492667
```go

artifactory/services/utils/tests/xray/consts.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,6 +1439,81 @@ const XscGitInfoResponse = `{"multi_scan_id": "3472b4e2-bddc-11ee-a9c9-acde48001
14391439

14401440
const XscGitInfoBadResponse = `"failed create git info request: git_repo_url field must contain value"`
14411441

1442+
const ArtifactStatusResponse = `{
1443+
"overall": {
1444+
"status": "DONE",
1445+
"time": "2023-12-01T10:00:00Z"
1446+
},
1447+
"details": {
1448+
"sca": {
1449+
"status": "DONE",
1450+
"time": "2023-12-01T10:00:00Z"
1451+
},
1452+
"contextual_analysis": {
1453+
"status": "DONE",
1454+
"time": "2023-12-01T10:00:00Z"
1455+
},
1456+
"exposures": {
1457+
"status": "NOT_SUPPORTED",
1458+
"time": "2023-12-01T10:00:00Z"
1459+
},
1460+
"violations": {
1461+
"status": "FAILED",
1462+
"time": "2023-12-01T10:00:00Z"
1463+
}
1464+
}
1465+
}`
1466+
1467+
const ArtifactStatusPendingResponse = `{
1468+
"overall": {
1469+
"status": "PENDING",
1470+
"time": "2023-12-01T09:30:00Z"
1471+
},
1472+
"details": {
1473+
"sca": {
1474+
"status": "PENDING",
1475+
"time": "2023-12-01T09:30:00Z"
1476+
},
1477+
"contextual_analysis": {
1478+
"status": "NOT_SCANNED",
1479+
"time": "2023-12-01T09:30:00Z"
1480+
},
1481+
"exposures": {
1482+
"status": "NOT_SUPPORTED",
1483+
"time": "2023-12-01T09:30:00Z"
1484+
},
1485+
"violations": {
1486+
"status": "NOT_SCANNED",
1487+
"time": "2023-12-01T09:30:00Z"
1488+
}
1489+
}
1490+
}`
1491+
1492+
const ArtifactStatusNotSupportedResponse = `{
1493+
"overall": {
1494+
"status": "NOT_SUPPORTED",
1495+
"time": "2023-12-01T11:00:00Z"
1496+
},
1497+
"details": {
1498+
"sca": {
1499+
"status": "NOT_SUPPORTED",
1500+
"time": "2023-12-01T11:00:00Z"
1501+
},
1502+
"contextual_analysis": {
1503+
"status": "NOT_SUPPORTED",
1504+
"time": "2023-12-01T11:00:00Z"
1505+
},
1506+
"exposures": {
1507+
"status": "NOT_SUPPORTED",
1508+
"time": "2023-12-01T11:00:00Z"
1509+
},
1510+
"violations": {
1511+
"status": "NOT_SUPPORTED",
1512+
"time": "2023-12-01T11:00:00Z"
1513+
}
1514+
}
1515+
}`
1516+
14421517
var GitInfoContextWithMinimalRequiredFields = xscServices.XscGitInfoContext{
14431518
Source: xscServices.CommitContext{
14441519
GitRepoHttpsCloneUrl: "https://git.jfrog.info/projects/XSC/repos/xsc-service",

artifactory/services/utils/tests/xray/server.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,41 @@ func getJasConfig(t *testing.T) func(w http.ResponseWriter, r *http.Request) {
231231
}
232232
}
233233

234+
func artifactStatusHandler(w http.ResponseWriter, r *http.Request) {
235+
if r.Method == http.MethodPost {
236+
body, err := io.ReadAll(r.Body)
237+
if err != nil {
238+
http.Error(w, err.Error(), http.StatusInternalServerError)
239+
return
240+
}
241+
242+
path, err := jsonparser.GetString(body, "path")
243+
if err != nil {
244+
http.Error(w, err.Error(), http.StatusInternalServerError)
245+
return
246+
}
247+
248+
// Return different responses based on the path to test different scenarios
249+
var response string
250+
switch path {
251+
case "path/to/pending-artifact":
252+
response = ArtifactStatusPendingResponse
253+
case "path/to/unsupported-artifact":
254+
response = ArtifactStatusNotSupportedResponse
255+
default:
256+
response = ArtifactStatusResponse
257+
}
258+
259+
_, err = fmt.Fprint(w, response)
260+
if err != nil {
261+
log.Error(err)
262+
http.Error(w, err.Error(), http.StatusInternalServerError)
263+
}
264+
return
265+
}
266+
http.Error(w, "Invalid artifact status request", http.StatusBadRequest)
267+
}
268+
234269
func enrichGetResults(t *testing.T) func(w http.ResponseWriter, r *http.Request) {
235270
return func(w http.ResponseWriter, r *http.Request) {
236271
if r.Method == http.MethodGet {
@@ -261,6 +296,7 @@ func StartXrayMockServerWithParams(t *testing.T, params MockServerParams) int {
261296
handlers["/xray/api/v1/system/version"] = xrayGetVersionHandlerFunc(t, params.XrayVersion)
262297
handlers["/api/xray/scanBuild"] = scanBuildHandler
263298
handlers["/api/v2/summary/artifact"] = artifactSummaryHandler
299+
handlers["/xray/api/v1/artifact/status"] = artifactStatusHandler
264300
handlers["/api/v1/entitlements/feature/"] = entitlementsHandler
265301
handlers["/xray/api/v1/scan/import_xml"] = enrichGetScanId(t)
266302
handlers[fmt.Sprintf("/xray/api/v1/scan/graph/%s", params.MSI)] = enrichGetResults(t)

go.mod

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/golang-jwt/jwt/v4 v4.5.2
1212
github.com/gookit/color v1.5.4
1313
github.com/jfrog/archiver/v3 v3.6.1
14-
github.com/jfrog/build-info-go v1.10.16
14+
github.com/jfrog/build-info-go v1.10.17
1515
github.com/jfrog/gofrog v1.7.6
1616
github.com/minio/sha256-simd v1.0.1
1717
github.com/stretchr/testify v1.10.0
@@ -23,11 +23,9 @@ require (
2323

2424
require (
2525
dario.cat/mergo v1.0.1 // indirect
26-
github.com/BurntSushi/toml v1.4.0 // indirect
2726
github.com/Microsoft/go-winio v0.6.2 // indirect
2827
github.com/andybalholm/brotli v1.1.1 // indirect
2928
github.com/cloudflare/circl v1.6.1 // indirect
30-
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
3129
github.com/cyphar/filepath-securejoin v0.4.1 // indirect
3230
github.com/davecgh/go-spew v1.1.1 // indirect
3331
github.com/dsnet/compress v0.0.1 // indirect
@@ -46,14 +44,11 @@ require (
4644
github.com/pjbgf/sha1cd v0.3.2 // indirect
4745
github.com/pmezard/go-difflib v1.0.0 // indirect
4846
github.com/rivo/uniseg v0.4.7 // indirect
49-
github.com/russross/blackfriday/v2 v2.1.0 // indirect
5047
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
5148
github.com/skeema/knownhosts v1.3.1 // indirect
5249
github.com/ulikunitz/xz v0.5.12 // indirect
53-
github.com/urfave/cli/v2 v2.27.4 // indirect
5450
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
5551
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
56-
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
5752
golang.org/x/net v0.38.0 // indirect
5853
golang.org/x/sync v0.12.0 // indirect
5954
golang.org/x/sys v0.31.0 // indirect

go.sum

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s=
22
dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
3-
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
4-
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
53
github.com/CycloneDX/cyclonedx-go v0.9.2 h1:688QHn2X/5nRezKe2ueIVCt+NRqf7fl3AVQk+vaFcIo=
64
github.com/CycloneDX/cyclonedx-go v0.9.2/go.mod h1:vcK6pKgO1WanCdd61qx4bFnSsDJQ6SbM2ZuMIgq86Jg=
75
github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY=
@@ -21,8 +19,6 @@ github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMU
2119
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
2220
github.com/cloudflare/circl v1.6.1 h1:zqIqSPIndyBh1bjLVVDHMPpVKqp8Su/V+6MeDzzQBQ0=
2321
github.com/cloudflare/circl v1.6.1/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs=
24-
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
25-
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
2622
github.com/cyphar/filepath-securejoin v0.4.1 h1:JyxxyPEaktOD+GAnqIqTf9A8tHyAG22rowi7HkoSU1s=
2723
github.com/cyphar/filepath-securejoin v0.4.1/go.mod h1:Sdj7gXlvMcPZsbhwhQ33GguGLDGQL7h7bg04C/+u9jI=
2824
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -61,10 +57,8 @@ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOl
6157
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
6258
github.com/jfrog/archiver/v3 v3.6.1 h1:LOxnkw9pOn45DzCbZNFV6K0+6dCsQ0L8mR3ZcujO5eI=
6359
github.com/jfrog/archiver/v3 v3.6.1/go.mod h1:VgR+3WZS4N+i9FaDwLZbq+jeU4B4zctXL+gL4EMzfLw=
64-
github.com/jfrog/build-info-go v1.10.15 h1:y6E87iIBTofNy4mus6Ngv6AtVwg/bN/Rz+oaI3kpN4M=
65-
github.com/jfrog/build-info-go v1.10.15/go.mod h1:+8u1CEGrr8XY5a5U6farFW3EKYk0ge0BMGZE3BAZBcE=
66-
github.com/jfrog/build-info-go v1.10.16 h1:M77OfTXl3Ew9AG9SIIYLAG5ccIIaf6xjIZ5nomc2XAw=
67-
github.com/jfrog/build-info-go v1.10.16/go.mod h1:szdz9+WzB7+7PGnILLUgyY+OF5qD5geBT7UGNIxibyw=
60+
github.com/jfrog/build-info-go v1.10.17 h1:wnVd9KkyFGQgNL+oU1wXyJB7/Ui9O/MqUnNKUMsyoRw=
61+
github.com/jfrog/build-info-go v1.10.17/go.mod h1:szdz9+WzB7+7PGnILLUgyY+OF5qD5geBT7UGNIxibyw=
6862
github.com/jfrog/gofrog v1.7.6 h1:QmfAiRzVyaI7JYGsB7cxfAJePAZTzFz0gRWZSE27c6s=
6963
github.com/jfrog/gofrog v1.7.6/go.mod h1:ntr1txqNOZtHplmaNd7rS4f8jpA5Apx8em70oYEe7+4=
7064
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
@@ -102,8 +96,6 @@ github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
10296
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
10397
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
10498
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
105-
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
106-
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
10799
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8=
108100
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
109101
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
@@ -119,8 +111,6 @@ github.com/terminalstatic/go-xsd-validate v0.1.6/go.mod h1:18lsvYFofBflqCrvo1ump
119111
github.com/ulikunitz/xz v0.5.6/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8=
120112
github.com/ulikunitz/xz v0.5.12 h1:37Nm15o69RwBkXM0J6A5OlE67RZTfzUxTj8fB3dfcsc=
121113
github.com/ulikunitz/xz v0.5.12/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
122-
github.com/urfave/cli/v2 v2.27.4 h1:o1owoI+02Eb+K107p27wEX9Bb8eqIoZCfLXloLUSWJ8=
123-
github.com/urfave/cli/v2 v2.27.4/go.mod h1:m4QzxcD2qpra4z7WhzEGn74WZLViBnMpb1ToCAKdGRQ=
124114
github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM=
125115
github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw=
126116
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f h1:J9EGpcZtP0E/raorCMxlFGSTBrsSlaDGf3jU/qvAE2c=
@@ -133,8 +123,6 @@ github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofm
133123
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos=
134124
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
135125
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
136-
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
137-
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
138126
github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU=
139127
github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E=
140128
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=

lifecycle/lifecycle_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func TestRemoteDeleteReleaseBundle(t *testing.T) {
199199
handlerFunc := func(w http.ResponseWriter, r *http.Request) {
200200
switch r.RequestURI {
201201
case "/" + lifecycle.GetReleaseBundleDistributionsApi(testRb):
202-
w.WriteHeader(http.StatusOK)
202+
w.WriteHeader(http.StatusAccepted)
203203
var rbStatus lifecycle.RbStatus
204204
switch requestNum {
205205
case 0:
@@ -212,7 +212,7 @@ func TestRemoteDeleteReleaseBundle(t *testing.T) {
212212
requestNum++
213213
writeMockStatusResponse(t, w, lifecycle.GetDistributionsResponse{{Status: rbStatus}})
214214
case "/" + lifecycle.GetRemoteDeleteReleaseBundleApi(testRb, false):
215-
w.WriteHeader(http.StatusAccepted)
215+
w.WriteHeader(http.StatusOK)
216216
}
217217
}
218218

lifecycle/services/delete.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (rbs *ReleaseBundlesService) RemoteDeleteReleaseBundle(rbDetails ReleaseBun
7474
return err
7575
}
7676
log.Debug("Artifactory response:", resp.Status)
77-
return errorutils.CheckResponseStatusWithBody(resp, body, http.StatusAccepted)
77+
return errorutils.CheckResponseStatusWithBody(resp, body, http.StatusOK)
7878
}
7979

8080
resp, body, err := rbs.client.SendPost(requestFullUrl, content, &httpClientDetails)
@@ -84,7 +84,7 @@ func (rbs *ReleaseBundlesService) RemoteDeleteReleaseBundle(rbDetails ReleaseBun
8484

8585
log.Debug("Artifactory response:", resp.Status)
8686

87-
err = errorutils.CheckResponseStatusWithBody(resp, body, http.StatusOK)
87+
err = errorutils.CheckResponseStatusWithBody(resp, body, http.StatusAccepted)
8888
if err != nil || params.Async || params.DryRun {
8989
return err
9090
}

tests/xrayartifact_test.go

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package tests
2+
3+
import (
4+
"strconv"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
9+
"github.com/jfrog/jfrog-client-go/artifactory/services/utils/tests/xray"
10+
"github.com/jfrog/jfrog-client-go/http/jfroghttpclient"
11+
"github.com/jfrog/jfrog-client-go/xray/services"
12+
)
13+
14+
func TestArtifactStatus(t *testing.T) {
15+
initXrayTest(t)
16+
xrayServerPort := xray.StartXrayMockServer(t)
17+
xrayDetails := GetXrayDetails()
18+
client, err := jfroghttpclient.JfrogClientBuilder().
19+
SetClientCertPath(xrayDetails.GetClientCertPath()).
20+
SetClientCertKeyPath(xrayDetails.GetClientCertKeyPath()).
21+
AppendPreRequestInterceptor(xrayDetails.RunPreRequestFunctions).
22+
Build()
23+
if err != nil {
24+
t.Error(err)
25+
}
26+
testsArtifactService := services.NewArtifactService(client)
27+
testsArtifactService.XrayDetails = xrayDetails
28+
testsArtifactService.XrayDetails.SetUrl("http://localhost:" + strconv.Itoa(xrayServerPort) + "/")
29+
30+
tests := []struct {
31+
name string
32+
repo string
33+
path string
34+
expectedStatus services.ArtifactStatus
35+
expectedTime string
36+
}{
37+
{
38+
name: "completed-scan",
39+
repo: "test-repo",
40+
path: "path/to/artifact",
41+
expectedStatus: services.ArtifactStatusDone,
42+
expectedTime: "2023-12-01T10:00:00Z",
43+
},
44+
{
45+
name: "pending-scan",
46+
repo: "test-repo",
47+
path: "path/to/pending-artifact",
48+
expectedStatus: services.ArtifactStatusPending,
49+
expectedTime: "2023-12-01T09:30:00Z",
50+
},
51+
{
52+
name: "unsupported-artifact",
53+
repo: "test-repo",
54+
path: "path/to/unsupported-artifact",
55+
expectedStatus: services.ArtifactStatusNotSupported,
56+
expectedTime: "2023-12-01T11:00:00Z",
57+
},
58+
}
59+
60+
for _, test := range tests {
61+
t.Run(test.name, func(t *testing.T) {
62+
response, err := testsArtifactService.GetStatus(test.repo, test.path)
63+
assert.NoError(t, err)
64+
assert.NotNil(t, response)
65+
66+
// Verify the overall status and timestamp
67+
assert.Equal(t, test.expectedStatus, response.Overall.Status)
68+
assert.Equal(t, test.expectedTime, response.Overall.Timestamp)
69+
70+
// Verify that all details have timestamps
71+
assert.NotEmpty(t, response.Details.Sca.Timestamp)
72+
assert.NotEmpty(t, response.Details.ContextualAnalysis.Timestamp)
73+
assert.NotEmpty(t, response.Details.Exposures.Timestamp)
74+
assert.NotEmpty(t, response.Details.Violations.Timestamp)
75+
})
76+
}
77+
78+
// Test specific scenario details for the completed scan
79+
t.Run("completed-scan-details", func(t *testing.T) {
80+
response, err := testsArtifactService.GetStatus("test-repo", "path/to/artifact")
81+
assert.NoError(t, err)
82+
83+
// Verify specific statuses for the completed scan
84+
assert.Equal(t, services.ArtifactStatusDone, response.Details.Sca.Status)
85+
assert.Equal(t, services.ArtifactStatusDone, response.Details.ContextualAnalysis.Status)
86+
assert.Equal(t, services.ArtifactStatusNotSupported, response.Details.Exposures.Status)
87+
assert.Equal(t, services.ArtifactStatusFailed, response.Details.Violations.Status)
88+
})
89+
90+
// Test specific scenario details for the pending scan
91+
t.Run("pending-scan-details", func(t *testing.T) {
92+
response, err := testsArtifactService.GetStatus("test-repo", "path/to/pending-artifact")
93+
assert.NoError(t, err)
94+
95+
// Verify specific statuses for the pending scan
96+
assert.Equal(t, services.ArtifactStatusPending, response.Details.Sca.Status)
97+
assert.Equal(t, services.ArtifactStatusNotScanned, response.Details.ContextualAnalysis.Status)
98+
assert.Equal(t, services.ArtifactStatusNotSupported, response.Details.Exposures.Status)
99+
assert.Equal(t, services.ArtifactStatusNotScanned, response.Details.Violations.Status)
100+
})
101+
}

0 commit comments

Comments
 (0)