(t *testing.T)
| 706 | } |
| 707 | |
| 708 | func 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"}, |
nothing calls this directly
no test coverage detected