mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-29 10:57:44 +09:00 
			
		
		
		
	Refactor CSRF token (#32216)
This commit is contained in:
		| @@ -29,7 +29,7 @@ import ( | ||||
| func testAPINewFile(t *testing.T, session *TestSession, user, repo, branch, treePath, content string) *httptest.ResponseRecorder { | ||||
| 	url := fmt.Sprintf("/%s/%s/_new/%s", user, repo, branch) | ||||
| 	req := NewRequestWithValues(t, "POST", url, map[string]string{ | ||||
| 		"_csrf":         GetCSRF(t, session, "/user/settings"), | ||||
| 		"_csrf":         GetUserCSRFToken(t, session), | ||||
| 		"commit_choice": "direct", | ||||
| 		"tree_path":     treePath, | ||||
| 		"content":       content, | ||||
| @@ -63,7 +63,7 @@ func TestEmptyRepoAddFile(t *testing.T) { | ||||
| 	doc := NewHTMLParser(t, resp.Body).Find(`input[name="commit_choice"]`) | ||||
| 	assert.Empty(t, doc.AttrOr("checked", "_no_")) | ||||
| 	req = NewRequestWithValues(t, "POST", "/user30/empty/_new/"+setting.Repository.DefaultBranch, map[string]string{ | ||||
| 		"_csrf":         GetCSRF(t, session, "/user/settings"), | ||||
| 		"_csrf":         GetUserCSRFToken(t, session), | ||||
| 		"commit_choice": "direct", | ||||
| 		"tree_path":     "test-file.md", | ||||
| 		"content":       "newly-added-test-file", | ||||
| @@ -89,7 +89,7 @@ func TestEmptyRepoUploadFile(t *testing.T) { | ||||
|  | ||||
| 	body := &bytes.Buffer{} | ||||
| 	mpForm := multipart.NewWriter(body) | ||||
| 	_ = mpForm.WriteField("_csrf", GetCSRF(t, session, "/user/settings")) | ||||
| 	_ = mpForm.WriteField("_csrf", GetUserCSRFToken(t, session)) | ||||
| 	file, _ := mpForm.CreateFormFile("file", "uploaded-file.txt") | ||||
| 	_, _ = io.Copy(file, bytes.NewBufferString("newly-uploaded-test-file")) | ||||
| 	_ = mpForm.Close() | ||||
| @@ -101,7 +101,7 @@ func TestEmptyRepoUploadFile(t *testing.T) { | ||||
| 	assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), &respMap)) | ||||
|  | ||||
| 	req = NewRequestWithValues(t, "POST", "/user30/empty/_upload/"+setting.Repository.DefaultBranch, map[string]string{ | ||||
| 		"_csrf":         GetCSRF(t, session, "/user/settings"), | ||||
| 		"_csrf":         GetUserCSRFToken(t, session), | ||||
| 		"commit_choice": "direct", | ||||
| 		"files":         respMap["uuid"], | ||||
| 		"tree_path":     "", | ||||
|   | ||||
		Reference in New Issue
	
	Block a user