@@ -80,7 +80,7 @@ func TestPublishEndpoint(t *testing.T) {
8080{
8181name : "successful publish with no auth (AuthMethodNone)" ,
8282requestBody : apiv0.ServerJSON {
83- Name : "example/test-server" ,
83+ Name : "com. example/test-server" ,
8484Description : "A test server without auth" ,
8585Repository : model.Repository {
8686URL : "https://github.com/example/test-server" ,
@@ -92,7 +92,7 @@ func TestPublishEndpoint(t *testing.T) {
9292tokenClaims : & auth.JWTClaims {
9393AuthMethod : auth .MethodNone ,
9494Permissions : []auth.Permission {
95- {Action : auth .PermissionActionPublish , ResourcePattern : "example/*" },
95+ {Action : auth .PermissionActionPublish , ResourcePattern : "com. example/*" },
9696},
9797},
9898setupRegistryService : func (_ service.RegistryService ) {
@@ -127,7 +127,7 @@ func TestPublishEndpoint(t *testing.T) {
127127{
128128name : "invalid token" ,
129129requestBody : apiv0.ServerJSON {
130- Name : "test-server" ,
130+ Name : "com.example/ test-server" ,
131131Description : "A test server" ,
132132Version : "1.0.0" ,
133133},
@@ -165,7 +165,7 @@ func TestPublishEndpoint(t *testing.T) {
165165{
166166name : "registry service error" ,
167167requestBody : apiv0.ServerJSON {
168- Name : "example/test-server" ,
168+ Name : "com. example/test-server" ,
169169Description : "A test server" ,
170170Version : "1.0.0" ,
171171Repository : model.Repository {
@@ -183,7 +183,7 @@ func TestPublishEndpoint(t *testing.T) {
183183setupRegistryService : func (registry service.RegistryService ) {
184184// Pre-publish the same server to cause duplicate version error
185185existingServer := apiv0.ServerJSON {
186- Name : "example/test-server" ,
186+ Name : "com. example/test-server" ,
187187Description : "Existing test server" ,
188188Version : "1.0.0" ,
189189Repository : model.Repository {
@@ -224,7 +224,6 @@ func TestPublishEndpoint(t *testing.T) {
224224setupRegistryService : func (_ service.RegistryService ) {},
225225expectedStatus : http .StatusOK ,
226226},
227- // IB-2-registry: Integration test for multi-slash server name rejection
228227{
229228name : "invalid server name - multiple slashes (two slashes)" ,
230229requestBody : apiv0.ServerJSON {
@@ -245,7 +244,7 @@ func TestPublishEndpoint(t *testing.T) {
245244},
246245setupRegistryService : func (_ service.RegistryService ) {},
247246expectedStatus : http .StatusBadRequest ,
248- expectedError : "server name format is invalid: must contain exactly one slash " ,
247+ expectedError : "server name cannot contain multiple slashes " ,
249248},
250249{
251250name : "invalid server name - multiple slashes (three slashes)" ,
@@ -262,7 +261,7 @@ func TestPublishEndpoint(t *testing.T) {
262261},
263262setupRegistryService : func (_ service.RegistryService ) {},
264263expectedStatus : http .StatusBadRequest ,
265- expectedError : "server name format is invalid: must contain exactly one slash " ,
264+ expectedError : "server name cannot contain multiple slashes " ,
266265},
267266{
268267name : "invalid server name - consecutive slashes" ,
@@ -279,7 +278,7 @@ func TestPublishEndpoint(t *testing.T) {
279278},
280279setupRegistryService : func (_ service.RegistryService ) {},
281280expectedStatus : http .StatusBadRequest ,
282- expectedError : "server name format is invalid: must contain exactly one slash " ,
281+ expectedError : "server name cannot contain multiple slashes " ,
283282},
284283{
285284name : "invalid server name - URL-like path" ,
@@ -296,7 +295,7 @@ func TestPublishEndpoint(t *testing.T) {
296295},
297296setupRegistryService : func (_ service.RegistryService ) {},
298297expectedStatus : http .StatusBadRequest ,
299- expectedError : "server name format is invalid: must contain exactly one slash " ,
298+ expectedError : "server name cannot contain multiple slashes " ,
300299},
301300{
302301name : "invalid server name - many slashes" ,
@@ -313,7 +312,7 @@ func TestPublishEndpoint(t *testing.T) {
313312},
314313setupRegistryService : func (_ service.RegistryService ) {},
315314expectedStatus : http .StatusBadRequest ,
316- expectedError : "server name format is invalid: must contain exactly one slash " ,
315+ expectedError : "server name cannot contain multiple slashes " ,
317316},
318317{
319318name : "invalid server name - with packages and remotes" ,
@@ -351,7 +350,41 @@ func TestPublishEndpoint(t *testing.T) {
351350},
352351setupRegistryService : func (_ service.RegistryService ) {},
353352expectedStatus : http .StatusBadRequest ,
354- expectedError : "server name format is invalid: must contain exactly one slash" ,
353+ expectedError : "server name cannot contain multiple slashes" ,
354+ },
355+ {
356+ name : "invalid server name - invalid namespace characters" ,
357+ requestBody : apiv0.ServerJSON {
358+ Name : "com.example@/test-server" ,
359+ Description : "Server with invalid namespace characters" ,
360+ Version : "1.0.0" ,
361+ },
362+ tokenClaims : & auth.JWTClaims {
363+ AuthMethod : auth .MethodNone ,
364+ Permissions : []auth.Permission {
365+ {Action : auth .PermissionActionPublish , ResourcePattern : "*" },
366+ },
367+ },
368+ setupRegistryService : func (_ service.RegistryService ) {},
369+ expectedStatus : http .StatusBadRequest ,
370+ expectedError : "namespace contains invalid characters" ,
371+ },
372+ {
373+ name : "invalid server name - invalid name characters" ,
374+ requestBody : apiv0.ServerJSON {
375+ Name : "com.example/test@server" ,
376+ Description : "Server with invalid name characters" ,
377+ Version : "1.0.0" ,
378+ },
379+ tokenClaims : & auth.JWTClaims {
380+ AuthMethod : auth .MethodNone ,
381+ Permissions : []auth.Permission {
382+ {Action : auth .PermissionActionPublish , ResourcePattern : "*" },
383+ },
384+ },
385+ setupRegistryService : func (_ service.RegistryService ) {},
386+ expectedStatus : http .StatusBadRequest ,
387+ expectedError : "name contains invalid characters" ,
355388},
356389}
357390
@@ -504,8 +537,8 @@ func TestPublishEndpoint_MultipleSlashesEdgeCases(t *testing.T) {
504537"%s: expected status %d, got %d" , tc .description , tc .expectedStatus , rr .Code )
505538
506539if tc .expectedStatus == http .StatusBadRequest {
507- assert .Contains (t , rr .Body .String (), "server name format is invalid: must contain exactly one slash " ,
508- "%s: should contain specific error message " , tc .description )
540+ assert .Contains (t , rr .Body .String (), "server name" ,
541+ "%s: should contain server name validation error " , tc .description )
509542}
510543})
511544}
0 commit comments