Skip to content

Commit b4c318c

Browse files
committed
more tests fix old type from my side
1 parent ae2202d commit b4c318c

File tree

2 files changed

+64
-4
lines changed

2 files changed

+64
-4
lines changed

routers/api/actions/artifactsv4.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ package actions
2525
// 1.3. Continue Upload Zip Content to Blobstorage (unauthenticated request), repeat until everything is uploaded
2626
// PUT: http://localhost:3000/twirp/github.actions.results.api.v1.ArtifactService/UploadArtifact?sig=mO7y35r4GyjN7fwg0DTv3-Fv1NDXD84KLEgLpoPOtDI=&expires=2024-01-23+21%3A48%3A37.20833956+%2B0100+CET&artifactName=test&taskID=75&comp=appendBlock
2727
// 1.4. BlockList xml payload to Blobstorage (unauthenticated request)
28-
// Files of about 800MB are parallel in parallel and / or out of order, this file is needed to enshure the correct order
28+
// Files of about 800MB are parallel in parallel and / or out of order, this file is needed to ensure the correct order
2929
// PUT: http://localhost:3000/twirp/github.actions.results.api.v1.ArtifactService/UploadArtifact?sig=mO7y35r4GyjN7fwg0DTv3-Fv1NDXD84KLEgLpoPOtDI=&expires=2024-01-23+21%3A48%3A37.20833956+%2B0100+CET&artifactName=test&taskID=75&comp=blockList
3030
// Request
3131
// <?xml version="1.0" encoding="UTF-8" standalone="yes"?>

