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

Function TestServerCmd_AllowedOrigins

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

Source from the content-addressed store, hash-verified

706}
707
708func TestServerCmd_AllowedOrigins(t *testing.T) {
709 tests := []struct {
710 name string
711 env map[string]string
712 args []string
713 expectedErr string
714 expected []string // only checked if expectedErr is empty
715 }{
716 // Environment variable scenarios (space-separated format)
717 {
718 name: "env: single valid origin",
719 env: map[string]string{"AGENTAPI_ALLOWED_ORIGINS": "https://example.com"},
720 args: []string{},
721 expected: []string{"https://example.com"},
722 },
723 {
724 name: "env: multiple valid origins space-separated",
725 env: map[string]string{"AGENTAPI_ALLOWED_ORIGINS": "https://example.com http://localhost:3000 https://app.example.com"},
726 args: []string{},
727 expected: []string{"https://example.com", "http://localhost:3000", "https://app.example.com"},
728 },
729 {
730 name: "env: wildcard origin",
731 env: map[string]string{"AGENTAPI_ALLOWED_ORIGINS": "*"},
732 args: []string{},
733 expected: []string{"*"},
734 },
735 {
736 name: "env: origin with tab",
737 env: map[string]string{"AGENTAPI_ALLOWED_ORIGINS": "https://example.com\thttp://localhost:3000"},
738 args: []string{},
739 expected: []string{"https://example.com", "http://localhost:3000"},
740 },
741
742 // CLI flag scenarios (comma-separated format)
743 {
744 name: "flag: single valid origin",
745 args: []string{"--allowed-origins", "https://example.com"},
746 expected: []string{"https://example.com"},
747 },
748 {
749 name: "flag: multiple valid origins comma-separated",
750 args: []string{"--allowed-origins", "https://example.com,http://localhost:3000,https://app.example.com"},
751 expected: []string{"https://example.com", "http://localhost:3000", "https://app.example.com"},
752 },
753 {
754 name: "flag: multiple valid origins with multiple flags",
755 args: []string{"--allowed-origins", "https://example.com", "--allowed-origins", "http://localhost:3000"},
756 expected: []string{"https://example.com", "http://localhost:3000"},
757 },
758 {
759 name: "flag: wildcard origin",
760 args: []string{"--allowed-origins", "*"},
761 expected: []string{"*"},
762 },
763 {
764 name: "flag: origin with newline",
765 args: []string{"--allowed-origins", "https://example.com\n"},

Callers

nothing calls this directly

Calls 3

isolateViperFunction · 0.85
CreateServerCmdFunction · 0.85
setupCommandOutputFunction · 0.85

Tested by

no test coverage detected