MCPcopy
hub / github.com/oauth2-proxy/oauth2-proxy / TestAuthSkippedForPreflightRequests

Function TestAuthSkippedForPreflightRequests

oauthproxy_test.go:1466–1503  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1464}
1465
1466func 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
1505type SignatureAuthenticator struct {
1506 auth hmacauth.HmacAuth

Callers

nothing calls this directly

Calls 8

ServeHTTPMethod · 0.95
ValidateFunction · 0.92
baseTestOptionsFunction · 0.85
NewOAuthProxyFunction · 0.85
NewTestProviderFunction · 0.85
WriteHeaderMethod · 0.80
WriteMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected