|
|
@ -5,9 +5,7 @@ |
|
|
|
package integrations |
|
|
|
package integrations |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"bytes" |
|
|
|
|
|
|
|
"net/http" |
|
|
|
"net/http" |
|
|
|
"net/url" |
|
|
|
|
|
|
|
"path" |
|
|
|
"path" |
|
|
|
"testing" |
|
|
|
"testing" |
|
|
|
|
|
|
|
|
|
|
@ -17,28 +15,25 @@ import ( |
|
|
|
func TestCreateFile(t *testing.T) { |
|
|
|
func TestCreateFile(t *testing.T) { |
|
|
|
prepareTestEnv(t) |
|
|
|
prepareTestEnv(t) |
|
|
|
|
|
|
|
|
|
|
|
session := loginUser(t, "user2", "password") |
|
|
|
session := loginUser(t, "user2") |
|
|
|
|
|
|
|
|
|
|
|
// Request editor page
|
|
|
|
// Request editor page
|
|
|
|
req := NewRequest(t, "GET", "/user2/repo1/_new/master/") |
|
|
|
req := NewRequest(t, "GET", "/user2/repo1/_new/master/") |
|
|
|
resp := session.MakeRequest(t, req) |
|
|
|
resp := session.MakeRequest(t, req) |
|
|
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode) |
|
|
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode) |
|
|
|
|
|
|
|
|
|
|
|
doc, err := NewHtmlParser(resp.Body) |
|
|
|
doc := NewHtmlParser(t, resp.Body) |
|
|
|
assert.NoError(t, err) |
|
|
|
|
|
|
|
lastCommit := doc.GetInputValueByName("last_commit") |
|
|
|
lastCommit := doc.GetInputValueByName("last_commit") |
|
|
|
assert.NotEmpty(t, lastCommit) |
|
|
|
assert.NotEmpty(t, lastCommit) |
|
|
|
|
|
|
|
|
|
|
|
// Save new file to master branch
|
|
|
|
// Save new file to master branch
|
|
|
|
req = NewRequestBody(t, "POST", "/user2/repo1/_new/master/", |
|
|
|
req = NewRequestWithValues(t, "POST", "/user2/repo1/_new/master/", map[string]string{ |
|
|
|
bytes.NewBufferString(url.Values{ |
|
|
|
"_csrf": doc.GetCSRF(), |
|
|
|
"_csrf": []string{doc.GetInputValueByName("_csrf")}, |
|
|
|
"last_commit": lastCommit, |
|
|
|
"last_commit": []string{lastCommit}, |
|
|
|
"tree_path": "test.txt", |
|
|
|
"tree_path": []string{"test.txt"}, |
|
|
|
"content": "Content", |
|
|
|
"content": []string{"Content"}, |
|
|
|
"commit_choice": "direct", |
|
|
|
"commit_choice": []string{"direct"}, |
|
|
|
}) |
|
|
|
}.Encode()), |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
req.Header.Add("Content-Type", "application/x-www-form-urlencoded") |
|
|
|
req.Header.Add("Content-Type", "application/x-www-form-urlencoded") |
|
|
|
resp = session.MakeRequest(t, req) |
|
|
|
resp = session.MakeRequest(t, req) |
|
|
|
assert.EqualValues(t, http.StatusFound, resp.HeaderCode) |
|
|
|
assert.EqualValues(t, http.StatusFound, resp.HeaderCode) |
|
|
@ -47,25 +42,21 @@ func TestCreateFile(t *testing.T) { |
|
|
|
func TestCreateFileOnProtectedBranch(t *testing.T) { |
|
|
|
func TestCreateFileOnProtectedBranch(t *testing.T) { |
|
|
|
prepareTestEnv(t) |
|
|
|
prepareTestEnv(t) |
|
|
|
|
|
|
|
|
|
|
|
session := loginUser(t, "user2", "password") |
|
|
|
session := loginUser(t, "user2") |
|
|
|
|
|
|
|
|
|
|
|
// Open repository branch settings
|
|
|
|
// Open repository branch settings
|
|
|
|
req := NewRequest(t, "GET", "/user2/repo1/settings/branches") |
|
|
|
req := NewRequest(t, "GET", "/user2/repo1/settings/branches") |
|
|
|
resp := session.MakeRequest(t, req) |
|
|
|
resp := session.MakeRequest(t, req) |
|
|
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode) |
|
|
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode) |
|
|
|
|
|
|
|
|
|
|
|
doc, err := NewHtmlParser(resp.Body) |
|
|
|
doc := NewHtmlParser(t, resp.Body) |
|
|
|
assert.NoError(t, err) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Change master branch to protected
|
|
|
|
// Change master branch to protected
|
|
|
|
req = NewRequestBody(t, "POST", "/user2/repo1/settings/branches?action=protected_branch", |
|
|
|
req = NewRequestWithValues(t, "POST", "/user2/repo1/settings/branches?action=protected_branch", map[string]string{ |
|
|
|
bytes.NewBufferString(url.Values{ |
|
|
|
"_csrf": doc.GetCSRF(), |
|
|
|
"_csrf": []string{doc.GetInputValueByName("_csrf")}, |
|
|
|
"branchName": "master", |
|
|
|
"branchName": []string{"master"}, |
|
|
|
"canPush": "true", |
|
|
|
"canPush": []string{"true"}, |
|
|
|
}) |
|
|
|
}.Encode()), |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
|
|
|
req.Header.Add("Content-Type", "application/x-www-form-urlencoded") |
|
|
|
req.Header.Add("Content-Type", "application/x-www-form-urlencoded") |
|
|
|
resp = session.MakeRequest(t, req) |
|
|
|
resp = session.MakeRequest(t, req) |
|
|
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode) |
|
|
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode) |
|
|
@ -79,21 +70,19 @@ func TestCreateFileOnProtectedBranch(t *testing.T) { |
|
|
|
resp = session.MakeRequest(t, req) |
|
|
|
resp = session.MakeRequest(t, req) |
|
|
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode) |
|
|
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode) |
|
|
|
|
|
|
|
|
|
|
|
doc, err = NewHtmlParser(resp.Body) |
|
|
|
doc = NewHtmlParser(t, resp.Body) |
|
|
|
assert.NoError(t, err) |
|
|
|
|
|
|
|
lastCommit := doc.GetInputValueByName("last_commit") |
|
|
|
lastCommit := doc.GetInputValueByName("last_commit") |
|
|
|
assert.NotEmpty(t, lastCommit) |
|
|
|
assert.NotEmpty(t, lastCommit) |
|
|
|
|
|
|
|
|
|
|
|
// Save new file to master branch
|
|
|
|
// Save new file to master branch
|
|
|
|
req = NewRequestBody(t, "POST", "/user2/repo1/_new/master/", |
|
|
|
req = NewRequestWithValues(t, "POST", "/user2/repo1/_new/master/", map[string]string{ |
|
|
|
bytes.NewBufferString(url.Values{ |
|
|
|
"_csrf": doc.GetCSRF(), |
|
|
|
"_csrf": []string{doc.GetInputValueByName("_csrf")}, |
|
|
|
"last_commit": lastCommit, |
|
|
|
"last_commit": []string{lastCommit}, |
|
|
|
"tree_path": "test.txt", |
|
|
|
"tree_path": []string{"test.txt"}, |
|
|
|
"content": "Content", |
|
|
|
"content": []string{"Content"}, |
|
|
|
"commit_choice": "direct", |
|
|
|
"commit_choice": []string{"direct"}, |
|
|
|
}) |
|
|
|
}.Encode()), |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
req.Header.Add("Content-Type", "application/x-www-form-urlencoded") |
|
|
|
req.Header.Add("Content-Type", "application/x-www-form-urlencoded") |
|
|
|
resp = session.MakeRequest(t, req) |
|
|
|
resp = session.MakeRequest(t, req) |
|
|
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode) |
|
|
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode) |
|
|
@ -110,20 +99,19 @@ func testEditFile(t *testing.T, session *TestSession, user, repo, branch, filePa |
|
|
|
resp := session.MakeRequest(t, req) |
|
|
|
resp := session.MakeRequest(t, req) |
|
|
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode) |
|
|
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode) |
|
|
|
|
|
|
|
|
|
|
|
htmlDoc, err := NewHtmlParser(resp.Body) |
|
|
|
htmlDoc := NewHtmlParser(t, resp.Body) |
|
|
|
assert.NoError(t, err) |
|
|
|
|
|
|
|
lastCommit := htmlDoc.GetInputValueByName("last_commit") |
|
|
|
lastCommit := htmlDoc.GetInputValueByName("last_commit") |
|
|
|
assert.NotEmpty(t, lastCommit) |
|
|
|
assert.NotEmpty(t, lastCommit) |
|
|
|
|
|
|
|
|
|
|
|
// Submit the edits
|
|
|
|
// Submit the edits
|
|
|
|
req = NewRequestBody(t, "POST", path.Join(user, repo, "_edit", branch, filePath), |
|
|
|
req = NewRequestWithValues(t, "POST", path.Join(user, repo, "_edit", branch, filePath), |
|
|
|
bytes.NewBufferString(url.Values{ |
|
|
|
map[string]string{ |
|
|
|
"_csrf": []string{htmlDoc.GetInputValueByName("_csrf")}, |
|
|
|
"_csrf": htmlDoc.GetCSRF(), |
|
|
|
"last_commit": []string{lastCommit}, |
|
|
|
"last_commit": lastCommit, |
|
|
|
"tree_path": []string{filePath}, |
|
|
|
"tree_path": filePath, |
|
|
|
"content": []string{newContent}, |
|
|
|
"content": newContent, |
|
|
|
"commit_choice": []string{"direct"}, |
|
|
|
"commit_choice": "direct", |
|
|
|
}.Encode()), |
|
|
|
}, |
|
|
|
) |
|
|
|
) |
|
|
|
req.Header.Add("Content-Type", "application/x-www-form-urlencoded") |
|
|
|
req.Header.Add("Content-Type", "application/x-www-form-urlencoded") |
|
|
|
resp = session.MakeRequest(t, req) |
|
|
|
resp = session.MakeRequest(t, req) |
|
|
@ -140,6 +128,6 @@ func testEditFile(t *testing.T, session *TestSession, user, repo, branch, filePa |
|
|
|
|
|
|
|
|
|
|
|
func TestEditFile(t *testing.T) { |
|
|
|
func TestEditFile(t *testing.T) { |
|
|
|
prepareTestEnv(t) |
|
|
|
prepareTestEnv(t) |
|
|
|
session := loginUser(t, "user2", "password") |
|
|
|
session := loginUser(t, "user2") |
|
|
|
testEditFile(t, session, "user2", "repo1", "master", "README.md") |
|
|
|
testEditFile(t, session, "user2", "repo1", "master", "README.md") |
|
|
|
} |
|
|
|
} |
|
|
|