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

Function TestAllowedRequestNegateWithoutMethod

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

Source from the content-addressed store, hash-verified

2948}
2949
2950func TestAllowedRequestNegateWithoutMethod(t *testing.T) {
2951 upstreamServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
2952 w.WriteHeader(200)
2953 _, err := w.Write([]byte("Allowed Request"))
2954 if err != nil {
2955 t.Fatal(err)
2956 }
2957 }))
2958 t.Cleanup(upstreamServer.Close)
2959
2960 opts := baseTestOptions()
2961 opts.UpstreamServers = options.UpstreamConfig{
2962 Upstreams: []options.Upstream{
2963 {
2964 ID: upstreamServer.URL,
2965 Path: "/",
2966 URI: upstreamServer.URL,
2967 },
2968 },
2969 }
2970 opts.SkipAuthRoutes = []string{
2971 "!=^/api", // any non-api routes
2972 "POST=^/api/public-entity/?$",
2973 }
2974 err := validation.Validate(opts)
2975 assert.NoError(t, err)
2976 proxy, err := NewOAuthProxy(opts, func(_ string) bool { return true })
2977 if err != nil {
2978 t.Fatal(err)
2979 }
2980
2981 testCases := []struct {
2982 name string
2983 method string
2984 url string
2985 allowed bool
2986 }{
2987 {
2988 name: "Some static file allowed",
2989 method: http.MethodGet,
2990 url: "/static/file.txt",
2991 allowed: true,
2992 },
2993 {
2994 name: "POST to contact form allowed",
2995 method: http.MethodPost,
2996 url: "/contact",
2997 allowed: true,
2998 },
2999 {
3000 name: "Regex POST allowed",
3001 method: http.MethodPost,
3002 url: "/api/public-entity",
3003 allowed: true,
3004 },
3005 {
3006 name: "Regex POST with trailing slash allowed",
3007 method: http.MethodPost,

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected