diff --git a/app/controller/controller_test.go b/app/controller/controller_test.go index e8d804e..20a4075 100644 --- a/app/controller/controller_test.go +++ b/app/controller/controller_test.go @@ -144,6 +144,8 @@ func runFailTests(t *testing.T, tests []failTest, groupName string) { httpResp := makeResp(req) resp := response.Response{} mustJsonDecode(httpResp, &resp) + t.Logf("Expected Status Code: %d", test.statusCode) + t.Logf("Actual Status Code: %d", httpResp.StatusCode) assert.Equal(t, test.statusCode, httpResp.StatusCode) assert.Equal(t, test.resp, resp) }) diff --git a/app/controller/problem_test.go b/app/controller/problem_test.go index c11a29e..7601353 100644 --- a/app/controller/problem_test.go +++ b/app/controller/problem_test.go @@ -878,7 +878,6 @@ func TestCreateProblem(t *testing.T) { LanguageAllowed: "", BuildArg: "", CompareScriptName: "", - Sanitize: nil, }, reqOptions: []reqOption{ applyAdminUser, @@ -925,11 +924,6 @@ func TestCreateProblem(t *testing.T) { "reason": "required", "translation": "评测脚本为必填字段", }, - map[string]interface{}{ - "field": "Sanitize", - "reason": "required", - "translation": "是否清洗数据为必填字段", - }, }), }, { @@ -967,7 +961,6 @@ func TestCreateProblem(t *testing.T) { TimeLimit: 1000, LanguageAllowed: "test_create_problem_1_language_allowed", CompareScriptName: "cmp1", - Sanitize: &boolFalse, Public: &boolFalse, Privacy: &boolTrue, }, @@ -982,7 +975,6 @@ func TestCreateProblem(t *testing.T) { TimeLimit: 1000, LanguageAllowed: "test_create_problem_3_language_allowed", CompareScriptName: "cmp1", - Sanitize: &boolFalse, Public: &boolFalse, Privacy: &boolTrue, Tags: "tag_1,tag_2", @@ -998,7 +990,6 @@ func TestCreateProblem(t *testing.T) { TimeLimit: 1000, LanguageAllowed: "test_create_problem_2_language_allowed", CompareScriptName: "cmp2", - Sanitize: &boolFalse, Public: &boolTrue, Privacy: &boolFalse, }, @@ -1025,7 +1016,6 @@ func TestCreateProblem(t *testing.T) { "time_limit": fmt.Sprint(test.req.TimeLimit), "language_allowed": test.req.LanguageAllowed, "compare_script_name": fmt.Sprint(test.req.CompareScriptName), - "sanitize": fmt.Sprint(test.req.Sanitize), "public": fmt.Sprint(*test.req.Public), "privacy": fmt.Sprint(*test.req.Privacy), }) @@ -1066,6 +1056,8 @@ func TestCreateProblem(t *testing.T) { storageContent := getObjectContent(t, "problems", fmt.Sprintf("%d/attachment", databaseProblem.ID)) expectedContent, err := ioutil.ReadAll(test.attachment.reader) assert.NoError(t, err) + t.Logf("Expected Content: %+v", expectedContent) + t.Logf("Storage Content: %+v", storageContent) assert.Equal(t, expectedContent, storageContent) assert.Equal(t, test.attachment.fileName, databaseProblem.AttachmentFileName) } else { @@ -1745,8 +1737,9 @@ func TestCreateTestCase(t *testing.T) { newFileContent("input_file", "test_create_test_case_non_existing_problem.in", inputTextBase64), newFileContent("output_file", "test_create_test_case_non_existing_problem.out", outputTextBase64), }, map[string]string{ - "score": "100", - "sample": "true", + "score": "100", + "sample": "true", + "sanitize": "false", }), reqOptions: []reqOption{ applyAdminUser, @@ -1761,8 +1754,9 @@ func TestCreateTestCase(t *testing.T) { req: addFieldContentSlice([]reqContent{ newFileContent("output_file", "test_create_test_case_lack_input_file.out", outputTextBase64), }, map[string]string{ - "score": "100", - "sample": "true", + "score": "100", + "sample": "true", + "sanitize": "false", }), reqOptions: []reqOption{ headerOption{ @@ -1779,8 +1773,9 @@ func TestCreateTestCase(t *testing.T) { req: addFieldContentSlice([]reqContent{ newFileContent("input_file", "test_create_test_case_lack_output_file.in", inputTextBase64), }, map[string]string{ - "score": "100", - "sample": "true", + "score": "100", + "sample": "true", + "sanitize": "false", }), reqOptions: []reqOption{ headerOption{ @@ -1795,8 +1790,9 @@ func TestCreateTestCase(t *testing.T) { method: "POST", path: base.Echo.Reverse("problem.createTestCase", problem.ID), req: addFieldContentSlice([]reqContent{}, map[string]string{ - "score": "100", - "sample": "true", + "score": "100", + "sample": "true", + "sanitize": "false", }), reqOptions: []reqOption{ headerOption{ @@ -1814,8 +1810,9 @@ func TestCreateTestCase(t *testing.T) { newFileContent("input_file", "test_create_test_case_permission_denied.in", inputTextBase64), newFileContent("output_file", "test_create_test_case_permission_denied.out", outputTextBase64), }, map[string]string{ - "score": "100", - "sample": "true", + "score": "100", + "sample": "true", + "sanitize": "false", }), reqOptions: []reqOption{ applyNormalUser, @@ -1833,8 +1830,9 @@ func TestCreateTestCase(t *testing.T) { newFileContent("input_file", "test_create_test_case_success.in", inputTextBase64), newFileContent("output_file", "test_create_test_case_success.out", outputTextBase64), }, map[string]string{ - "score": "100", - "sample": "true", + "score": "100", + "sample": "true", + "sanitize": "false", }), headerOption{ "Set-User-For-Test": {fmt.Sprintf("%d", user.ID)}, }) @@ -2077,14 +2075,16 @@ func TestUpdateTestCase(t *testing.T) { problem := createProblemForTest(t, "update_test_case", 0, nil, user) boolTrue := true + boolFalse := false failTests := []failTest{ { name: "NonExistingProblem", method: "PUT", path: base.Echo.Reverse("problem.updateTestCase", -1, 1), req: request.UpdateTestCaseRequest{ - Score: 100, - Sample: &boolTrue, + Score: 100, + Sample: &boolTrue, + Sanitize: &boolFalse, }, reqOptions: []reqOption{ applyAdminUser, @@ -2097,8 +2097,9 @@ func TestUpdateTestCase(t *testing.T) { method: "PUT", path: base.Echo.Reverse("problem.updateTestCase", problem.ID, -1), req: request.UpdateTestCaseRequest{ - Score: 100, - Sample: &boolTrue, + Score: 100, + Sample: &boolTrue, + Sanitize: &boolFalse, }, reqOptions: []reqOption{ headerOption{ @@ -2117,8 +2118,9 @@ func TestUpdateTestCase(t *testing.T) { method: "PUT", path: base.Echo.Reverse("problem.updateTestCase", problem.ID, 1), req: request.UpdateTestCaseRequest{ - Score: 100, - Sample: &boolTrue, + Score: 100, + Sample: &boolTrue, + Sanitize: &boolFalse, }, reqOptions: []reqOption{ applyNormalUser, @@ -2139,7 +2141,7 @@ func TestUpdateTestCase(t *testing.T) { { name: "SuccessWithoutUpdatingFile", originalData: testCaseData{ - Score: 0, + Score: 100, Sample: false, InputFile: newFileContent("input_file", "test_update_test_case_1.in", inputTextBase64), OutputFile: newFileContent("output_file", "test_update_test_case_1.out", outputTextBase64), @@ -2240,10 +2242,12 @@ func TestUpdateTestCase(t *testing.T) { if test.updatedData.OutputFile != nil { reqContentSlice = append(reqContentSlice, test.updatedData.OutputFile) } + sanitizeValue := false req := makeReq(t, "PUT", base.Echo.Reverse("problem.updateTestCase", problem.ID, testCase.ID), addFieldContentSlice( reqContentSlice, map[string]string{ - "score": fmt.Sprintf("%d", test.updatedData.Score), - "sample": fmt.Sprintf("%t", test.updatedData.Sample), + "score": fmt.Sprintf("%d", test.updatedData.Score), + "sample": fmt.Sprintf("%t", test.updatedData.Sample), + "sanitize": fmt.Sprintf("%t", sanitizeValue), }), headerOption{ "Set-User-For-Test": {fmt.Sprintf("%d", user.ID)}, }) diff --git a/app/request/problem.go b/app/request/problem.go index eb03e71..9f6a40a 100644 --- a/app/request/problem.go +++ b/app/request/problem.go @@ -7,7 +7,7 @@ type CreateProblemRequest struct { Public *bool `json:"public" form:"public" query:"public" validate:"required"` Privacy *bool `json:"privacy" form:"privacy" query:"privacy" validate:"required"` - Sanitize *bool `json:"sanitize" form:"sanitize" query:"sanitize" validate:"required"` + //Sanitize *bool `json:"sanitize" form:"sanitize" query:"sanitize" validate:"required"` MemoryLimit uint64 `json:"memory_limit" form:"memory_limit" query:"memory_limit" validate:"required"` // Byte TimeLimit uint `json:"time_limit" form:"time_limit" query:"time_limit" validate:"required"` // ms