@@ -1805,7 +1805,7 @@ func Test_prepareNoCache(t *testing.T) {
18051805 }
18061806}
18071807
1808−func Test_noCacheHeadersDoesNotExistsInResponseHeadersFromUpstream(t *testing.T) {
1808+func Test_noCacheHeaders(t *testing.T) {
18091809 upstream := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
18101810 w.Write([]byte("upstream"))
18111811 }))
@@ -1820,17 +1820,68 @@ func Test_noCacheHeadersDoesNotExistsInResponseHeadersFromUpstream(t *testing.T)
18201820 })
18211821 assert.NoError(t, err)
18221822
1823− rec := httptest.NewRecorder()
1824− req := httptest.NewRequest(http.MethodGet, "/upstream", nil)
1825− proxy.ServeHTTP(rec, req)
1823+ t.Run("not exist in response from upstream", func(t *testing.T) {
1824+ rec := httptest.NewRecorder()
1825+ req := httptest.NewRequest(http.MethodGet, "/upstream", nil)
1826+ proxy.ServeHTTP(rec, req)
18261827
1827− assert.Equal(t, http.StatusOK, rec.Code)
1828− assert.Equal(t, "upstream", rec.Body.String())
1828+ assert.Equal(t, http.StatusOK, rec.Code)
1829+ assert.Equal(t, "upstream", rec.Body.String())
18291830
1830− // checking noCacheHeaders does not exists in response headers from upstream
1831− for k := range noCacheHeaders {
1832− assert.Equal(t, "", rec.Header().Get(k))
1833− }
1831+ // checking noCacheHeaders does not exists in response headers from upstream
1832+ for k := range noCacheHeaders {
1833+ assert.Equal(t, "", rec.Header().Get(k))
1834+ }
1835+ })
1836+
1837+ t.Run("has no-cache", func(t *testing.T) {
1838+ tests := []struct {
1839+ path string
1840+ hasNoCache bool
1841+ }{
1842+ {
1843+ path: "/oauth2/sign_in",
1844+ hasNoCache: true,
1845+ },
1846+ {
1847+ path: "/oauth2/sign_out",
1848+ hasNoCache: true,
1849+ },
1850+ {
1851+ path: "/oauth2/start",
1852+ hasNoCache: true,
1853+ },
1854+ {
1855+ path: "/oauth2/callback",
1856+ hasNoCache: true,
1857+ },
1858+ {
1859+ path: "/oauth2/auth",
1860+ hasNoCache: false,
1861+ },
1862+ {
1863+ path: "/oauth2/userinfo",
1864+ hasNoCache: true,
1865+ },
1866+ {
1867+ path: "/upstream",
1868+ hasNoCache: false,
1869+ },
1870+ }
1871+
1872+ for _, tt := range tests {
1873+ t.Run(tt.path, func(t *testing.T) {
1874+ rec := httptest.NewRecorder()
1875+ req := httptest.NewRequest(http.MethodGet, tt.path, nil)
1876+ proxy.ServeHTTP(rec, req)
1877+ cacheControl := rec.Result().Header.Get("Cache-Control")
1878+ if tt.hasNoCache != (strings.Contains(cacheControl, "no-cache")) {
1879+ t.Errorf(`unexpected "Cache-Control" header: %s`, cacheControl)
1880+ }
1881+ })
1882+ }
1883+
1884+ })
18341885}
18351886
18361887func baseTestOptions() *options.Options {