blob: 1f653ddcdc72bdf69f663e40fa3e102360abd856 [file] [log] [blame]
giodcd9fef2024-09-26 14:42:59 +02001package main
2
3import (
gioe71b12b2026-07-29 10:02:37 +04004 "net/http"
5 "net/http/httptest"
6 "strings"
giodcd9fef2024-09-26 14:42:59 +02007 "testing"
8)
9
gioe71b12b2026-07-29 10:02:37 +040010func 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)
giodcd9fef2024-09-26 14:42:59 +020015
gioe71b12b2026-07-29 10:02:37 +040016 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)
giodcd9fef2024-09-26 14:42:59 +020026 }
27}