tests/integration/api_actions_artifact_v4_test.go

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ func TestActionsArtifactV4RunDownloadSinglePublicApi(t *testing.T) {
350350
session := loginUser(t, user.Name)
351351
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
352352

353-
// confirm artifact upload via rest api
353+
// confirm artifact can be listed and found by name
354354
req := NewRequestWithBody(t, "GET", fmt.Sprintf("/api/v1/repos/%s/actions/runs/792/artifacts?name=artifact-v4-download", repo.FullName()), nil).
355355
AddTokenAuth(token)
356356
resp := MakeRequest(t, req, http.StatusOK)
@@ -360,11 +360,13 @@ func TestActionsArtifactV4RunDownloadSinglePublicApi(t *testing.T) {
360360
assert.NotEmpty(t, listResp.Entries[0].ArchiveDownloadURL)
361361
assert.Equal(t, "artifact-v4-download", listResp.Entries[0].Name)
362362

363+
// confirm artifact blob storage url can be retrieved
363364
req = NewRequestWithBody(t, "GET", listResp.Entries[0].ArchiveDownloadURL, nil).
364365
AddTokenAuth(token)
365366

366367
resp = MakeRequest(t, req, http.StatusFound)
367368

369+
// confirm artifact can be downloaded and has expected content
368370
req = NewRequestWithBody(t, "GET", resp.Header().Get("Location"), nil).
369371
AddTokenAuth(token)
370372
resp = MakeRequest(t, req, http.StatusOK)
@@ -381,7 +383,7 @@ func TestActionsArtifactV4DownloadSinglePublicApi(t *testing.T) {
381383
session := loginUser(t, user.Name)
382384
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
383385

384-
// confirm artifact upload via rest api
386+
// confirm artifact can be listed and found by name
385387
req := NewRequestWithBody(t, "GET", fmt.Sprintf("/api/v1/repos/%s/actions/artifacts?name=artifact-v4-download", repo.FullName()), nil).
386388
AddTokenAuth(token)
387389
resp := MakeRequest(t, req, http.StatusOK)
@@ -391,11 +393,13 @@ func TestActionsArtifactV4DownloadSinglePublicApi(t *testing.T) {
391393
assert.NotEmpty(t, listResp.Entries[0].ArchiveDownloadURL)
392394
assert.Equal(t, "artifact-v4-download", listResp.Entries[0].Name)
393395

396+
// confirm artifact blob storage url can be retrieved
394397
req = NewRequestWithBody(t, "GET", listResp.Entries[0].ArchiveDownloadURL, nil).
395398
AddTokenAuth(token)
396399

397400
resp = MakeRequest(t, req, http.StatusFound)
398401

402+
// confirm artifact can be downloaded and has expected content
399403
req = NewRequestWithBody(t, "GET", resp.Header().Get("Location"), nil).
400404
AddTokenAuth(token)
401405
resp = MakeRequest(t, req, http.StatusOK)
@@ -411,7 +415,7 @@ func TestActionsArtifactV4ListAndGetPublicApi(t *testing.T) {
411415
session := loginUser(t, user.Name)
412416
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
413417

414-
// confirm artifact upload via rest api
418+
// confirm artifact can be listed
415419
req := NewRequestWithBody(t, "GET", fmt.Sprintf("/api/v1/repos/%s/actions/artifacts", repo.FullName()), nil).
416420
AddTokenAuth(token)
417421
resp := MakeRequest(t, req, http.StatusOK)
@@ -438,6 +442,62 @@ func TestActionsArtifactV4ListAndGetPublicApi(t *testing.T) {
438442
}
439443
}
440444

445+
func TestActionsArtifactV4GetArtifactMismatchedRepoOwnerNotFound(t *testing.T) {
446+
defer prepareTestEnvActionsArtifacts(t)()
447+
448+
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
449+
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
450+
session := loginUser(t, user.Name)
451+
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
452+
453+
// confirm artifacts of wrong owner or repo is not visible
454+
req := NewRequestWithBody(t, "GET", fmt.Sprintf("/api/v1/repos/%s/actions/artifacts/%d", repo.FullName(), 22), nil).
455+
AddTokenAuth(token)
456+
MakeRequest(t, req, http.StatusNotFound)
457+
}
458+
459+
func TestActionsArtifactV4DownloadArtifactMismatchedRepoOwnerNotFound(t *testing.T) {
460+
defer prepareTestEnvActionsArtifacts(t)()
461+
462+
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
463+
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
464+
session := loginUser(t, user.Name)
465+
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
466+
467+
// confirm artifacts of wrong owner or repo is not visible
468+
req := NewRequestWithBody(t, "GET", fmt.Sprintf("/api/v1/repos/%s/actions/artifacts/%d/zip", repo.FullName(), 22), nil).
469+
AddTokenAuth(token)
470+
MakeRequest(t, req, http.StatusNotFound)
471+
}
472+
473+
func TestActionsArtifactV4DownloadArtifactCorrectRepoOwnerFound(t *testing.T) {
474+
defer prepareTestEnvActionsArtifacts(t)()
475+
476+
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4})
477+
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
478+
session := loginUser(t, user.Name)
479+
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
480+
481+
// confirm artifacts of wrong owner or repo is not visible
482+
req := NewRequestWithBody(t, "GET", fmt.Sprintf("/api/v1/repos/%s/actions/artifacts/%d/zip", repo.FullName(), 22), nil).
483+
AddTokenAuth(token)
484+
MakeRequest(t, req, http.StatusFound)
485+
}
486+
487+
func TestActionsArtifactV4DownloadRawArtifactMismatchedRepoOwnerNotFound(t *testing.T) {
488+
defer prepareTestEnvActionsArtifacts(t)()
489+
490+
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
491+
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
492+
session := loginUser(t, user.Name)
493+
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
494+
495+
// confirm artifacts of wrong owner or repo is not visible
496+
req := NewRequestWithBody(t, "GET", fmt.Sprintf("/api/v1/repos/%s/actions/artifacts/%d/zip/raw", repo.FullName(), 22), nil).
497+
AddTokenAuth(token)
498+
MakeRequest(t, req, http.StatusNotFound)
499+
}
500+
441501
func TestActionsArtifactV4Delete(t *testing.T) {
442502
defer prepareTestEnvActionsArtifacts(t)()
443503

0 commit comments

Comments
 (0)