chore(test): add test for cache control
All checks were successful
Build Docker Image / Build-Docker-Image (push) Successful in 42s
All checks were successful
Build Docker Image / Build-Docker-Image (push) Successful in 42s
This commit is contained in:
@@ -2,11 +2,10 @@ package middleware
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"me-fit/service"
|
"me-fit/service"
|
||||||
|
|
||||||
"net/http"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type csrfResponseWriter struct {
|
type csrfResponseWriter struct {
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package middleware
|
package middleware
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"me-fit/log"
|
|
||||||
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"me-fit/log"
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||||
)
|
)
|
||||||
|
|||||||
28
main_test.go
28
main_test.go
@@ -32,6 +32,34 @@ var (
|
|||||||
|
|
||||||
func TestSecurity(t *testing.T) {
|
func TestSecurity(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
t.Run("should keep caching for static content", func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
_, basePath, ctx := setupIntegrationTest(t)
|
||||||
|
|
||||||
|
req, err := http.NewRequestWithContext(ctx, "GET", basePath+"/static/favicon.svg", nil)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
|
||||||
|
resp, err := httpClient.Do(req)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
|
||||||
|
cacheControl := resp.Header.Get("Cache-Control")
|
||||||
|
assert.Equal(t, "", cacheControl)
|
||||||
|
})
|
||||||
|
t.Run("should disable caching for dynamic content", func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
_, basePath, ctx := setupIntegrationTest(t)
|
||||||
|
|
||||||
|
req, err := http.NewRequestWithContext(ctx, "GET", basePath, nil)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
|
||||||
|
resp, err := httpClient.Do(req)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
|
||||||
|
cacheControl := resp.Header.Get("Cache-Control")
|
||||||
|
assert.Equal(t, "no-cache, no-store, must-revalidate", cacheControl)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAuth(t *testing.T) {
|
func TestAuth(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user