Merge pull request 'test: add more sha256 repositories tests' (#3794) from oliverpool/forgejo:push_deploy_sha256 into forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/3794 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
This commit is contained in:
commit
56ca2e43e9
9 changed files with 135 additions and 118 deletions
|
@ -11,6 +11,7 @@ import (
|
||||||
auth_model "code.gitea.io/gitea/models/auth"
|
auth_model "code.gitea.io/gitea/models/auth"
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
git_model "code.gitea.io/gitea/models/git"
|
git_model "code.gitea.io/gitea/models/git"
|
||||||
|
"code.gitea.io/gitea/modules/git"
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
api "code.gitea.io/gitea/modules/structs"
|
||||||
"code.gitea.io/gitea/tests"
|
"code.gitea.io/gitea/tests"
|
||||||
|
|
||||||
|
@ -110,61 +111,62 @@ func TestAPICreateBranch(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAPICreateBranches(t *testing.T, giteaURL *url.URL) {
|
func testAPICreateBranches(t *testing.T, giteaURL *url.URL) {
|
||||||
username := "user2"
|
forEachObjectFormat(t, func(t *testing.T, objectFormat git.ObjectFormat) {
|
||||||
ctx := NewAPITestContext(t, username, "my-noo-repo", auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
|
ctx := NewAPITestContext(t, "user2", "my-noo-repo-"+objectFormat.Name(), auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
|
||||||
giteaURL.Path = ctx.GitPath()
|
giteaURL.Path = ctx.GitPath()
|
||||||
|
|
||||||
t.Run("CreateRepo", doAPICreateRepository(ctx, false))
|
t.Run("CreateRepo", doAPICreateRepository(ctx, false, objectFormat))
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
OldBranch string
|
OldBranch string
|
||||||
NewBranch string
|
NewBranch string
|
||||||
ExpectedHTTPStatus int
|
ExpectedHTTPStatus int
|
||||||
}{
|
}{
|
||||||
// Creating branch from default branch
|
// Creating branch from default branch
|
||||||
{
|
{
|
||||||
OldBranch: "",
|
OldBranch: "",
|
||||||
NewBranch: "new_branch_from_default_branch",
|
NewBranch: "new_branch_from_default_branch",
|
||||||
ExpectedHTTPStatus: http.StatusCreated,
|
ExpectedHTTPStatus: http.StatusCreated,
|
||||||
},
|
},
|
||||||
// Creating branch from master
|
// Creating branch from master
|
||||||
{
|
{
|
||||||
OldBranch: "master",
|
OldBranch: "master",
|
||||||
NewBranch: "new_branch_from_master_1",
|
NewBranch: "new_branch_from_master_1",
|
||||||
ExpectedHTTPStatus: http.StatusCreated,
|
ExpectedHTTPStatus: http.StatusCreated,
|
||||||
},
|
},
|
||||||
// Trying to create from master but already exists
|
// Trying to create from master but already exists
|
||||||
{
|
{
|
||||||
OldBranch: "master",
|
OldBranch: "master",
|
||||||
NewBranch: "new_branch_from_master_1",
|
NewBranch: "new_branch_from_master_1",
|
||||||
ExpectedHTTPStatus: http.StatusConflict,
|
ExpectedHTTPStatus: http.StatusConflict,
|
||||||
},
|
},
|
||||||
// Trying to create from other branch (not default branch)
|
// Trying to create from other branch (not default branch)
|
||||||
// ps: it can't test the case-sensitive behavior here: the "BRANCH_2" can't be created by git on a case-insensitive filesystem, it makes the test fail quickly before the database code.
|
// ps: it can't test the case-sensitive behavior here: the "BRANCH_2" can't be created by git on a case-insensitive filesystem, it makes the test fail quickly before the database code.
|
||||||
// Suppose some users are running Gitea on a case-insensitive filesystem, it seems that it's unable to support case-sensitive branch names.
|
// Suppose some users are running Gitea on a case-insensitive filesystem, it seems that it's unable to support case-sensitive branch names.
|
||||||
{
|
{
|
||||||
OldBranch: "new_branch_from_master_1",
|
OldBranch: "new_branch_from_master_1",
|
||||||
NewBranch: "branch_2",
|
NewBranch: "branch_2",
|
||||||
ExpectedHTTPStatus: http.StatusCreated,
|
ExpectedHTTPStatus: http.StatusCreated,
|
||||||
},
|
},
|
||||||
// Trying to create from a branch which does not exist
|
// Trying to create from a branch which does not exist
|
||||||
{
|
{
|
||||||
OldBranch: "does_not_exist",
|
OldBranch: "does_not_exist",
|
||||||
NewBranch: "new_branch_from_non_existent",
|
NewBranch: "new_branch_from_non_existent",
|
||||||
ExpectedHTTPStatus: http.StatusNotFound,
|
ExpectedHTTPStatus: http.StatusNotFound,
|
||||||
},
|
},
|
||||||
// Trying to create a branch with UTF8
|
// Trying to create a branch with UTF8
|
||||||
{
|
{
|
||||||
OldBranch: "master",
|
OldBranch: "master",
|
||||||
NewBranch: "test-👀",
|
NewBranch: "test-👀",
|
||||||
ExpectedHTTPStatus: http.StatusCreated,
|
ExpectedHTTPStatus: http.StatusCreated,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, test := range testCases {
|
for _, test := range testCases {
|
||||||
session := ctx.Session
|
session := ctx.Session
|
||||||
t.Run(test.NewBranch, func(t *testing.T) {
|
t.Run(test.NewBranch, func(t *testing.T) {
|
||||||
testAPICreateBranch(t, session, "user2", "my-noo-repo", test.OldBranch, test.NewBranch, test.ExpectedHTTPStatus)
|
testAPICreateBranch(t, session, ctx.Username, ctx.Reponame, test.OldBranch, test.NewBranch, test.ExpectedHTTPStatus)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAPICreateBranch(t testing.TB, session *TestSession, user, repo, oldBranch, newBranch string, status int) bool {
|
func testAPICreateBranch(t testing.TB, session *TestSession, user, repo, oldBranch, newBranch string, status int) bool {
|
||||||
|
|
|
@ -16,6 +16,7 @@ import (
|
||||||
"code.gitea.io/gitea/models/auth"
|
"code.gitea.io/gitea/models/auth"
|
||||||
"code.gitea.io/gitea/models/perm"
|
"code.gitea.io/gitea/models/perm"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
|
"code.gitea.io/gitea/modules/git"
|
||||||
"code.gitea.io/gitea/modules/json"
|
"code.gitea.io/gitea/modules/json"
|
||||||
"code.gitea.io/gitea/modules/queue"
|
"code.gitea.io/gitea/modules/queue"
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
api "code.gitea.io/gitea/modules/structs"
|
||||||
|
@ -47,17 +48,18 @@ func (ctx APITestContext) GitPath() string {
|
||||||
return fmt.Sprintf("%s/%s.git", ctx.Username, ctx.Reponame)
|
return fmt.Sprintf("%s/%s.git", ctx.Username, ctx.Reponame)
|
||||||
}
|
}
|
||||||
|
|
||||||
func doAPICreateRepository(ctx APITestContext, empty bool, callback ...func(*testing.T, api.Repository)) func(*testing.T) {
|
func doAPICreateRepository(ctx APITestContext, empty bool, objectFormat git.ObjectFormat, callback ...func(*testing.T, api.Repository)) func(*testing.T) {
|
||||||
return func(t *testing.T) {
|
return func(t *testing.T) {
|
||||||
createRepoOption := &api.CreateRepoOption{
|
createRepoOption := &api.CreateRepoOption{
|
||||||
AutoInit: !empty,
|
AutoInit: !empty,
|
||||||
Description: "Temporary repo",
|
Description: "Temporary repo",
|
||||||
Name: ctx.Reponame,
|
Name: ctx.Reponame,
|
||||||
Private: true,
|
Private: true,
|
||||||
Template: true,
|
Template: true,
|
||||||
Gitignores: "",
|
Gitignores: "",
|
||||||
License: "WTFPL",
|
License: "WTFPL",
|
||||||
Readme: "Default",
|
Readme: "Default",
|
||||||
|
ObjectFormatName: objectFormat.Name(),
|
||||||
}
|
}
|
||||||
req := NewRequestWithJSON(t, "POST", "/api/v1/user/repos", createRepoOption).
|
req := NewRequestWithJSON(t, "POST", "/api/v1/user/repos", createRepoOption).
|
||||||
AddTokenAuth(ctx.Token)
|
AddTokenAuth(ctx.Token)
|
||||||
|
|
|
@ -17,6 +17,7 @@ import (
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
"code.gitea.io/gitea/models/unittest"
|
"code.gitea.io/gitea/models/unittest"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
|
"code.gitea.io/gitea/modules/git"
|
||||||
"code.gitea.io/gitea/modules/gitrepo"
|
"code.gitea.io/gitea/modules/gitrepo"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
api "code.gitea.io/gitea/modules/structs"
|
||||||
|
@ -52,6 +53,10 @@ func getCreateFileOptions() api.CreateFileOptions {
|
||||||
|
|
||||||
func getExpectedFileResponseForCreate(repoFullName, commitID, treePath, latestCommitSHA string) *api.FileResponse {
|
func getExpectedFileResponseForCreate(repoFullName, commitID, treePath, latestCommitSHA string) *api.FileResponse {
|
||||||
sha := "a635aa942442ddfdba07468cf9661c08fbdf0ebf"
|
sha := "a635aa942442ddfdba07468cf9661c08fbdf0ebf"
|
||||||
|
if len(latestCommitSHA) > len(sha) {
|
||||||
|
// repository is in SHA256 format
|
||||||
|
sha = "3edd190f61237b7a0a5c49aa47fb58b2ec14d53a2afc90803bc713fab5d5aec0"
|
||||||
|
}
|
||||||
encoding := "base64"
|
encoding := "base64"
|
||||||
content := "VGhpcyBpcyBuZXcgdGV4dA=="
|
content := "VGhpcyBpcyBuZXcgdGV4dA=="
|
||||||
selfURL := setting.AppURL + "api/v1/repos/" + repoFullName + "/contents/" + treePath + "?ref=master"
|
selfURL := setting.AppURL + "api/v1/repos/" + repoFullName + "/contents/" + treePath + "?ref=master"
|
||||||
|
@ -277,28 +282,31 @@ func TestAPICreateFile(t *testing.T) {
|
||||||
MakeRequest(t, req, http.StatusForbidden)
|
MakeRequest(t, req, http.StatusForbidden)
|
||||||
|
|
||||||
// Test creating a file in an empty repository
|
// Test creating a file in an empty repository
|
||||||
doAPICreateRepository(NewAPITestContext(t, "user2", "empty-repo", auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser), true)(t)
|
forEachObjectFormat(t, func(t *testing.T, objectFormat git.ObjectFormat) {
|
||||||
createFileOptions = getCreateFileOptions()
|
reponame := "empty-repo-" + objectFormat.Name()
|
||||||
fileID++
|
doAPICreateRepository(NewAPITestContext(t, "user2", reponame, auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser), true, objectFormat)(t)
|
||||||
treePath = fmt.Sprintf("new/file%d.txt", fileID)
|
createFileOptions = getCreateFileOptions()
|
||||||
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, "empty-repo", treePath), &createFileOptions).
|
fileID++
|
||||||
AddTokenAuth(token2)
|
treePath = fmt.Sprintf("new/file%d.txt", fileID)
|
||||||
resp = MakeRequest(t, req, http.StatusCreated)
|
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, reponame, treePath), &createFileOptions).
|
||||||
emptyRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerName: "user2", Name: "empty-repo"}) // public repo
|
AddTokenAuth(token2)
|
||||||
gitRepo, _ := gitrepo.OpenRepository(stdCtx.Background(), emptyRepo)
|
resp = MakeRequest(t, req, http.StatusCreated)
|
||||||
commitID, _ := gitRepo.GetBranchCommitID(createFileOptions.NewBranchName)
|
emptyRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerName: "user2", Name: reponame}) // public repo
|
||||||
latestCommit, _ := gitRepo.GetCommitByPath(treePath)
|
gitRepo, _ := gitrepo.OpenRepository(stdCtx.Background(), emptyRepo)
|
||||||
expectedFileResponse := getExpectedFileResponseForCreate("user2/empty-repo", commitID, treePath, latestCommit.ID.String())
|
commitID, _ := gitRepo.GetBranchCommitID(createFileOptions.NewBranchName)
|
||||||
DecodeJSON(t, resp, &fileResponse)
|
latestCommit, _ := gitRepo.GetCommitByPath(treePath)
|
||||||
assert.EqualValues(t, expectedFileResponse.Content, fileResponse.Content)
|
expectedFileResponse := getExpectedFileResponseForCreate("user2/"+reponame, commitID, treePath, latestCommit.ID.String())
|
||||||
assert.EqualValues(t, expectedFileResponse.Commit.SHA, fileResponse.Commit.SHA)
|
DecodeJSON(t, resp, &fileResponse)
|
||||||
assert.EqualValues(t, expectedFileResponse.Commit.HTMLURL, fileResponse.Commit.HTMLURL)
|
assert.EqualValues(t, expectedFileResponse.Content, fileResponse.Content)
|
||||||
assert.EqualValues(t, expectedFileResponse.Commit.Author.Email, fileResponse.Commit.Author.Email)
|
assert.EqualValues(t, expectedFileResponse.Commit.SHA, fileResponse.Commit.SHA)
|
||||||
assert.EqualValues(t, expectedFileResponse.Commit.Author.Name, fileResponse.Commit.Author.Name)
|
assert.EqualValues(t, expectedFileResponse.Commit.HTMLURL, fileResponse.Commit.HTMLURL)
|
||||||
assert.EqualValues(t, expectedFileResponse.Commit.Author.Date, fileResponse.Commit.Author.Date)
|
assert.EqualValues(t, expectedFileResponse.Commit.Author.Email, fileResponse.Commit.Author.Email)
|
||||||
assert.EqualValues(t, expectedFileResponse.Commit.Committer.Email, fileResponse.Commit.Committer.Email)
|
assert.EqualValues(t, expectedFileResponse.Commit.Author.Name, fileResponse.Commit.Author.Name)
|
||||||
assert.EqualValues(t, expectedFileResponse.Commit.Committer.Name, fileResponse.Commit.Committer.Name)
|
assert.EqualValues(t, expectedFileResponse.Commit.Author.Date, fileResponse.Commit.Author.Date)
|
||||||
assert.EqualValues(t, expectedFileResponse.Commit.Committer.Date, fileResponse.Commit.Committer.Date)
|
assert.EqualValues(t, expectedFileResponse.Commit.Committer.Email, fileResponse.Commit.Committer.Email)
|
||||||
gitRepo.Close()
|
assert.EqualValues(t, expectedFileResponse.Commit.Committer.Name, fileResponse.Commit.Committer.Name)
|
||||||
|
assert.EqualValues(t, expectedFileResponse.Commit.Committer.Date, fileResponse.Commit.Committer.Date)
|
||||||
|
gitRepo.Close()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
auth_model "code.gitea.io/gitea/models/auth"
|
auth_model "code.gitea.io/gitea/models/auth"
|
||||||
|
"code.gitea.io/gitea/modules/git"
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
api "code.gitea.io/gitea/modules/structs"
|
||||||
"code.gitea.io/gitea/tests"
|
"code.gitea.io/gitea/tests"
|
||||||
|
|
||||||
|
@ -26,7 +27,7 @@ func TestAPIGetRawFileOrLFS(t *testing.T) {
|
||||||
// Test with LFS
|
// Test with LFS
|
||||||
onGiteaRun(t, func(t *testing.T, u *url.URL) {
|
onGiteaRun(t, func(t *testing.T, u *url.URL) {
|
||||||
httpContext := NewAPITestContext(t, "user2", "repo-lfs-test", auth_model.AccessTokenScopeWriteRepository)
|
httpContext := NewAPITestContext(t, "user2", "repo-lfs-test", auth_model.AccessTokenScopeWriteRepository)
|
||||||
doAPICreateRepository(httpContext, false, func(t *testing.T, repository api.Repository) {
|
doAPICreateRepository(httpContext, false, git.Sha1ObjectFormat, func(t *testing.T, repository api.Repository) { // FIXME: use forEachObjectFormat
|
||||||
u.Path = httpContext.GitPath()
|
u.Path = httpContext.GitPath()
|
||||||
dstPath := t.TempDir()
|
dstPath := t.TempDir()
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ import (
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
"code.gitea.io/gitea/models/unittest"
|
"code.gitea.io/gitea/models/unittest"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
|
"code.gitea.io/gitea/modules/git"
|
||||||
"code.gitea.io/gitea/modules/json"
|
"code.gitea.io/gitea/modules/json"
|
||||||
"code.gitea.io/gitea/modules/lfs"
|
"code.gitea.io/gitea/modules/lfs"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
@ -61,7 +62,7 @@ func TestAPILFSMediaType(t *testing.T) {
|
||||||
|
|
||||||
func createLFSTestRepository(t *testing.T, name string) *repo_model.Repository {
|
func createLFSTestRepository(t *testing.T, name string) *repo_model.Repository {
|
||||||
ctx := NewAPITestContext(t, "user2", "lfs-"+name+"-repo", auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
|
ctx := NewAPITestContext(t, "user2", "lfs-"+name+"-repo", auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
|
||||||
t.Run("CreateRepo", doAPICreateRepository(ctx, false))
|
t.Run("CreateRepo", doAPICreateRepository(ctx, false, git.Sha1ObjectFormat)) // FIXME: use forEachObjectFormat
|
||||||
|
|
||||||
repo, err := repo_model.GetRepositoryByOwnerAndName(db.DefaultContext, "user2", "lfs-"+name+"-repo")
|
repo, err := repo_model.GetRepositoryByOwnerAndName(db.DefaultContext, "user2", "lfs-"+name+"-repo")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
|
@ -16,6 +16,7 @@ import (
|
||||||
unit_model "code.gitea.io/gitea/models/unit"
|
unit_model "code.gitea.io/gitea/models/unit"
|
||||||
"code.gitea.io/gitea/models/unittest"
|
"code.gitea.io/gitea/models/unittest"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
|
"code.gitea.io/gitea/modules/git"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
api "code.gitea.io/gitea/modules/structs"
|
||||||
repo_service "code.gitea.io/gitea/services/repository"
|
repo_service "code.gitea.io/gitea/services/repository"
|
||||||
|
@ -427,7 +428,7 @@ func testAPIRepoMigrateConflict(t *testing.T, u *url.URL) {
|
||||||
httpContext := baseAPITestContext
|
httpContext := baseAPITestContext
|
||||||
|
|
||||||
httpContext.Reponame = "repo-tmp-17"
|
httpContext.Reponame = "repo-tmp-17"
|
||||||
t.Run("CreateRepo", doAPICreateRepository(httpContext, false))
|
t.Run("CreateRepo", doAPICreateRepository(httpContext, false, git.Sha1ObjectFormat)) // FIXME: use forEachObjectFormat
|
||||||
|
|
||||||
user, err := user_model.GetUserByName(db.DefaultContext, httpContext.Username)
|
user, err := user_model.GetUserByName(db.DefaultContext, httpContext.Username)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
@ -510,7 +511,7 @@ func testAPIRepoCreateConflict(t *testing.T, u *url.URL) {
|
||||||
httpContext := baseAPITestContext
|
httpContext := baseAPITestContext
|
||||||
|
|
||||||
httpContext.Reponame = "repo-tmp-17"
|
httpContext.Reponame = "repo-tmp-17"
|
||||||
t.Run("CreateRepo", doAPICreateRepository(httpContext, false))
|
t.Run("CreateRepo", doAPICreateRepository(httpContext, false, git.Sha1ObjectFormat)) // FIXME: use forEachObjectFormat
|
||||||
|
|
||||||
req := NewRequestWithJSON(t, "POST", "/api/v1/user/repos",
|
req := NewRequestWithJSON(t, "POST", "/api/v1/user/repos",
|
||||||
&api.CreateRepoOption{
|
&api.CreateRepoOption{
|
||||||
|
|
|
@ -64,7 +64,7 @@ func testGit(t *testing.T, u *url.URL) {
|
||||||
|
|
||||||
dstPath := t.TempDir()
|
dstPath := t.TempDir()
|
||||||
|
|
||||||
t.Run("CreateRepoInDifferentUser", doAPICreateRepository(forkedUserCtx, false))
|
t.Run("CreateRepoInDifferentUser", doAPICreateRepository(forkedUserCtx, false, git.Sha1ObjectFormat)) // FIXME: use forEachObjectFormat
|
||||||
t.Run("AddUserAsCollaborator", doAPIAddCollaborator(forkedUserCtx, httpContext.Username, perm.AccessModeRead))
|
t.Run("AddUserAsCollaborator", doAPIAddCollaborator(forkedUserCtx, httpContext.Username, perm.AccessModeRead))
|
||||||
|
|
||||||
t.Run("ForkFromDifferentUser", doAPIForkRepository(httpContext, forkedUserCtx.Username))
|
t.Run("ForkFromDifferentUser", doAPIForkRepository(httpContext, forkedUserCtx.Username))
|
||||||
|
@ -103,7 +103,7 @@ func testGit(t *testing.T, u *url.URL) {
|
||||||
sshContext.Reponame = "repo-tmp-18"
|
sshContext.Reponame = "repo-tmp-18"
|
||||||
keyname := "my-testing-key"
|
keyname := "my-testing-key"
|
||||||
forkedUserCtx.Reponame = sshContext.Reponame
|
forkedUserCtx.Reponame = sshContext.Reponame
|
||||||
t.Run("CreateRepoInDifferentUser", doAPICreateRepository(forkedUserCtx, false))
|
t.Run("CreateRepoInDifferentUser", doAPICreateRepository(forkedUserCtx, false, git.Sha1ObjectFormat)) // FIXME: use forEachObjectFormat
|
||||||
t.Run("AddUserAsCollaborator", doAPIAddCollaborator(forkedUserCtx, sshContext.Username, perm.AccessModeRead))
|
t.Run("AddUserAsCollaborator", doAPIAddCollaborator(forkedUserCtx, sshContext.Username, perm.AccessModeRead))
|
||||||
t.Run("ForkFromDifferentUser", doAPIForkRepository(sshContext, forkedUserCtx.Username))
|
t.Run("ForkFromDifferentUser", doAPIForkRepository(sshContext, forkedUserCtx.Username))
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
auth_model "code.gitea.io/gitea/models/auth"
|
auth_model "code.gitea.io/gitea/models/auth"
|
||||||
"code.gitea.io/gitea/models/unittest"
|
"code.gitea.io/gitea/models/unittest"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
|
"code.gitea.io/gitea/modules/git"
|
||||||
"code.gitea.io/gitea/modules/process"
|
"code.gitea.io/gitea/modules/process"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
api "code.gitea.io/gitea/modules/structs"
|
||||||
|
@ -56,7 +57,7 @@ func TestGPGGit(t *testing.T) {
|
||||||
t.Run("Unsigned-Initial", func(t *testing.T) {
|
t.Run("Unsigned-Initial", func(t *testing.T) {
|
||||||
defer tests.PrintCurrentTest(t)()
|
defer tests.PrintCurrentTest(t)()
|
||||||
testCtx := NewAPITestContext(t, username, "initial-unsigned", auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
|
testCtx := NewAPITestContext(t, username, "initial-unsigned", auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
|
||||||
t.Run("CreateRepository", doAPICreateRepository(testCtx, false))
|
t.Run("CreateRepository", doAPICreateRepository(testCtx, false, git.Sha1ObjectFormat)) // FIXME: use forEachObjectFormat
|
||||||
t.Run("CheckMasterBranchUnsigned", doAPIGetBranch(testCtx, "master", func(t *testing.T, branch api.Branch) {
|
t.Run("CheckMasterBranchUnsigned", doAPIGetBranch(testCtx, "master", func(t *testing.T, branch api.Branch) {
|
||||||
assert.NotNil(t, branch.Commit)
|
assert.NotNil(t, branch.Commit)
|
||||||
assert.NotNil(t, branch.Commit.Verification)
|
assert.NotNil(t, branch.Commit.Verification)
|
||||||
|
@ -149,7 +150,7 @@ func TestGPGGit(t *testing.T) {
|
||||||
t.Run("AlwaysSign-Initial", func(t *testing.T) {
|
t.Run("AlwaysSign-Initial", func(t *testing.T) {
|
||||||
defer tests.PrintCurrentTest(t)()
|
defer tests.PrintCurrentTest(t)()
|
||||||
testCtx := NewAPITestContext(t, username, "initial-always", auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
|
testCtx := NewAPITestContext(t, username, "initial-always", auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
|
||||||
t.Run("CreateRepository", doAPICreateRepository(testCtx, false))
|
t.Run("CreateRepository", doAPICreateRepository(testCtx, false, git.Sha1ObjectFormat)) // FIXME: use forEachObjectFormat
|
||||||
t.Run("CheckMasterBranchSigned", doAPIGetBranch(testCtx, "master", func(t *testing.T, branch api.Branch) {
|
t.Run("CheckMasterBranchSigned", doAPIGetBranch(testCtx, "master", func(t *testing.T, branch api.Branch) {
|
||||||
assert.NotNil(t, branch.Commit)
|
assert.NotNil(t, branch.Commit)
|
||||||
if branch.Commit == nil {
|
if branch.Commit == nil {
|
||||||
|
@ -171,7 +172,7 @@ func TestGPGGit(t *testing.T) {
|
||||||
t.Run("AlwaysSign-Initial-CRUD-Never", func(t *testing.T) {
|
t.Run("AlwaysSign-Initial-CRUD-Never", func(t *testing.T) {
|
||||||
defer tests.PrintCurrentTest(t)()
|
defer tests.PrintCurrentTest(t)()
|
||||||
testCtx := NewAPITestContext(t, username, "initial-always-never", auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
|
testCtx := NewAPITestContext(t, username, "initial-always-never", auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
|
||||||
t.Run("CreateRepository", doAPICreateRepository(testCtx, false))
|
t.Run("CreateRepository", doAPICreateRepository(testCtx, false, git.Sha1ObjectFormat)) // FIXME: use forEachObjectFormat
|
||||||
t.Run("CreateCRUDFile-Never", crudActionCreateFile(
|
t.Run("CreateCRUDFile-Never", crudActionCreateFile(
|
||||||
t, testCtx, user, "master", "never", "unsigned-never.txt", func(t *testing.T, response api.FileResponse) {
|
t, testCtx, user, "master", "never", "unsigned-never.txt", func(t *testing.T, response api.FileResponse) {
|
||||||
assert.False(t, response.Verification.Verified)
|
assert.False(t, response.Verification.Verified)
|
||||||
|
@ -182,7 +183,7 @@ func TestGPGGit(t *testing.T) {
|
||||||
t.Run("AlwaysSign-Initial-CRUD-ParentSigned-On-Always", func(t *testing.T) {
|
t.Run("AlwaysSign-Initial-CRUD-ParentSigned-On-Always", func(t *testing.T) {
|
||||||
defer tests.PrintCurrentTest(t)()
|
defer tests.PrintCurrentTest(t)()
|
||||||
testCtx := NewAPITestContext(t, username, "initial-always-parent", auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
|
testCtx := NewAPITestContext(t, username, "initial-always-parent", auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
|
||||||
t.Run("CreateRepository", doAPICreateRepository(testCtx, false))
|
t.Run("CreateRepository", doAPICreateRepository(testCtx, false, git.Sha1ObjectFormat)) // FIXME: use forEachObjectFormat
|
||||||
t.Run("CreateCRUDFile-ParentSigned", crudActionCreateFile(
|
t.Run("CreateCRUDFile-ParentSigned", crudActionCreateFile(
|
||||||
t, testCtx, user, "master", "parentsigned", "signed-parent.txt", func(t *testing.T, response api.FileResponse) {
|
t, testCtx, user, "master", "parentsigned", "signed-parent.txt", func(t *testing.T, response api.FileResponse) {
|
||||||
assert.True(t, response.Verification.Verified)
|
assert.True(t, response.Verification.Verified)
|
||||||
|
@ -198,7 +199,7 @@ func TestGPGGit(t *testing.T) {
|
||||||
t.Run("AlwaysSign-Initial-CRUD-Always", func(t *testing.T) {
|
t.Run("AlwaysSign-Initial-CRUD-Always", func(t *testing.T) {
|
||||||
defer tests.PrintCurrentTest(t)()
|
defer tests.PrintCurrentTest(t)()
|
||||||
testCtx := NewAPITestContext(t, username, "initial-always-always", auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
|
testCtx := NewAPITestContext(t, username, "initial-always-always", auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
|
||||||
t.Run("CreateRepository", doAPICreateRepository(testCtx, false))
|
t.Run("CreateRepository", doAPICreateRepository(testCtx, false, git.Sha1ObjectFormat)) // FIXME: use forEachObjectFormat
|
||||||
t.Run("CreateCRUDFile-Always", crudActionCreateFile(
|
t.Run("CreateCRUDFile-Always", crudActionCreateFile(
|
||||||
t, testCtx, user, "master", "always", "signed-always.txt", func(t *testing.T, response api.FileResponse) {
|
t, testCtx, user, "master", "always", "signed-always.txt", func(t *testing.T, response api.FileResponse) {
|
||||||
assert.True(t, response.Verification.Verified)
|
assert.True(t, response.Verification.Verified)
|
||||||
|
|
|
@ -47,35 +47,36 @@ func TestPushDeployKeyOnEmptyRepo(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func testPushDeployKeyOnEmptyRepo(t *testing.T, u *url.URL) {
|
func testPushDeployKeyOnEmptyRepo(t *testing.T, u *url.URL) {
|
||||||
// OK login
|
forEachObjectFormat(t, func(t *testing.T, objectFormat git.ObjectFormat) {
|
||||||
ctx := NewAPITestContext(t, "user2", "deploy-key-empty-repo-1", auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
|
// OK login
|
||||||
ctxWithDeleteRepo := NewAPITestContext(t, "user2", "deploy-key-empty-repo-1", auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
|
ctx := NewAPITestContext(t, "user2", "deploy-key-empty-repo-"+objectFormat.Name(), auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
|
||||||
|
|
||||||
keyname := fmt.Sprintf("%s-push", ctx.Reponame)
|
keyname := fmt.Sprintf("%s-push", ctx.Reponame)
|
||||||
u.Path = ctx.GitPath()
|
u.Path = ctx.GitPath()
|
||||||
|
|
||||||
t.Run("CreateEmptyRepository", doAPICreateRepository(ctx, true))
|
t.Run("CreateEmptyRepository", doAPICreateRepository(ctx, true, objectFormat))
|
||||||
|
|
||||||
t.Run("CheckIsEmpty", doCheckRepositoryEmptyStatus(ctx, true))
|
t.Run("CheckIsEmpty", doCheckRepositoryEmptyStatus(ctx, true))
|
||||||
|
|
||||||
withKeyFile(t, keyname, func(keyFile string) {
|
withKeyFile(t, keyname, func(keyFile string) {
|
||||||
t.Run("CreatePushDeployKey", doAPICreateDeployKey(ctx, keyname, keyFile, false))
|
t.Run("CreatePushDeployKey", doAPICreateDeployKey(ctx, keyname, keyFile, false))
|
||||||
|
|
||||||
// Setup the testing repository
|
// Setup the testing repository
|
||||||
dstPath := t.TempDir()
|
dstPath := t.TempDir()
|
||||||
|
|
||||||
t.Run("InitTestRepository", doGitInitTestRepository(dstPath, git.Sha1ObjectFormat)) // FIXME: use forEachObjectFormat
|
t.Run("InitTestRepository", doGitInitTestRepository(dstPath, objectFormat))
|
||||||
|
|
||||||
// Setup remote link
|
// Setup remote link
|
||||||
sshURL := createSSHUrl(ctx.GitPath(), u)
|
sshURL := createSSHUrl(ctx.GitPath(), u)
|
||||||
|
|
||||||
t.Run("AddRemote", doGitAddRemote(dstPath, "origin", sshURL))
|
t.Run("AddRemote", doGitAddRemote(dstPath, "origin", sshURL))
|
||||||
|
|
||||||
t.Run("SSHPushTestRepository", doGitPushTestRepository(dstPath, "origin", "master"))
|
t.Run("SSHPushTestRepository", doGitPushTestRepository(dstPath, "origin", "master"))
|
||||||
|
|
||||||
t.Run("CheckIsNotEmpty", doCheckRepositoryEmptyStatus(ctx, false))
|
t.Run("CheckIsNotEmpty", doCheckRepositoryEmptyStatus(ctx, false))
|
||||||
|
|
||||||
t.Run("DeleteRepository", doAPIDeleteRepository(ctxWithDeleteRepo))
|
t.Run("DeleteRepository", doAPIDeleteRepository(ctx))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,8 +104,8 @@ func testKeyOnlyOneType(t *testing.T, u *url.URL) {
|
||||||
failCtx := ctx
|
failCtx := ctx
|
||||||
failCtx.ExpectedCode = http.StatusUnprocessableEntity
|
failCtx.ExpectedCode = http.StatusUnprocessableEntity
|
||||||
|
|
||||||
t.Run("CreateRepository", doAPICreateRepository(ctx, false))
|
t.Run("CreateRepository", doAPICreateRepository(ctx, false, git.Sha1ObjectFormat)) // FIXME: use forEachObjectFormat
|
||||||
t.Run("CreateOtherRepository", doAPICreateRepository(otherCtx, false))
|
t.Run("CreateOtherRepository", doAPICreateRepository(otherCtx, false, git.Sha1ObjectFormat)) // FIXME: use forEachObjectFormat
|
||||||
|
|
||||||
withKeyFile(t, keyname, func(keyFile string) {
|
withKeyFile(t, keyname, func(keyFile string) {
|
||||||
var userKeyPublicKeyID int64
|
var userKeyPublicKeyID int64
|
||||||
|
@ -178,7 +179,7 @@ func testKeyOnlyOneType(t *testing.T, u *url.URL) {
|
||||||
|
|
||||||
t.Run("DeleteOtherRepository", doAPIDeleteRepository(otherCtxWithDeleteRepo))
|
t.Run("DeleteOtherRepository", doAPIDeleteRepository(otherCtxWithDeleteRepo))
|
||||||
|
|
||||||
t.Run("RecreateRepository", doAPICreateRepository(ctxWithDeleteRepo, false))
|
t.Run("RecreateRepository", doAPICreateRepository(ctxWithDeleteRepo, false, git.Sha1ObjectFormat)) // FIXME: use forEachObjectFormat
|
||||||
|
|
||||||
t.Run("CreateUserKey", doAPICreateUserKey(ctx, keyname, keyFile, func(t *testing.T, publicKey api.PublicKey) {
|
t.Run("CreateUserKey", doAPICreateUserKey(ctx, keyname, keyFile, func(t *testing.T, publicKey api.PublicKey) {
|
||||||
userKeyPublicKeyID = publicKey.ID
|
userKeyPublicKeyID = publicKey.ID
|
||||||
|
|
Loading…
Add table
Reference in a new issue