forked from mtusi2026/mtusi2026lab2
fixed a bug in JSON validation
This commit is contained in:
@@ -21,6 +21,10 @@ func TestValidation_InvalidJSON(t *testing.T) {
|
||||
[]byte(`{"text": 123,}`),
|
||||
[]byte(``),
|
||||
[]byte(`{"text": "ok"}{"text":"bonus"}`),
|
||||
[]byte(`{"text": "ok"}}`),
|
||||
[]byte(`{"text": "ok"}]`),
|
||||
[]byte(`{"text": "ok"} }`),
|
||||
[]byte(`{"text": "ok"} x`),
|
||||
[]byte("{\"text\":\"\xff\xfe bad utf8\"}"),
|
||||
}
|
||||
for _, payload := range bad {
|
||||
@@ -104,6 +108,7 @@ func TestValidation_ErrorMessages(t *testing.T) {
|
||||
{http.MethodPost, "/api/v1/users", "", ``, "body: empty body"},
|
||||
{http.MethodPost, "/api/v1/users", "", `[]`, "body: expected a JSON object"},
|
||||
{http.MethodPost, "/api/v1/users", "", `{"username":"abc","display_name":"x"} {}`, "body: unexpected data after JSON object"},
|
||||
{http.MethodPost, "/api/v1/users", "", `{"username":"abc","display_name":"x"}}`, "body: unexpected data after JSON object"},
|
||||
{http.MethodPost, "/api/v1/users", "", "{\"username\":\"abc\",\"display_name\":\"\xff\"}",
|
||||
"body: invalid UTF-8"},
|
||||
{http.MethodPost, "/api/v1/chats", alice.ID, `{"title":"t","member_ids":["` + bob.ID + `"]}`,
|
||||
|
||||
Reference in New Issue
Block a user