Skip to content

Commit 7668923

Browse files
committed
actions artifacts internal api list/download check status upload confirmed
* fixes a fixture status to upload confirmed * add another fixture as noise to break tests as soon they are exposed to api * v4 delete test added check that artifact is no longer visible in internal api with status pending delete
1 parent 8aee07a commit 7668923

File tree

4 files changed

+71
-7
lines changed

4 files changed

+71
-7
lines changed

models/fixtures/action_artifact.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,24 @@
1111
content_encoding: ""
1212
artifact_path: "abc.txt"
1313
artifact_name: "artifact-download"
14+
status: 2
15+
created_unix: 1712338649
16+
updated_unix: 1712338649
17+
expired_unix: 1720114649
18+
19+
-
20+
id: 2
21+
run_id: 791
22+
runner_id: 1
23+
repo_id: 4
24+
owner_id: 1
25+
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
26+
storage_path: ""
27+
file_size: 1024
28+
file_compressed_size: 1024
29+
content_encoding: "30/20/1712348022422036662.chunk"
30+
artifact_path: "abc.txt"
31+
artifact_name: "artifact-download-incomplete"
1432
status: 1
1533
created_unix: 1712338649
1634
updated_unix: 1712338649

routers/api/actions/artifacts.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,10 @@ func (ar artifactRoutes) listArtifacts(ctx *ArtifactContext) {
337337
return
338338
}
339339

340-
artifacts, err := db.Find[actions.ActionArtifact](ctx, actions.FindArtifactsOptions{RunID: runID})
340+
artifacts, err := db.Find[actions.ActionArtifact](ctx, actions.FindArtifactsOptions{
341+
RunID: runID,
342+
Status: int(actions.ArtifactStatusUploadConfirmed),
343+
})
341344
if err != nil {
342345
log.Error("Error getting artifacts: %v", err)
343346
ctx.HTTPError(http.StatusInternalServerError, err.Error())
@@ -402,6 +405,7 @@ func (ar artifactRoutes) getDownloadArtifactURL(ctx *ArtifactContext) {
402405
artifacts, err := db.Find[actions.ActionArtifact](ctx, actions.FindArtifactsOptions{
403406
RunID: runID,
404407
ArtifactName: itemPath,
408+
Status: int(actions.ArtifactStatusUploadConfirmed),
405409
})
406410
if err != nil {
407411
log.Error("Error getting artifacts: %v", err)
@@ -473,6 +477,11 @@ func (ar artifactRoutes) downloadArtifact(ctx *ArtifactContext) {
473477
ctx.HTTPError(http.StatusBadRequest)
474478
return
475479
}
480+
if artifact.Status != actions.ArtifactStatusUploadConfirmed {
481+
log.Error("Error artifact not found: unconfirmed")
482+
ctx.HTTPError(http.StatusNotFound, "Error artifact not found")
483+
return
484+
}
476485

477486
fd, err := ar.fs.Open(artifact.StoragePath)
478487
if err != nil {

routers/api/actions/artifactsv4.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -448,17 +448,15 @@ func (r *artifactV4Routes) listArtifacts(ctx *ArtifactContext) {
448448
return
449449
}
450450

451-
artifacts, err := db.Find[actions.ActionArtifact](ctx, actions.FindArtifactsOptions{RunID: runID})
451+
artifacts, err := db.Find[actions.ActionArtifact](ctx, actions.FindArtifactsOptions{
452+
RunID: runID,
453+
Status: int(actions.ArtifactStatusUploadConfirmed),
454+
})
452455
if err != nil {
453456
log.Error("Error getting artifacts: %v", err)
454457
ctx.HTTPError(http.StatusInternalServerError, err.Error())
455458
return
456459
}
457-
if len(artifacts) == 0 {
458-
log.Debug("[artifact] handleListArtifacts, no artifacts")
459-
ctx.HTTPError(http.StatusNotFound)
460-
return
461-
}
462460

463461
list := []*ListArtifactsResponse_MonolithArtifact{}
464462

@@ -510,6 +508,11 @@ func (r *artifactV4Routes) getSignedArtifactURL(ctx *ArtifactContext) {
510508
ctx.HTTPError(http.StatusNotFound, "Error artifact not found")
511509
return
512510
}
511+
if artifact.Status != actions.ArtifactStatusUploadConfirmed {
512+
log.Error("Error artifact not found: unconfirmed")
513+
ctx.HTTPError(http.StatusNotFound, "Error artifact not found")
514+
return
515+
}
513516

514517
respData := GetSignedArtifactURLResponse{}
515518

@@ -538,6 +541,11 @@ func (r *artifactV4Routes) downloadArtifact(ctx *ArtifactContext) {
538541
ctx.HTTPError(http.StatusNotFound, "Error artifact not found")
539542
return
540543
}
544+
if artifact.Status != actions.ArtifactStatusUploadConfirmed {
545+
log.Error("Error artifact not found: unconfirmed")
546+
ctx.HTTPError(http.StatusNotFound, "Error artifact not found")
547+
return
548+
}
541549

542550
file, _ := r.fs.Open(artifact.StoragePath)
543551

tests/integration/api_actions_artifact_v4_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,35 @@ func TestActionsArtifactV4Delete(t *testing.T) {
557557
var deleteResp actions.DeleteArtifactResponse
558558
protojson.Unmarshal(resp.Body.Bytes(), &deleteResp)
559559
assert.True(t, deleteResp.Ok)
560+
561+
// confirm artifact is no longer accessible by GetSignedArtifactURL
562+
req = NewRequestWithBody(t, "POST", "/twirp/github.actions.results.api.v1.ArtifactService/GetSignedArtifactURL", toProtoJSON(&actions.GetSignedArtifactURLRequest{
563+
Name: "artifact-v4-download",
564+
WorkflowRunBackendId: "792",
565+
WorkflowJobRunBackendId: "193",
566+
})).
567+
AddTokenAuth(token)
568+
resp = MakeRequest(t, req, http.StatusNotFound)
569+
570+
// confirm artifact is no longer accessible by GetSignedArtifactURL
571+
req = NewRequestWithBody(t, "POST", "/twirp/github.actions.results.api.v1.ArtifactService/GetSignedArtifactURL", toProtoJSON(&actions.GetSignedArtifactURLRequest{
572+
Name: "artifact-v4-download",
573+
WorkflowRunBackendId: "792",
574+
WorkflowJobRunBackendId: "193",
575+
})).
576+
AddTokenAuth(token)
577+
resp = MakeRequest(t, req, http.StatusNotFound)
578+
579+
// confirm artifact is no longer enumerateable by ListArtifacts and returns length == 0 without error
580+
req = NewRequestWithBody(t, "POST", "/twirp/github.actions.results.api.v1.ArtifactService/ListArtifacts", toProtoJSON(&actions.ListArtifactsRequest{
581+
NameFilter: wrapperspb.String("artifact-v4-download"),
582+
WorkflowRunBackendId: "792",
583+
WorkflowJobRunBackendId: "193",
584+
})).AddTokenAuth(token)
585+
resp = MakeRequest(t, req, http.StatusOK)
586+
var listResp actions.ListArtifactsResponse
587+
protojson.Unmarshal(resp.Body.Bytes(), &listResp)
588+
assert.Len(t, listResp.Artifacts, 0)
560589
}
561590

562591
func TestActionsArtifactV4DeletePublicApi(t *testing.T) {

0 commit comments

Comments
 (0)