|
7 | 7 | "net/http/httptest" |
8 | 8 | "net/url" |
9 | 9 | "os" |
| 10 | + "strings" |
10 | 11 | "testing" |
11 | 12 |
|
12 | 13 | "github.com/spf13/viper" |
@@ -85,8 +86,55 @@ func TestGetBackplaneConnection(t *testing.T) { |
85 | 86 | t.Failed() |
86 | 87 | } |
87 | 88 | }) |
| 89 | + |
| 90 | + t.Run("should pass for valid http proxy URL", func(t *testing.T) { |
| 91 | + proxyURL := "http://www.example.com" |
| 92 | + config := BackplaneConfiguration{URL: "https://api.example.com", ProxyURL: &proxyURL} |
| 93 | + _, err := config.testHTTPRequestToBackplaneAPI() |
| 94 | + |
| 95 | + // Should not get scheme validation error (DNS lookup error is expected) |
| 96 | + if err != nil && strings.Contains(err.Error(), "proxy URL scheme must be http or https") { |
| 97 | + t.Errorf("unexpected scheme validation error: %v", err) |
| 98 | + } |
| 99 | + }) |
| 100 | + |
| 101 | + t.Run("should pass for valid https proxy URL", func(t *testing.T) { |
| 102 | + proxyURL := "https://www.example.com" |
| 103 | + config := BackplaneConfiguration{URL: "https://api.example.com", ProxyURL: &proxyURL} |
| 104 | + _, err := config.testHTTPRequestToBackplaneAPI() |
| 105 | + |
| 106 | + // Should not get scheme validation error (DNS lookup error is expected) |
| 107 | + if err != nil && strings.Contains(err.Error(), "proxy URL scheme must be http or https") { |
| 108 | + t.Errorf("unexpected scheme validation error: %v", err) |
| 109 | + } |
| 110 | + }) |
| 111 | + |
| 112 | + t.Run("should fail for proxy URL without scheme", func(t *testing.T) { |
| 113 | + proxyURL := "www.example.com" |
| 114 | + config := BackplaneConfiguration{URL: "https://api.example.com", ProxyURL: &proxyURL} |
| 115 | + _, err := config.testHTTPRequestToBackplaneAPI() |
| 116 | + |
| 117 | + if err == nil { |
| 118 | + t.Errorf("expected error but got none") |
| 119 | + } else if !strings.Contains(err.Error(), "proxy URL scheme must be http or https, got:") { |
| 120 | + t.Errorf("expected scheme validation error, got: %s", err.Error()) |
| 121 | + } |
| 122 | + }) |
| 123 | + |
| 124 | + t.Run("should fail for ftp proxy URL", func(t *testing.T) { |
| 125 | + proxyURL := "ftp://www.example.com" |
| 126 | + config := BackplaneConfiguration{URL: "https://api.example.com", ProxyURL: &proxyURL} |
| 127 | + _, err := config.testHTTPRequestToBackplaneAPI() |
| 128 | + |
| 129 | + if err == nil { |
| 130 | + t.Errorf("expected error but got none") |
| 131 | + } else if !strings.Contains(err.Error(), "proxy URL scheme must be http or https, got: ftp") { |
| 132 | + t.Errorf("expected scheme validation error for ftp, got: %s", err.Error()) |
| 133 | + } |
| 134 | + }) |
88 | 135 | } |
89 | 136 |
|
| 137 | + |
90 | 138 | func TestBackplaneConfiguration_getFirstWorkingProxyURL(t *testing.T) { |
91 | 139 | tests := []struct { |
92 | 140 | name string |
|
0 commit comments