TestExtractExpectedAudience tests audience extraction from HTTP requests
(t *testing.T)
| 211 | |
| 212 | // TestExtractExpectedAudience tests audience extraction from HTTP requests |
| 213 | func TestExtractExpectedAudience(t *testing.T) { |
| 214 | t.Parallel() |
| 215 | |
| 216 | testCases := []struct { |
| 217 | name string |
| 218 | scheme string |
| 219 | host string |
| 220 | path string |
| 221 | expected string |
| 222 | }{ |
| 223 | { |
| 224 | name: "SimpleHTTP", |
| 225 | scheme: "http", |
| 226 | host: "example.com", |
| 227 | path: "/api/test", |
| 228 | expected: "http://example.com/", |
| 229 | }, |
| 230 | { |
| 231 | name: "HTTPS", |
| 232 | scheme: "https", |
| 233 | host: "api.example.com", |
| 234 | path: "/v1/users", |
| 235 | expected: "https://api.example.com/", |
| 236 | }, |
| 237 | { |
| 238 | name: "WithPort", |
| 239 | scheme: "http", |
| 240 | host: "localhost:8080", |
| 241 | path: "/api", |
| 242 | expected: "http://localhost:8080/", |
| 243 | }, |
| 244 | } |
| 245 | |
| 246 | for _, tc := range testCases { |
| 247 | t.Run(tc.name, func(t *testing.T) { |
| 248 | t.Parallel() |
| 249 | var req *http.Request |
| 250 | if tc.scheme == "https" { |
| 251 | req = httptest.NewRequest("GET", "https://"+tc.host+tc.path, nil) |
| 252 | } else { |
| 253 | req = httptest.NewRequest("GET", "http://"+tc.host+tc.path, nil) |
| 254 | } |
| 255 | req.Host = tc.host |
| 256 | |
| 257 | result := extractExpectedAudience(nil, req) |
| 258 | assert.Equal(t, tc.expected, result) |
| 259 | }) |
| 260 | } |
| 261 | } |
nothing calls this directly
no test coverage detected