chore(test): add test for cache control
All checks were successful
Build Docker Image / Build-Docker-Image (push) Successful in 42s

This commit is contained in:
2024-12-16 22:51:23 +01:00
parent 9bb603970d
commit a38a9f010d
3 changed files with 31 additions and 4 deletions

View File

@@ -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 {

View File

@@ -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"
) )

View File

@@ -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) {