Skip to content

Commit 3ee0672

Browse files
domdomeggclaude
andcommitted
Fix test expectations for server name validation
Updated test expectations to align with actual Huma framework behavior where schema validation occurs before handler execution: - Changed expected status from 400 to 422 (Unprocessable Entity) - Updated error message checks to match Huma's pattern validation error - Fixed "invalid token" test to use valid server name format Schema validation in Huma happens at the framework level before the handler function runs, so invalid server names (with multiple slashes, no slashes, etc.) return 422 with pattern matching errors rather than custom 400 errors. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent e23d4e2 commit 3ee0672

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

internal/api/handlers/v0/publish_test.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func TestPublishEndpoint(t *testing.T) {
131131
name: "invalid token",
132132
requestBody: apiv0.ServerJSON{
133133
Schema: model.CurrentSchemaURL,
134-
Name: "test-server",
134+
Name: "example/test-server",
135135
Description: "A test server",
136136
Version: "1.0.0",
137137
},
@@ -252,8 +252,8 @@ func TestPublishEndpoint(t *testing.T) {
252252
},
253253
},
254254
setupRegistryService: func(_ service.RegistryService) {},
255-
expectedStatus: http.StatusBadRequest,
256-
expectedError: "server name cannot contain multiple slashes",
255+
expectedStatus: http.StatusUnprocessableEntity,
256+
expectedError: "expected string to match pattern",
257257
},
258258
{
259259
name: "invalid server name - multiple slashes (three slashes)",
@@ -270,8 +270,8 @@ func TestPublishEndpoint(t *testing.T) {
270270
},
271271
},
272272
setupRegistryService: func(_ service.RegistryService) {},
273-
expectedStatus: http.StatusBadRequest,
274-
expectedError: "server name cannot contain multiple slashes",
273+
expectedStatus: http.StatusUnprocessableEntity,
274+
expectedError: "expected string to match pattern",
275275
},
276276
{
277277
name: "invalid server name - consecutive slashes",
@@ -288,8 +288,8 @@ func TestPublishEndpoint(t *testing.T) {
288288
},
289289
},
290290
setupRegistryService: func(_ service.RegistryService) {},
291-
expectedStatus: http.StatusBadRequest,
292-
expectedError: "server name cannot contain multiple slashes",
291+
expectedStatus: http.StatusUnprocessableEntity,
292+
expectedError: "expected string to match pattern",
293293
},
294294
{
295295
name: "invalid server name - URL-like path",
@@ -306,8 +306,8 @@ func TestPublishEndpoint(t *testing.T) {
306306
},
307307
},
308308
setupRegistryService: func(_ service.RegistryService) {},
309-
expectedStatus: http.StatusBadRequest,
310-
expectedError: "server name cannot contain multiple slashes",
309+
expectedStatus: http.StatusUnprocessableEntity,
310+
expectedError: "expected string to match pattern",
311311
},
312312
{
313313
name: "invalid server name - many slashes",
@@ -324,8 +324,8 @@ func TestPublishEndpoint(t *testing.T) {
324324
},
325325
},
326326
setupRegistryService: func(_ service.RegistryService) {},
327-
expectedStatus: http.StatusBadRequest,
328-
expectedError: "server name cannot contain multiple slashes",
327+
expectedStatus: http.StatusUnprocessableEntity,
328+
expectedError: "expected string to match pattern",
329329
},
330330
{
331331
name: "invalid server name - with packages and remotes",
@@ -363,8 +363,8 @@ func TestPublishEndpoint(t *testing.T) {
363363
},
364364
},
365365
setupRegistryService: func(_ service.RegistryService) {},
366-
expectedStatus: http.StatusBadRequest,
367-
expectedError: "server name cannot contain multiple slashes",
366+
expectedStatus: http.StatusUnprocessableEntity,
367+
expectedError: "expected string to match pattern",
368368
},
369369
}
370370

@@ -447,25 +447,25 @@ func TestPublishEndpoint_MultipleSlashesEdgeCases(t *testing.T) {
447447
{
448448
name: "invalid - trailing slash after valid name",
449449
serverName: "com.example/server/",
450-
expectedStatus: http.StatusBadRequest,
450+
expectedStatus: http.StatusUnprocessableEntity,
451451
description: "Trailing slash creates multiple slashes",
452452
},
453453
{
454454
name: "invalid - leading and middle slash",
455455
serverName: "/com.example/server",
456-
expectedStatus: http.StatusBadRequest,
456+
expectedStatus: http.StatusUnprocessableEntity,
457457
description: "Leading slash with middle slash",
458458
},
459459
{
460460
name: "invalid - file system style path",
461461
serverName: "usr/local/bin/server",
462-
expectedStatus: http.StatusBadRequest,
462+
expectedStatus: http.StatusUnprocessableEntity,
463463
description: "File system style paths should be rejected",
464464
},
465465
{
466466
name: "invalid - version-like suffix",
467467
serverName: "com.example/server/v1.0.0",
468-
expectedStatus: http.StatusBadRequest,
468+
expectedStatus: http.StatusUnprocessableEntity,
469469
description: "Version suffixes with slash should be rejected",
470470
},
471471
}
@@ -517,9 +517,9 @@ func TestPublishEndpoint_MultipleSlashesEdgeCases(t *testing.T) {
517517
assert.Equal(t, tc.expectedStatus, rr.Code,
518518
"%s: expected status %d, got %d", tc.description, tc.expectedStatus, rr.Code)
519519

520-
if tc.expectedStatus == http.StatusBadRequest {
521-
assert.Contains(t, rr.Body.String(), "server name cannot contain multiple slashes",
522-
"%s: should contain specific error message", tc.description)
520+
if tc.expectedStatus == http.StatusUnprocessableEntity {
521+
assert.Contains(t, rr.Body.String(), "expected string to match pattern",
522+
"%s: should contain pattern validation error", tc.description)
523523
}
524524
})
525525
}

0 commit comments

Comments
 (0)