(t *testing.T)
| 2658 | } |
| 2659 | |
| 2660 | func TestAllowedRequest(t *testing.T) { |
| 2661 | upstreamServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 2662 | w.WriteHeader(200) |
| 2663 | _, err := w.Write([]byte("Allowed Request")) |
| 2664 | if err != nil { |
| 2665 | t.Fatal(err) |
| 2666 | } |
| 2667 | })) |
| 2668 | t.Cleanup(upstreamServer.Close) |
| 2669 | |
| 2670 | opts := baseTestOptions() |
| 2671 | opts.UpstreamServers = options.UpstreamConfig{ |
| 2672 | Upstreams: []options.Upstream{ |
| 2673 | { |
| 2674 | ID: upstreamServer.URL, |
| 2675 | Path: "/", |
| 2676 | URI: upstreamServer.URL, |
| 2677 | }, |
| 2678 | }, |
| 2679 | } |
| 2680 | opts.SkipAuthRegex = []string{ |
| 2681 | "^/skip/auth/regex$", |
| 2682 | "^/public/.*/endpoint$", |
| 2683 | } |
| 2684 | opts.SkipAuthRoutes = []string{ |
| 2685 | "GET=^/skip/auth/routes/get", |
| 2686 | "^/foo/.*/bar$", |
| 2687 | } |
| 2688 | err := validation.Validate(opts) |
| 2689 | assert.NoError(t, err) |
| 2690 | proxy, err := NewOAuthProxy(opts, func(_ string) bool { return true }) |
| 2691 | if err != nil { |
| 2692 | t.Fatal(err) |
| 2693 | } |
| 2694 | |
| 2695 | testCases := []struct { |
| 2696 | name string |
| 2697 | method string |
| 2698 | url string |
| 2699 | allowed bool |
| 2700 | }{ |
| 2701 | { |
| 2702 | name: "Regex GET allowed", |
| 2703 | method: http.MethodGet, |
| 2704 | url: "/skip/auth/regex", |
| 2705 | allowed: true, |
| 2706 | }, |
| 2707 | { |
| 2708 | name: "Regex POST allowed ", |
| 2709 | method: http.MethodPost, |
| 2710 | url: "/skip/auth/regex", |
| 2711 | allowed: true, |
| 2712 | }, |
| 2713 | { |
| 2714 | name: "Regex denied", |
| 2715 | method: http.MethodGet, |
| 2716 | url: "/wrong/denied", |
| 2717 | allowed: false, |
nothing calls this directly
no test coverage detected