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 (
"fmt"
"net/http"
"strings"
"me-fit/service"
"net/http"
)
type csrfResponseWriter struct {

View File

@@ -1,12 +1,12 @@
package middleware
import (
"me-fit/log"
"net/http"
"strconv"
"time"
"me-fit/log"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)

View File

@@ -32,6 +32,34 @@ var (
func TestSecurity(t *testing.T) {
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) {