| gio | dcd9fef | 2024-09-26 14:42:59 +0200 | [diff] [blame] | 1 | package main |
| 2 | |
| 3 | import ( |
| gio | e71b12b | 2026-07-29 10:02:37 +0400 | [diff] [blame] | 4 | "net/http" |
| 5 | "net/http/httptest" |
| 6 | "strings" |
| gio | dcd9fef | 2024-09-26 14:42:59 +0200 | [diff] [blame] | 7 | "testing" |
| 8 | ) |
| 9 | |
| gio | e71b12b | 2026-07-29 10:02:37 +0400 | [diff] [blame] | 10 | func TestIdentityCreateSharedValidationResponseRemainsCompatible(t *testing.T) { |
| 11 | server := NewAPIServer(0, "http://kratos.invalid") |
| 12 | request := httptest.NewRequest(http.MethodPost, "/identities", strings.NewReader(`{"username":"x","password":"short"}`)) |
| 13 | recorder := httptest.NewRecorder() |
| 14 | server.identityCreate(recorder, request) |
| gio | dcd9fef | 2024-09-26 14:42:59 +0200 | [diff] [blame] | 15 | |
| gio | e71b12b | 2026-07-29 10:02:37 +0400 | [diff] [blame] | 16 | 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"}]} |
| 17 | ` |
| 18 | if recorder.Code != http.StatusBadRequest { |
| 19 | t.Fatalf("status = %d, want 400", recorder.Code) |
| 20 | } |
| 21 | if got := recorder.Header().Get("Content-Type"); got != "application/json" { |
| 22 | t.Fatalf("content type = %q", got) |
| 23 | } |
| 24 | if got := recorder.Body.String(); got != expected { |
| 25 | t.Fatalf("body = %q, want byte-compatible %q", got, expected) |
| gio | dcd9fef | 2024-09-26 14:42:59 +0200 | [diff] [blame] | 26 | } |
| 27 | } |