@@ -89,9 +89,15 @@ func TestHandler(t *testing.T) {
8989 send := func (t * testing.T , base * httptest.Server , method , href string , expectCode int , send interface {}) gjson.Result {
9090 t .Helper ()
9191 var b bytes.Buffer
92- if send != nil {
93- require .NoError (t , json .NewEncoder (& b ).Encode (send ))
92+ switch raw := send .(type ) {
93+ case json.RawMessage :
94+ b = * bytes .NewBuffer (raw )
95+ default :
96+ if send != nil {
97+ require .NoError (t , json .NewEncoder (& b ).Encode (send ))
98+ }
9499 }
100+
95101 req , err := http .NewRequest (method , base .URL + href , & b )
96102 require .NoError (t , err )
97103 req .Header .Set ("Content-Type" , "application/json" )
@@ -190,7 +196,19 @@ func TestHandler(t *testing.T) {
190196 actual , err := reg .PrivilegedIdentityPool ().GetIdentityConfidential (ctx , uuid .FromStringOrNil (res .Get ("id" ).String ()))
191197 require .NoError (t , err )
192198
193- snapshotx .SnapshotTExceptMatchingKeys (t , identity .WithCredentialsAndAdminMetadataInJSON (* actual ), ignoreDefault )
199+ snapshotx .SnapshotT (t , identity .WithCredentialsAndAdminMetadataInJSON (* actual ), snapshotx .ExceptNestedKeys (ignoreDefault ... ))
200+ })
201+
202+ t .Run ("without traits" , func (t * testing.T ) {
203+ res := send (t , adminTS , "POST" , "/identities" , http .StatusCreated , json .RawMessage ("{}" ))
204+ actual , err := reg .PrivilegedIdentityPool ().GetIdentityConfidential (ctx , uuid .FromStringOrNil (res .Get ("id" ).String ()))
205+ require .NoError (t , err )
206+
207+ snapshotx .SnapshotT (t , identity .WithCredentialsAndAdminMetadataInJSON (* actual ), snapshotx .ExceptNestedKeys (ignoreDefault ... ))
208+ })
209+
210+ t .Run ("with malformed traits" , func (t * testing.T ) {
211+ send (t , adminTS , "POST" , "/identities" , http .StatusBadRequest , json .RawMessage (`{"traits": not valid JSON}` ))
194212 })
195213
196214 t .Run ("with cleartext password and oidc credentials" , func (t * testing.T ) {
@@ -276,7 +294,7 @@ func TestHandler(t *testing.T) {
276294 actual , err := reg .PrivilegedIdentityPool ().GetIdentityConfidential (ctx , uuid .FromStringOrNil (res .Get ("id" ).String ()))
277295 require .NoError (t , err )
278296
279- snapshotx .SnapshotTExceptMatchingKeys (t , identity .WithCredentialsAndAdminMetadataInJSON (* actual ), append (ignoreDefault , "hashed_password" ))
297+ snapshotx .SnapshotT (t , identity .WithCredentialsAndAdminMetadataInJSON (* actual ), snapshotx . ExceptNestedKeys (ignoreDefault ... ), snapshotx . ExceptNestedKeys ( "hashed_password" ))
280298
281299 require .NoError (t , hash .Compare (ctx , []byte (tt .pass ), []byte (gjson .GetBytes (actual .Credentials [identity .CredentialsTypePassword ].Config , "hashed_password" ).String ())))
282300 })
0 commit comments