MCPcopy Create free account
hub / github.com/coder/agentapi / TestServerCmd_AllowedHosts

Function TestServerCmd_AllowedHosts

cmd/server/server_test.go:394–480  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

392}
393
394func TestServerCmd_AllowedHosts(t *testing.T) {
395 tests := []struct {
396 name string
397 env map[string]string
398 args []string
399 expectedErr string
400 expected []string // only checked if expectedErr is empty
401 }{
402 // Environment variable scenarios (space-separated format)
403 {
404 name: "env: single valid host",
405 env: map[string]string{"AGENTAPI_ALLOWED_HOSTS": "localhost"},
406 args: []string{},
407 expected: []string{"localhost"},
408 },
409 {
410 name: "env: multiple valid hosts space-separated",
411 env: map[string]string{"AGENTAPI_ALLOWED_HOSTS": "localhost example.com 192.168.1.1"},
412 args: []string{},
413 expected: []string{"localhost", "example.com", "192.168.1.1"},
414 },
415 {
416 name: "env: host with tab",
417 env: map[string]string{"AGENTAPI_ALLOWED_HOSTS": "localhost\texample.com"},
418 args: []string{},
419 expected: []string{"localhost", "example.com"},
420 },
421 // CLI flag scenarios (comma-separated format)
422 {
423 name: "flag: single valid host",
424 args: []string{"--allowed-hosts", "localhost"},
425 expected: []string{"localhost"},
426 },
427 {
428 name: "flag: multiple valid hosts comma-separated",
429 args: []string{"--allowed-hosts", "localhost,example.com,192.168.1.1"},
430 expected: []string{"localhost", "example.com", "192.168.1.1"},
431 },
432 {
433 name: "flag: multiple valid hosts with multiple flags",
434 args: []string{"--allowed-hosts", "localhost", "--allowed-hosts", "example.com"},
435 expected: []string{"localhost", "example.com"},
436 },
437 {
438 name: "flag: host with newline",
439 args: []string{"--allowed-hosts", "localhost\n"},
440 expected: []string{"localhost"},
441 },
442 {
443 name: "flag: ipv6 bracketed literal",
444 args: []string{"--allowed-hosts", "[2001:db8::1]"},
445 expected: []string{"[2001:db8::1]"},
446 },
447
448 // Mixed scenarios (env + flag precedence)
449 {
450 name: "mixed: flag overrides env",
451 env: map[string]string{"AGENTAPI_ALLOWED_HOSTS": "localhost"},

Callers

nothing calls this directly

Calls 3

isolateViperFunction · 0.85
CreateServerCmdFunction · 0.85
setupCommandOutputFunction · 0.85

Tested by

no test coverage detected