(t *testing.T)
| 1464 | } |
| 1465 | |
| 1466 | func TestAuthSkippedForPreflightRequests(t *testing.T) { |
| 1467 | upstreamServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 1468 | w.WriteHeader(200) |
| 1469 | _, err := w.Write([]byte("response")) |
| 1470 | if err != nil { |
| 1471 | t.Fatal(err) |
| 1472 | } |
| 1473 | })) |
| 1474 | t.Cleanup(upstreamServer.Close) |
| 1475 | |
| 1476 | opts := baseTestOptions() |
| 1477 | opts.UpstreamServers = options.UpstreamConfig{ |
| 1478 | Upstreams: []options.Upstream{ |
| 1479 | { |
| 1480 | ID: upstreamServer.URL, |
| 1481 | Path: "/", |
| 1482 | URI: upstreamServer.URL, |
| 1483 | }, |
| 1484 | }, |
| 1485 | } |
| 1486 | opts.SkipAuthPreflight = true |
| 1487 | err := validation.Validate(opts) |
| 1488 | assert.NoError(t, err) |
| 1489 | |
| 1490 | upstreamURL, _ := url.Parse(upstreamServer.URL) |
| 1491 | |
| 1492 | proxy, err := NewOAuthProxy(opts, func(string) bool { return false }) |
| 1493 | if err != nil { |
| 1494 | t.Fatal(err) |
| 1495 | } |
| 1496 | proxy.provider = NewTestProvider(upstreamURL, "") |
| 1497 | rw := httptest.NewRecorder() |
| 1498 | req, _ := http.NewRequest(http.MethodOptions, "/preflight-request", nil) |
| 1499 | proxy.ServeHTTP(rw, req) |
| 1500 | |
| 1501 | assert.Equal(t, 200, rw.Code) |
| 1502 | assert.Equal(t, "response", rw.Body.String()) |
| 1503 | } |
| 1504 | |
| 1505 | type SignatureAuthenticator struct { |
| 1506 | auth hmacauth.HmacAuth |
nothing calls this directly
no test coverage detected