summaryrefslogtreecommitdiffstats
path: root/integrations
diff options
context:
space:
mode:
authorKN4CK3R <admin@oldschoolhack.me>2022-05-07 18:21:15 +0200
committerGitHub <noreply@github.com>2022-05-07 18:21:15 +0200
commit8adba93498ccdde7edcb54e10f6a3d176c3815c4 (patch)
treee48b5809a0a76ca8c2087d373d00a225b713ebb3 /integrations
parent38d72d40f132df8a6e90063f3e96a80048bf299e (diff)
downloadgitea-8adba93498ccdde7edcb54e10f6a3d176c3815c4.tar.gz
gitea-8adba93498ccdde7edcb54e10f6a3d176c3815c4.zip
Hide private repositories in packages (#19584)
Diffstat (limited to 'integrations')
-rw-r--r--integrations/api_packages_test.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/integrations/api_packages_test.go b/integrations/api_packages_test.go
index b3f6e88d9f..1f24807060 100644
--- a/integrations/api_packages_test.go
+++ b/integrations/api_packages_test.go
@@ -71,6 +71,44 @@ func TestPackageAPI(t *testing.T) {
assert.Equal(t, packageVersion, p.Version)
assert.NotNil(t, p.Creator)
assert.Equal(t, user.Name, p.Creator.UserName)
+
+ t.Run("RepositoryLink", func(t *testing.T) {
+ defer PrintCurrentTest(t)()
+
+ p, err := packages_model.GetPackageByName(db.DefaultContext, user.ID, packages_model.TypeGeneric, packageName)
+ assert.NoError(t, err)
+
+ // no repository link
+ req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/packages/%s/generic/%s/%s?token=%s", user.Name, packageName, packageVersion, token))
+ resp := MakeRequest(t, req, http.StatusOK)
+
+ var ap1 *api.Package
+ DecodeJSON(t, resp, &ap1)
+ assert.Nil(t, ap1.Repository)
+
+ // link to public repository
+ assert.NoError(t, packages_model.SetRepositoryLink(db.DefaultContext, p.ID, 1))
+
+ req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/packages/%s/generic/%s/%s?token=%s", user.Name, packageName, packageVersion, token))
+ resp = MakeRequest(t, req, http.StatusOK)
+
+ var ap2 *api.Package
+ DecodeJSON(t, resp, &ap2)
+ assert.NotNil(t, ap2.Repository)
+ assert.EqualValues(t, 1, ap2.Repository.ID)
+
+ // link to private repository
+ assert.NoError(t, packages_model.SetRepositoryLink(db.DefaultContext, p.ID, 2))
+
+ req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/packages/%s/generic/%s/%s?token=%s", user.Name, packageName, packageVersion, token))
+ resp = MakeRequest(t, req, http.StatusOK)
+
+ var ap3 *api.Package
+ DecodeJSON(t, resp, &ap3)
+ assert.Nil(t, ap3.Repository)
+
+ assert.NoError(t, packages_model.UnlinkRepositoryFromAllPackages(db.DefaultContext, 2))
+ })
})
t.Run("ListPackageFiles", func(t *testing.T) {