| package main |
| |
| import ( |
| "net/http" |
| "net/http/httptest" |
| "strings" |
| "testing" |
| ) |
| |
| func TestIdentityCreateSharedValidationResponseRemainsCompatible(t *testing.T) { |
| server := NewAPIServer(0, "http://kratos.invalid") |
| request := httptest.NewRequest(http.MethodPost, "/identities", strings.NewReader(`{"username":"x","password":"short"}`)) |
| recorder := httptest.NewRecorder() |
| server.identityCreate(recorder, request) |
| |
| const expected = `{"errors":[{"field":"username","message":"Username must be at least 3 characters long."},{"field":"password","message":"Password must be at least 20 characters long."},{"field":"password","message":"Password must contain at least one digit, lower\u0026upper case and special characters"}]} |
| ` |
| if recorder.Code != http.StatusBadRequest { |
| t.Fatalf("status = %d, want 400", recorder.Code) |
| } |
| if got := recorder.Header().Get("Content-Type"); got != "application/json" { |
| t.Fatalf("content type = %q", got) |
| } |
| if got := recorder.Body.String(); got != expected { |
| t.Fatalf("body = %q, want byte-compatible %q", got, expected) |
| } |
| } |