|
|
@ -13,11 +13,13 @@ import ( |
|
|
|
"os" |
|
|
|
"os" |
|
|
|
"path" |
|
|
|
"path" |
|
|
|
"path/filepath" |
|
|
|
"path/filepath" |
|
|
|
|
|
|
|
"strconv" |
|
|
|
"testing" |
|
|
|
"testing" |
|
|
|
"time" |
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models" |
|
|
|
"code.gitea.io/gitea/models" |
|
|
|
"code.gitea.io/gitea/modules/git" |
|
|
|
"code.gitea.io/gitea/modules/git" |
|
|
|
|
|
|
|
api "code.gitea.io/gitea/modules/structs" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert" |
|
|
|
"github.com/stretchr/testify/assert" |
|
|
|
) |
|
|
|
) |
|
|
@ -43,119 +45,23 @@ func testGit(t *testing.T, u *url.URL) { |
|
|
|
httpContext.Reponame = "repo-tmp-17" |
|
|
|
httpContext.Reponame = "repo-tmp-17" |
|
|
|
|
|
|
|
|
|
|
|
dstPath, err := ioutil.TempDir("", httpContext.Reponame) |
|
|
|
dstPath, err := ioutil.TempDir("", httpContext.Reponame) |
|
|
|
var little, big, littleLFS, bigLFS string |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert.NoError(t, err) |
|
|
|
assert.NoError(t, err) |
|
|
|
defer os.RemoveAll(dstPath) |
|
|
|
defer os.RemoveAll(dstPath) |
|
|
|
t.Run("Standard", func(t *testing.T) { |
|
|
|
|
|
|
|
PrintCurrentTest(t) |
|
|
|
|
|
|
|
ensureAnonymousClone(t, u) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t.Run("CreateRepo", doAPICreateRepository(httpContext, false)) |
|
|
|
t.Run("CreateRepo", doAPICreateRepository(httpContext, false)) |
|
|
|
|
|
|
|
ensureAnonymousClone(t, u) |
|
|
|
|
|
|
|
|
|
|
|
u.Path = httpContext.GitPath() |
|
|
|
u.Path = httpContext.GitPath() |
|
|
|
u.User = url.UserPassword(username, userPassword) |
|
|
|
u.User = url.UserPassword(username, userPassword) |
|
|
|
|
|
|
|
|
|
|
|
t.Run("Clone", doGitClone(dstPath, u)) |
|
|
|
t.Run("Clone", doGitClone(dstPath, u)) |
|
|
|
|
|
|
|
|
|
|
|
t.Run("PushCommit", func(t *testing.T) { |
|
|
|
little, big := standardCommitAndPushTest(t, dstPath) |
|
|
|
PrintCurrentTest(t) |
|
|
|
littleLFS, bigLFS := lfsCommitAndPushTest(t, dstPath) |
|
|
|
t.Run("Little", func(t *testing.T) { |
|
|
|
rawTest(t, &httpContext, little, big, littleLFS, bigLFS) |
|
|
|
PrintCurrentTest(t) |
|
|
|
mediaTest(t, &httpContext, little, big, littleLFS, bigLFS) |
|
|
|
little = commitAndPush(t, littleSize, dstPath) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
t.Run("Big", func(t *testing.T) { |
|
|
|
|
|
|
|
if testing.Short() { |
|
|
|
|
|
|
|
t.Skip("skipping test in short mode.") |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
PrintCurrentTest(t) |
|
|
|
|
|
|
|
big = commitAndPush(t, bigSize, dstPath) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
t.Run("LFS", func(t *testing.T) { |
|
|
|
|
|
|
|
PrintCurrentTest(t) |
|
|
|
|
|
|
|
t.Run("PushCommit", func(t *testing.T) { |
|
|
|
|
|
|
|
PrintCurrentTest(t) |
|
|
|
|
|
|
|
//Setup git LFS
|
|
|
|
|
|
|
|
_, err = git.NewCommand("lfs").AddArguments("install").RunInDir(dstPath) |
|
|
|
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
|
|
|
_, err = git.NewCommand("lfs").AddArguments("track", "data-file-*").RunInDir(dstPath) |
|
|
|
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
|
|
|
err = git.AddChanges(dstPath, false, ".gitattributes") |
|
|
|
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t.Run("Little", func(t *testing.T) { |
|
|
|
|
|
|
|
PrintCurrentTest(t) |
|
|
|
|
|
|
|
littleLFS = commitAndPush(t, littleSize, dstPath) |
|
|
|
|
|
|
|
lockFileTest(t, littleLFS, dstPath) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
t.Run("Big", func(t *testing.T) { |
|
|
|
|
|
|
|
if testing.Short() { |
|
|
|
|
|
|
|
t.Skip("skipping test in short mode.") |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
PrintCurrentTest(t) |
|
|
|
|
|
|
|
bigLFS = commitAndPush(t, bigSize, dstPath) |
|
|
|
|
|
|
|
lockFileTest(t, bigLFS, dstPath) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
t.Run("Locks", func(t *testing.T) { |
|
|
|
|
|
|
|
PrintCurrentTest(t) |
|
|
|
|
|
|
|
lockTest(t, u.String(), dstPath) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
t.Run("Raw", func(t *testing.T) { |
|
|
|
|
|
|
|
PrintCurrentTest(t) |
|
|
|
|
|
|
|
session := loginUser(t, "user2") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Request raw paths
|
|
|
|
|
|
|
|
req := NewRequest(t, "GET", path.Join("/user2/repo-tmp-17/raw/branch/master/", little)) |
|
|
|
|
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK) |
|
|
|
|
|
|
|
assert.Equal(t, littleSize, resp.Body.Len()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
req = NewRequest(t, "GET", path.Join("/user2/repo-tmp-17/raw/branch/master/", littleLFS)) |
|
|
|
|
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK) |
|
|
|
|
|
|
|
assert.NotEqual(t, littleSize, resp.Body.Len()) |
|
|
|
|
|
|
|
assert.Contains(t, resp.Body.String(), models.LFSMetaFileIdentifier) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !testing.Short() { |
|
|
|
|
|
|
|
req = NewRequest(t, "GET", path.Join("/user2/repo-tmp-17/raw/branch/master/", big)) |
|
|
|
|
|
|
|
nilResp := session.MakeRequestNilResponseRecorder(t, req, http.StatusOK) |
|
|
|
|
|
|
|
assert.Equal(t, bigSize, nilResp.Length) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
req = NewRequest(t, "GET", path.Join("/user2/repo-tmp-17/raw/branch/master/", bigLFS)) |
|
|
|
|
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK) |
|
|
|
|
|
|
|
assert.NotEqual(t, bigSize, resp.Body.Len()) |
|
|
|
|
|
|
|
assert.Contains(t, resp.Body.String(), models.LFSMetaFileIdentifier) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
t.Run("Media", func(t *testing.T) { |
|
|
|
|
|
|
|
PrintCurrentTest(t) |
|
|
|
|
|
|
|
session := loginUser(t, "user2") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Request media paths
|
|
|
|
|
|
|
|
req := NewRequest(t, "GET", path.Join("/user2/repo-tmp-17/media/branch/master/", little)) |
|
|
|
|
|
|
|
resp := session.MakeRequestNilResponseRecorder(t, req, http.StatusOK) |
|
|
|
|
|
|
|
assert.Equal(t, littleSize, resp.Length) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
req = NewRequest(t, "GET", path.Join("/user2/repo-tmp-17/media/branch/master/", littleLFS)) |
|
|
|
|
|
|
|
resp = session.MakeRequestNilResponseRecorder(t, req, http.StatusOK) |
|
|
|
|
|
|
|
assert.Equal(t, littleSize, resp.Length) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !testing.Short() { |
|
|
|
|
|
|
|
req = NewRequest(t, "GET", path.Join("/user2/repo-tmp-17/media/branch/master/", big)) |
|
|
|
|
|
|
|
resp = session.MakeRequestNilResponseRecorder(t, req, http.StatusOK) |
|
|
|
|
|
|
|
assert.Equal(t, bigSize, resp.Length) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
req = NewRequest(t, "GET", path.Join("/user2/repo-tmp-17/media/branch/master/", bigLFS)) |
|
|
|
|
|
|
|
resp = session.MakeRequestNilResponseRecorder(t, req, http.StatusOK) |
|
|
|
|
|
|
|
assert.Equal(t, bigSize, resp.Length) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t.Run("BranchProtectMerge", doBranchProtectPRMerge(&httpContext, dstPath)) |
|
|
|
}) |
|
|
|
}) |
|
|
|
t.Run("SSH", func(t *testing.T) { |
|
|
|
t.Run("SSH", func(t *testing.T) { |
|
|
|
PrintCurrentTest(t) |
|
|
|
PrintCurrentTest(t) |
|
|
@ -165,137 +71,149 @@ func testGit(t *testing.T, u *url.URL) { |
|
|
|
//Setup key the user ssh key
|
|
|
|
//Setup key the user ssh key
|
|
|
|
withKeyFile(t, keyname, func(keyFile string) { |
|
|
|
withKeyFile(t, keyname, func(keyFile string) { |
|
|
|
t.Run("CreateUserKey", doAPICreateUserKey(sshContext, "test-key", keyFile)) |
|
|
|
t.Run("CreateUserKey", doAPICreateUserKey(sshContext, "test-key", keyFile)) |
|
|
|
PrintCurrentTest(t) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Setup remote link
|
|
|
|
//Setup remote link
|
|
|
|
|
|
|
|
//TODO: get url from api
|
|
|
|
sshURL := createSSHUrl(sshContext.GitPath(), u) |
|
|
|
sshURL := createSSHUrl(sshContext.GitPath(), u) |
|
|
|
|
|
|
|
|
|
|
|
//Setup clone folder
|
|
|
|
//Setup clone folder
|
|
|
|
dstPath, err := ioutil.TempDir("", sshContext.Reponame) |
|
|
|
dstPath, err := ioutil.TempDir("", sshContext.Reponame) |
|
|
|
assert.NoError(t, err) |
|
|
|
assert.NoError(t, err) |
|
|
|
defer os.RemoveAll(dstPath) |
|
|
|
defer os.RemoveAll(dstPath) |
|
|
|
var little, big, littleLFS, bigLFS string |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t.Run("Standard", func(t *testing.T) { |
|
|
|
|
|
|
|
PrintCurrentTest(t) |
|
|
|
|
|
|
|
t.Run("CreateRepo", doAPICreateRepository(sshContext, false)) |
|
|
|
t.Run("CreateRepo", doAPICreateRepository(sshContext, false)) |
|
|
|
|
|
|
|
|
|
|
|
//TODO get url from api
|
|
|
|
|
|
|
|
t.Run("Clone", doGitClone(dstPath, sshURL)) |
|
|
|
t.Run("Clone", doGitClone(dstPath, sshURL)) |
|
|
|
|
|
|
|
|
|
|
|
//time.Sleep(5 * time.Minute)
|
|
|
|
little, big := standardCommitAndPushTest(t, dstPath) |
|
|
|
t.Run("PushCommit", func(t *testing.T) { |
|
|
|
littleLFS, bigLFS := lfsCommitAndPushTest(t, dstPath) |
|
|
|
PrintCurrentTest(t) |
|
|
|
rawTest(t, &sshContext, little, big, littleLFS, bigLFS) |
|
|
|
t.Run("Little", func(t *testing.T) { |
|
|
|
mediaTest(t, &sshContext, little, big, littleLFS, bigLFS) |
|
|
|
PrintCurrentTest(t) |
|
|
|
|
|
|
|
little = commitAndPush(t, littleSize, dstPath) |
|
|
|
t.Run("BranchProtectMerge", doBranchProtectPRMerge(&sshContext, dstPath)) |
|
|
|
}) |
|
|
|
|
|
|
|
t.Run("Big", func(t *testing.T) { |
|
|
|
|
|
|
|
if testing.Short() { |
|
|
|
|
|
|
|
t.Skip("skipping test in short mode.") |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
PrintCurrentTest(t) |
|
|
|
|
|
|
|
big = commitAndPush(t, bigSize, dstPath) |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func ensureAnonymousClone(t *testing.T, u *url.URL) { |
|
|
|
|
|
|
|
dstLocalPath, err := ioutil.TempDir("", "repo1") |
|
|
|
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
|
|
|
defer os.RemoveAll(dstLocalPath) |
|
|
|
|
|
|
|
t.Run("CloneAnonymous", doGitClone(dstLocalPath, u)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func standardCommitAndPushTest(t *testing.T, dstPath string) (little, big string) { |
|
|
|
|
|
|
|
t.Run("Standard", func(t *testing.T) { |
|
|
|
|
|
|
|
PrintCurrentTest(t) |
|
|
|
|
|
|
|
little, big = commitAndPushTest(t, dstPath, "data-file-") |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func lfsCommitAndPushTest(t *testing.T, dstPath string) (littleLFS, bigLFS string) { |
|
|
|
t.Run("LFS", func(t *testing.T) { |
|
|
|
t.Run("LFS", func(t *testing.T) { |
|
|
|
PrintCurrentTest(t) |
|
|
|
PrintCurrentTest(t) |
|
|
|
t.Run("PushCommit", func(t *testing.T) { |
|
|
|
prefix := "lfs-data-file-" |
|
|
|
PrintCurrentTest(t) |
|
|
|
_, err := git.NewCommand("lfs").AddArguments("install").RunInDir(dstPath) |
|
|
|
//Setup git LFS
|
|
|
|
|
|
|
|
_, err = git.NewCommand("lfs").AddArguments("install").RunInDir(dstPath) |
|
|
|
|
|
|
|
assert.NoError(t, err) |
|
|
|
assert.NoError(t, err) |
|
|
|
_, err = git.NewCommand("lfs").AddArguments("track", "data-file-*").RunInDir(dstPath) |
|
|
|
_, err = git.NewCommand("lfs").AddArguments("track", prefix+"*").RunInDir(dstPath) |
|
|
|
assert.NoError(t, err) |
|
|
|
assert.NoError(t, err) |
|
|
|
err = git.AddChanges(dstPath, false, ".gitattributes") |
|
|
|
err = git.AddChanges(dstPath, false, ".gitattributes") |
|
|
|
assert.NoError(t, err) |
|
|
|
assert.NoError(t, err) |
|
|
|
|
|
|
|
|
|
|
|
t.Run("Little", func(t *testing.T) { |
|
|
|
littleLFS, bigLFS = commitAndPushTest(t, dstPath, prefix) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t.Run("Locks", func(t *testing.T) { |
|
|
|
PrintCurrentTest(t) |
|
|
|
PrintCurrentTest(t) |
|
|
|
littleLFS = commitAndPush(t, littleSize, dstPath) |
|
|
|
lockTest(t, dstPath) |
|
|
|
lockFileTest(t, littleLFS, dstPath) |
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func commitAndPushTest(t *testing.T, dstPath, prefix string) (little, big string) { |
|
|
|
|
|
|
|
t.Run("PushCommit", func(t *testing.T) { |
|
|
|
|
|
|
|
PrintCurrentTest(t) |
|
|
|
|
|
|
|
t.Run("Little", func(t *testing.T) { |
|
|
|
|
|
|
|
PrintCurrentTest(t) |
|
|
|
|
|
|
|
little = doCommitAndPush(t, littleSize, dstPath, prefix) |
|
|
|
}) |
|
|
|
}) |
|
|
|
t.Run("Big", func(t *testing.T) { |
|
|
|
t.Run("Big", func(t *testing.T) { |
|
|
|
if testing.Short() { |
|
|
|
if testing.Short() { |
|
|
|
|
|
|
|
t.Skip("Skipping test in short mode.") |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
PrintCurrentTest(t) |
|
|
|
PrintCurrentTest(t) |
|
|
|
bigLFS = commitAndPush(t, bigSize, dstPath) |
|
|
|
big = doCommitAndPush(t, bigSize, dstPath, prefix) |
|
|
|
lockFileTest(t, bigLFS, dstPath) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
t.Run("Locks", func(t *testing.T) { |
|
|
|
|
|
|
|
PrintCurrentTest(t) |
|
|
|
|
|
|
|
lockTest(t, u.String(), dstPath) |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func rawTest(t *testing.T, ctx *APITestContext, little, big, littleLFS, bigLFS string) { |
|
|
|
t.Run("Raw", func(t *testing.T) { |
|
|
|
t.Run("Raw", func(t *testing.T) { |
|
|
|
PrintCurrentTest(t) |
|
|
|
PrintCurrentTest(t) |
|
|
|
session := loginUser(t, "user2") |
|
|
|
username := ctx.Username |
|
|
|
|
|
|
|
reponame := ctx.Reponame |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
session := loginUser(t, username) |
|
|
|
|
|
|
|
|
|
|
|
// Request raw paths
|
|
|
|
// Request raw paths
|
|
|
|
req := NewRequest(t, "GET", path.Join("/user2/repo-tmp-18/raw/branch/master/", little)) |
|
|
|
req := NewRequest(t, "GET", path.Join("/", username, reponame, "/raw/branch/master/", little)) |
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK) |
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK) |
|
|
|
assert.Equal(t, littleSize, resp.Body.Len()) |
|
|
|
assert.Equal(t, littleSize, resp.Body.Len()) |
|
|
|
|
|
|
|
|
|
|
|
req = NewRequest(t, "GET", path.Join("/user2/repo-tmp-18/raw/branch/master/", littleLFS)) |
|
|
|
req = NewRequest(t, "GET", path.Join("/", username, reponame, "/raw/branch/master/", littleLFS)) |
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK) |
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK) |
|
|
|
assert.NotEqual(t, littleSize, resp.Body.Len()) |
|
|
|
assert.NotEqual(t, littleSize, resp.Body.Len()) |
|
|
|
assert.Contains(t, resp.Body.String(), models.LFSMetaFileIdentifier) |
|
|
|
assert.Contains(t, resp.Body.String(), models.LFSMetaFileIdentifier) |
|
|
|
|
|
|
|
|
|
|
|
if !testing.Short() { |
|
|
|
if !testing.Short() { |
|
|
|
req = NewRequest(t, "GET", path.Join("/user2/repo-tmp-18/raw/branch/master/", big)) |
|
|
|
req = NewRequest(t, "GET", path.Join("/", username, reponame, "/raw/branch/master/", big)) |
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK) |
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK) |
|
|
|
assert.Equal(t, bigSize, resp.Body.Len()) |
|
|
|
assert.Equal(t, bigSize, resp.Body.Len()) |
|
|
|
|
|
|
|
|
|
|
|
req = NewRequest(t, "GET", path.Join("/user2/repo-tmp-18/raw/branch/master/", bigLFS)) |
|
|
|
req = NewRequest(t, "GET", path.Join("/", username, reponame, "/raw/branch/master/", bigLFS)) |
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK) |
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK) |
|
|
|
assert.NotEqual(t, bigSize, resp.Body.Len()) |
|
|
|
assert.NotEqual(t, bigSize, resp.Body.Len()) |
|
|
|
assert.Contains(t, resp.Body.String(), models.LFSMetaFileIdentifier) |
|
|
|
assert.Contains(t, resp.Body.String(), models.LFSMetaFileIdentifier) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func mediaTest(t *testing.T, ctx *APITestContext, little, big, littleLFS, bigLFS string) { |
|
|
|
t.Run("Media", func(t *testing.T) { |
|
|
|
t.Run("Media", func(t *testing.T) { |
|
|
|
PrintCurrentTest(t) |
|
|
|
PrintCurrentTest(t) |
|
|
|
session := loginUser(t, "user2") |
|
|
|
|
|
|
|
|
|
|
|
username := ctx.Username |
|
|
|
|
|
|
|
reponame := ctx.Reponame |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
session := loginUser(t, username) |
|
|
|
|
|
|
|
|
|
|
|
// Request media paths
|
|
|
|
// Request media paths
|
|
|
|
req := NewRequest(t, "GET", path.Join("/user2/repo-tmp-18/media/branch/master/", little)) |
|
|
|
req := NewRequest(t, "GET", path.Join("/", username, reponame, "/media/branch/master/", little)) |
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK) |
|
|
|
resp := session.MakeRequestNilResponseRecorder(t, req, http.StatusOK) |
|
|
|
assert.Equal(t, littleSize, resp.Body.Len()) |
|
|
|
assert.Equal(t, littleSize, resp.Length) |
|
|
|
|
|
|
|
|
|
|
|
req = NewRequest(t, "GET", path.Join("/user2/repo-tmp-18/media/branch/master/", littleLFS)) |
|
|
|
req = NewRequest(t, "GET", path.Join("/", username, reponame, "/media/branch/master/", littleLFS)) |
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK) |
|
|
|
resp = session.MakeRequestNilResponseRecorder(t, req, http.StatusOK) |
|
|
|
assert.Equal(t, littleSize, resp.Body.Len()) |
|
|
|
assert.Equal(t, littleSize, resp.Length) |
|
|
|
|
|
|
|
|
|
|
|
if !testing.Short() { |
|
|
|
if !testing.Short() { |
|
|
|
req = NewRequest(t, "GET", path.Join("/user2/repo-tmp-18/media/branch/master/", big)) |
|
|
|
req = NewRequest(t, "GET", path.Join("/", username, reponame, "/media/branch/master/", big)) |
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK) |
|
|
|
resp = session.MakeRequestNilResponseRecorder(t, req, http.StatusOK) |
|
|
|
assert.Equal(t, bigSize, resp.Body.Len()) |
|
|
|
assert.Equal(t, bigSize, resp.Length) |
|
|
|
|
|
|
|
|
|
|
|
req = NewRequest(t, "GET", path.Join("/user2/repo-tmp-18/media/branch/master/", bigLFS)) |
|
|
|
req = NewRequest(t, "GET", path.Join("/", username, reponame, "/media/branch/master/", bigLFS)) |
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK) |
|
|
|
resp = session.MakeRequestNilResponseRecorder(t, req, http.StatusOK) |
|
|
|
assert.Equal(t, bigSize, resp.Body.Len()) |
|
|
|
assert.Equal(t, bigSize, resp.Length) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func ensureAnonymousClone(t *testing.T, u *url.URL) { |
|
|
|
func lockTest(t *testing.T, repoPath string) { |
|
|
|
dstLocalPath, err := ioutil.TempDir("", "repo1") |
|
|
|
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
|
|
|
defer os.RemoveAll(dstLocalPath) |
|
|
|
|
|
|
|
t.Run("CloneAnonymous", doGitClone(dstLocalPath, u)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func lockTest(t *testing.T, remote, repoPath string) { |
|
|
|
|
|
|
|
lockFileTest(t, "README.md", repoPath) |
|
|
|
lockFileTest(t, "README.md", repoPath) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -310,22 +228,22 @@ func lockFileTest(t *testing.T, filename, repoPath string) { |
|
|
|
assert.NoError(t, err) |
|
|
|
assert.NoError(t, err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func commitAndPush(t *testing.T, size int, repoPath string) string { |
|
|
|
func doCommitAndPush(t *testing.T, size int, repoPath, prefix string) string { |
|
|
|
name, err := generateCommitWithNewData(size, repoPath, "user2@example.com", "User Two") |
|
|
|
name, err := generateCommitWithNewData(size, repoPath, "user2@example.com", "User Two", prefix) |
|
|
|
assert.NoError(t, err) |
|
|
|
assert.NoError(t, err) |
|
|
|
_, err = git.NewCommand("push").RunInDir(repoPath) //Push
|
|
|
|
_, err = git.NewCommand("push", "origin", "master").RunInDir(repoPath) //Push
|
|
|
|
assert.NoError(t, err) |
|
|
|
assert.NoError(t, err) |
|
|
|
return name |
|
|
|
return name |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func generateCommitWithNewData(size int, repoPath, email, fullName string) (string, error) { |
|
|
|
func generateCommitWithNewData(size int, repoPath, email, fullName, prefix string) (string, error) { |
|
|
|
//Generate random file
|
|
|
|
//Generate random file
|
|
|
|
data := make([]byte, size) |
|
|
|
data := make([]byte, size) |
|
|
|
_, err := rand.Read(data) |
|
|
|
_, err := rand.Read(data) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return "", err |
|
|
|
return "", err |
|
|
|
} |
|
|
|
} |
|
|
|
tmpFile, err := ioutil.TempFile(repoPath, "data-file-") |
|
|
|
tmpFile, err := ioutil.TempFile(repoPath, prefix) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return "", err |
|
|
|
return "", err |
|
|
|
} |
|
|
|
} |
|
|
@ -355,3 +273,71 @@ func generateCommitWithNewData(size int, repoPath, email, fullName string) (stri |
|
|
|
}) |
|
|
|
}) |
|
|
|
return filepath.Base(tmpFile.Name()), err |
|
|
|
return filepath.Base(tmpFile.Name()), err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func doBranchProtectPRMerge(baseCtx *APITestContext, dstPath string) func(t *testing.T) { |
|
|
|
|
|
|
|
return func(t *testing.T) { |
|
|
|
|
|
|
|
PrintCurrentTest(t) |
|
|
|
|
|
|
|
t.Run("CreateBranchProtected", doGitCreateBranch(dstPath, "protected")) |
|
|
|
|
|
|
|
t.Run("PushProtectedBranch", doGitPushTestRepository(dstPath, "origin", "protected")) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctx := NewAPITestContext(t, baseCtx.Username, baseCtx.Reponame) |
|
|
|
|
|
|
|
t.Run("ProtectProtectedBranchNoWhitelist", doProtectBranch(ctx, "protected", "")) |
|
|
|
|
|
|
|
t.Run("GenerateCommit", func(t *testing.T) { |
|
|
|
|
|
|
|
_, err := generateCommitWithNewData(littleSize, dstPath, "user2@example.com", "User Two", "branch-data-file-") |
|
|
|
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
t.Run("FailToPushToProtectedBranch", doGitPushTestRepositoryFail(dstPath, "origin", "protected")) |
|
|
|
|
|
|
|
t.Run("PushToUnprotectedBranch", doGitPushTestRepository(dstPath, "origin", "protected:unprotected")) |
|
|
|
|
|
|
|
var pr api.PullRequest |
|
|
|
|
|
|
|
var err error |
|
|
|
|
|
|
|
t.Run("CreatePullRequest", func(t *testing.T) { |
|
|
|
|
|
|
|
pr, err = doAPICreatePullRequest(ctx, baseCtx.Username, baseCtx.Reponame, "protected", "unprotected")(t) |
|
|
|
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
t.Run("MergePR", doAPIMergePullRequest(ctx, baseCtx.Username, baseCtx.Reponame, pr.Index)) |
|
|
|
|
|
|
|
t.Run("PullProtected", doGitPull(dstPath, "origin", "protected")) |
|
|
|
|
|
|
|
t.Run("ProtectProtectedBranchWhitelist", doProtectBranch(ctx, "protected", baseCtx.Username)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t.Run("CheckoutMaster", doGitCheckoutBranch(dstPath, "master")) |
|
|
|
|
|
|
|
t.Run("CreateBranchForced", doGitCreateBranch(dstPath, "toforce")) |
|
|
|
|
|
|
|
t.Run("GenerateCommit", func(t *testing.T) { |
|
|
|
|
|
|
|
_, err := generateCommitWithNewData(littleSize, dstPath, "user2@example.com", "User Two", "branch-data-file-") |
|
|
|
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
t.Run("FailToForcePushToProtectedBranch", doGitPushTestRepositoryFail(dstPath, "-f", "origin", "toforce:protected")) |
|
|
|
|
|
|
|
t.Run("MergeProtectedToToforce", doGitMerge(dstPath, "protected")) |
|
|
|
|
|
|
|
t.Run("PushToProtectedBranch", doGitPushTestRepository(dstPath, "origin", "toforce:protected")) |
|
|
|
|
|
|
|
t.Run("CheckoutMasterAgain", doGitCheckoutBranch(dstPath, "master")) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func doProtectBranch(ctx APITestContext, branch string, userToWhitelist string) func(t *testing.T) { |
|
|
|
|
|
|
|
// We are going to just use the owner to set the protection.
|
|
|
|
|
|
|
|
return func(t *testing.T) { |
|
|
|
|
|
|
|
csrf := GetCSRF(t, ctx.Session, fmt.Sprintf("/%s/%s/settings/branches", url.PathEscape(ctx.Username), url.PathEscape(ctx.Reponame))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if userToWhitelist == "" { |
|
|
|
|
|
|
|
// Change branch to protected
|
|
|
|
|
|
|
|
req := NewRequestWithValues(t, "POST", fmt.Sprintf("/%s/%s/settings/branches/%s", url.PathEscape(ctx.Username), url.PathEscape(ctx.Reponame), url.PathEscape(branch)), map[string]string{ |
|
|
|
|
|
|
|
"_csrf": csrf, |
|
|
|
|
|
|
|
"protected": "on", |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
ctx.Session.MakeRequest(t, req, http.StatusFound) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
user, err := models.GetUserByName(userToWhitelist) |
|
|
|
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
|
|
|
// Change branch to protected
|
|
|
|
|
|
|
|
req := NewRequestWithValues(t, "POST", fmt.Sprintf("/%s/%s/settings/branches/%s", url.PathEscape(ctx.Username), url.PathEscape(ctx.Reponame), url.PathEscape(branch)), map[string]string{ |
|
|
|
|
|
|
|
"_csrf": csrf, |
|
|
|
|
|
|
|
"protected": "on", |
|
|
|
|
|
|
|
"enable_whitelist": "on", |
|
|
|
|
|
|
|
"whitelist_users": strconv.FormatInt(user.ID, 10), |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
ctx.Session.MakeRequest(t, req, http.StatusFound) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Check if master branch has been locked successfully
|
|
|
|
|
|
|
|
flashCookie := ctx.Session.GetCookie("macaron_flash") |
|
|
|
|
|
|
|
assert.NotNil(t, flashCookie) |
|
|
|
|
|
|
|
assert.EqualValues(t, "success%3DBranch%2Bprotection%2Bfor%2Bbranch%2B%2527"+url.QueryEscape(branch)+"%2527%2Bhas%2Bbeen%2Bupdated.", flashCookie.Value) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|