@@ -155,7 +155,7 @@ func TestServerCmd_AllArgs_Defaults(t *testing.T) {
155
155
{"chat-base-path default" , FlagChatBasePath , "/chat" , func () any { return viper .GetString (FlagChatBasePath ) }},
156
156
{"term-width default" , FlagTermWidth , uint16 (80 ), func () any { return viper .GetUint16 (FlagTermWidth ) }},
157
157
{"term-height default" , FlagTermHeight , uint16 (1000 ), func () any { return viper .GetUint16 (FlagTermHeight ) }},
158
- {"allowed-hosts default" , FlagAllowedHosts , []string {"localhost" }, func () any { return viper .GetStringSlice (FlagAllowedHosts ) }},
158
+ {"allowed-hosts default" , FlagAllowedHosts , []string {"localhost" , "127.0.0.1" , "[::1]" }, func () any { return viper .GetStringSlice (FlagAllowedHosts ) }},
159
159
{"allowed-origins default" , FlagAllowedOrigins , []string {"http://localhost:3284" , "http://localhost:3000" , "http://localhost:3001" }, func () any { return viper .GetStringSlice (FlagAllowedOrigins ) }},
160
160
}
161
161
@@ -341,37 +341,6 @@ func TestServerCmd_AllowedHosts(t *testing.T) {
341
341
args : []string {},
342
342
expected : []string {"localhost" , "example.com" },
343
343
},
344
- {
345
- name : "env: host with comma (invalid)" ,
346
- env : map [string ]string {"AGENTAPI_ALLOWED_HOSTS" : "localhost:3284,example.com" },
347
- args : []string {},
348
- expectedErr : "contains comma characters" ,
349
- },
350
- {
351
- name : "env: host with port (invalid)" ,
352
- env : map [string ]string {"AGENTAPI_ALLOWED_HOSTS" : "localhost:3284" },
353
- args : []string {},
354
- expectedErr : "must not include a port" ,
355
- },
356
- {
357
- name : "env: ipv6 literal" ,
358
- env : map [string ]string {"AGENTAPI_ALLOWED_HOSTS" : "2001:db8::1" },
359
- args : []string {},
360
- expected : []string {"2001:db8::1" },
361
- },
362
- {
363
- name : "env: ipv6 bracketed literal" ,
364
- env : map [string ]string {"AGENTAPI_ALLOWED_HOSTS" : "[2001:db8::1]" },
365
- args : []string {},
366
- expected : []string {"[2001:db8::1]" },
367
- },
368
- {
369
- name : "env: ipv6 with port (invalid)" ,
370
- env : map [string ]string {"AGENTAPI_ALLOWED_HOSTS" : "[2001:db8::1]:443" },
371
- args : []string {},
372
- expectedErr : "must not include a port" ,
373
- },
374
-
375
344
// CLI flag scenarios (comma-separated format)
376
345
{
377
346
name : "flag: single valid host" ,
@@ -394,30 +363,10 @@ func TestServerCmd_AllowedHosts(t *testing.T) {
394
363
expected : []string {"localhost" },
395
364
},
396
365
{
397
- name : "flag: host with space in comma-separated list (invalid)" ,
398
- args : []string {"--allowed-hosts" , "localhost:3284,example .com" },
399
- expectedErr : "contains whitespace characters" ,
400
- },
401
- {
402
- name : "flag: host with port (invalid)" ,
403
- args : []string {"--allowed-hosts" , "localhost:3284" },
404
- expectedErr : "must not include a port" ,
366
+ name : "flag: ipv6 bracketed literal" ,
367
+ args : []string {"--allowed-hosts" , "[2001:db8::1]" },
368
+ expected : []string {"[2001:db8::1]" },
405
369
},
406
- {
407
- name : "flag: ipv6 literal" ,
408
- args : []string {"--allowed-hosts" , "2001:db8::1" },
409
- expected : []string {"2001:db8::1" },
410
- },
411
- {
412
- name : "flag: ipv6 bracketed literal" ,
413
- args : []string {"--allowed-hosts" , "[2001:db8::1]" },
414
- expected : []string {"[2001:db8::1]" },
415
- },
416
- {
417
- name : "flag: ipv6 with port (invalid)" ,
418
- args : []string {"--allowed-hosts" , "[2001:db8::1]:443" },
419
- expectedErr : "must not include a port" ,
420
- },
421
370
422
371
// Mixed scenarios (env + flag precedence)
423
372
{
@@ -426,26 +375,6 @@ func TestServerCmd_AllowedHosts(t *testing.T) {
426
375
args : []string {"--allowed-hosts" , "override.com" },
427
376
expected : []string {"override.com" },
428
377
},
429
- {
430
- name : "mixed: flag overrides env but flag is invalid" ,
431
- env : map [string ]string {"AGENTAPI_ALLOWED_HOSTS" : "localhost" },
432
- args : []string {"--allowed-hosts" , "invalid .com" },
433
- expectedErr : "contains whitespace characters" ,
434
- },
435
-
436
- // Empty hosts are not allowed
437
- {
438
- name : "empty host" ,
439
- args : []string {"--allowed-hosts" , "" },
440
- expectedErr : "the list must not be empty" ,
441
- },
442
-
443
- // Default behavior
444
- {
445
- name : "default hosts when neither env nor flag provided" ,
446
- args : []string {},
447
- expected : []string {"localhost" },
448
- },
449
378
}
450
379
451
380
for _ , tt := range tests {
@@ -506,12 +435,6 @@ func TestServerCmd_AllowedOrigins(t *testing.T) {
506
435
args : []string {},
507
436
expected : []string {"https://example.com" , "http://localhost:3000" },
508
437
},
509
- {
510
- name : "env: origin with comma (invalid)" ,
511
- env : map [string ]string {"AGENTAPI_ALLOWED_ORIGINS" : "https://example.com,http://localhost:3000" },
512
- args : []string {},
513
- expectedErr : "contains comma characters" ,
514
- },
515
438
516
439
// CLI flag scenarios (comma-separated format)
517
440
{
@@ -539,11 +462,6 @@ func TestServerCmd_AllowedOrigins(t *testing.T) {
539
462
args : []string {"--allowed-origins" , "https://example.com\n " },
540
463
expected : []string {"https://example.com" },
541
464
},
542
- {
543
- name : "flag: origin with space in comma-separated list (invalid)" ,
544
- args : []string {"--allowed-origins" , "https://example.com,http://localhost :3000" },
545
- expectedErr : "contains whitespace characters" ,
546
- },
547
465
548
466
// Mixed scenarios (env + flag precedence)
549
467
{
@@ -552,26 +470,6 @@ func TestServerCmd_AllowedOrigins(t *testing.T) {
552
470
args : []string {"--allowed-origins" , "https://override.com" },
553
471
expected : []string {"https://override.com" },
554
472
},
555
- {
556
- name : "mixed: flag overrides env but flag is invalid" ,
557
- env : map [string ]string {"AGENTAPI_ALLOWED_ORIGINS" : "https://env-example.com" },
558
- args : []string {"--allowed-origins" , "invalid origin" },
559
- expectedErr : "contains whitespace characters" ,
560
- },
561
-
562
- // Empty origins are not allowed
563
- {
564
- name : "empty origin" ,
565
- args : []string {"--allowed-origins" , "" },
566
- expectedErr : "the list must not be empty" ,
567
- },
568
-
569
- // Default behavior
570
- {
571
- name : "default origins when neither env nor flag provided" ,
572
- args : []string {},
573
- expected : []string {"http://localhost:3284" , "http://localhost:3000" , "http://localhost:3001" },
574
- },
575
473
}
576
474
577
475
for _ , tt := range tests {
0 commit comments