Skip to content

Commit 8485044

Browse files
committed
add download test for private repo and remove the token to the redirect
1 parent 6009e63 commit 8485044

File tree

2 files changed

+80
-4
lines changed

2 files changed

+80
-4
lines changed

models/fixtures/action_artifact.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,21 @@
6969
created_unix: 1730330775
7070
updated_unix: 1730330775
7171
expired_unix: 1738106775
72+
73+
-
74+
id: 23
75+
run_id: 793
76+
runner_id: 1
77+
repo_id: 2
78+
owner_id: 2
79+
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
80+
storage_path: "27/5/1730330775594233150.chunk"
81+
file_size: 1024
82+
file_compressed_size: 1024
83+
content_encoding: "application/zip"
84+
artifact_path: "artifact-v4-download.zip"
85+
artifact_name: "artifact-v4-download"
86+
status: 2
87+
created_unix: 1730330775
88+
updated_unix: 1730330775
89+
expired_unix: 1738106775

tests/integration/api_actions_artifact_v4_test.go

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,12 +398,56 @@ func TestActionsArtifactV4DownloadSinglePublicApi(t *testing.T) {
398398

399399
resp = MakeRequest(t, req, http.StatusFound)
400400

401-
// confirm artifact can be downloaded and has expected content
402-
req = NewRequestWithBody(t, "GET", resp.Header().Get("Location"), nil).
401+
blobLocation := resp.Header().Get("Location")
402+
403+
// confirm artifact can be downloaded without token and has expected content
404+
req = NewRequestWithBody(t, "GET", blobLocation, nil)
405+
resp = MakeRequest(t, req, http.StatusOK)
406+
body := strings.Repeat("D", 1024)
407+
assert.Equal(t, body, resp.Body.String())
408+
409+
// confirm artifact can not be downloaded without query
410+
req = NewRequestWithBody(t, "GET", blobLocation, nil)
411+
req.URL.RawQuery = ""
412+
_ = MakeRequest(t, req, http.StatusUnauthorized)
413+
}
414+
415+
func TestActionsArtifactV4DownloadSinglePublicApiPrivateRepo(t *testing.T) {
416+
defer prepareTestEnvActionsArtifacts(t)()
417+
418+
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
419+
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
420+
session := loginUser(t, user.Name)
421+
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
422+
423+
// confirm artifact can be listed and found by name
424+
req := NewRequestWithBody(t, "GET", fmt.Sprintf("/api/v1/repos/%s/actions/artifacts?name=artifact-v4-download", repo.FullName()), nil).
425+
AddTokenAuth(token)
426+
resp := MakeRequest(t, req, http.StatusOK)
427+
var listResp api.ActionArtifactsResponse
428+
err := json.Unmarshal(resp.Body.Bytes(), &listResp)
429+
assert.NoError(t, err)
430+
assert.Equal(t, int64(23), listResp.Entries[0].ID)
431+
assert.NotEmpty(t, listResp.Entries[0].ArchiveDownloadURL)
432+
assert.Equal(t, "artifact-v4-download", listResp.Entries[0].Name)
433+
434+
// confirm artifact blob storage url can be retrieved
435+
req = NewRequestWithBody(t, "GET", listResp.Entries[0].ArchiveDownloadURL, nil).
403436
AddTokenAuth(token)
437+
438+
resp = MakeRequest(t, req, http.StatusFound)
439+
440+
blobLocation := resp.Header().Get("Location")
441+
// confirm artifact can be downloaded without token and has expected content
442+
req = NewRequestWithBody(t, "GET", blobLocation, nil)
404443
resp = MakeRequest(t, req, http.StatusOK)
405444
body := strings.Repeat("D", 1024)
406445
assert.Equal(t, body, resp.Body.String())
446+
447+
// confirm artifact can not be downloaded without query
448+
req = NewRequestWithBody(t, "GET", blobLocation, nil)
449+
req.URL.RawQuery = ""
450+
_ = MakeRequest(t, req, http.StatusUnauthorized)
407451
}
408452

409453
func TestActionsArtifactV4ListAndGetPublicApi(t *testing.T) {
@@ -483,7 +527,7 @@ func TestActionsArtifactV4DownloadArtifactCorrectRepoOwnerFound(t *testing.T) {
483527
MakeRequest(t, req, http.StatusFound)
484528
}
485529

486-
func TestActionsArtifactV4DownloadRawArtifactMismatchedRepoOwnerNotFound(t *testing.T) {
530+
func TestActionsArtifactV4DownloadRawArtifactMismatchedRepoOwnerMissingSignatureUnauthorized(t *testing.T) {
487531
defer prepareTestEnvActionsArtifacts(t)()
488532

489533
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
@@ -494,7 +538,21 @@ func TestActionsArtifactV4DownloadRawArtifactMismatchedRepoOwnerNotFound(t *test
494538
// confirm artifacts of wrong owner or repo is not visible
495539
req := NewRequestWithBody(t, "GET", fmt.Sprintf("/api/v1/repos/%s/actions/artifacts/%d/zip/raw", repo.FullName(), 22), nil).
496540
AddTokenAuth(token)
497-
MakeRequest(t, req, http.StatusNotFound)
541+
MakeRequest(t, req, http.StatusUnauthorized)
542+
}
543+
544+
func TestActionsArtifactV4DownloadRawArtifactCorrectRepoOwnerMissingSignatureUnauthorized(t *testing.T) {
545+
defer prepareTestEnvActionsArtifacts(t)()
546+
547+
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4})
548+
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
549+
session := loginUser(t, user.Name)
550+
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
551+
552+
// confirm artifacts of wrong owner or repo is not visible
553+
req := NewRequestWithBody(t, "GET", fmt.Sprintf("/api/v1/repos/%s/actions/artifacts/%d/zip/raw", repo.FullName(), 22), nil).
554+
AddTokenAuth(token)
555+
MakeRequest(t, req, http.StatusUnauthorized)
498556
}
499557

500558
func TestActionsArtifactV4Delete(t *testing.T) {

0 commit comments

Comments
 (0)