(t *testing.T)
| 1997 | } |
| 1998 | |
| 1999 | func Test_noCacheHeaders(t *testing.T) { |
| 2000 | upstreamServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 2001 | _, err := w.Write([]byte("upstream")) |
| 2002 | if err != nil { |
| 2003 | t.Error(err) |
| 2004 | } |
| 2005 | })) |
| 2006 | t.Cleanup(upstreamServer.Close) |
| 2007 | |
| 2008 | opts := baseTestOptions() |
| 2009 | opts.UpstreamServers = options.UpstreamConfig{ |
| 2010 | Upstreams: []options.Upstream{ |
| 2011 | { |
| 2012 | ID: upstreamServer.URL, |
| 2013 | Path: "/", |
| 2014 | URI: upstreamServer.URL, |
| 2015 | }, |
| 2016 | }, |
| 2017 | } |
| 2018 | opts.SkipAuthRegex = []string{".*"} |
| 2019 | err := validation.Validate(opts) |
| 2020 | assert.NoError(t, err) |
| 2021 | proxy, err := NewOAuthProxy(opts, func(_ string) bool { return true }) |
| 2022 | if err != nil { |
| 2023 | t.Fatal(err) |
| 2024 | } |
| 2025 | |
| 2026 | t.Run("not exist in response from upstream", func(t *testing.T) { |
| 2027 | rec := httptest.NewRecorder() |
| 2028 | req := httptest.NewRequest(http.MethodGet, "/upstream", nil) |
| 2029 | proxy.ServeHTTP(rec, req) |
| 2030 | |
| 2031 | assert.Equal(t, http.StatusOK, rec.Code) |
| 2032 | assert.Equal(t, "upstream", rec.Body.String()) |
| 2033 | |
| 2034 | // checking noCacheHeaders does not exists in response headers from upstream |
| 2035 | for k := range noCacheHeaders { |
| 2036 | assert.Equal(t, "", rec.Header().Get(k)) |
| 2037 | } |
| 2038 | }) |
| 2039 | |
| 2040 | t.Run("has no-cache", func(t *testing.T) { |
| 2041 | tests := []struct { |
| 2042 | path string |
| 2043 | hasNoCache bool |
| 2044 | }{ |
| 2045 | { |
| 2046 | path: "/oauth2/sign_in", |
| 2047 | hasNoCache: true, |
| 2048 | }, |
| 2049 | { |
| 2050 | path: "/oauth2/sign_out", |
| 2051 | hasNoCache: true, |
| 2052 | }, |
| 2053 | { |
| 2054 | path: "/oauth2/start", |
| 2055 | hasNoCache: true, |
| 2056 | }, |
nothing calls this directly
no test coverage detected