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 (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"me-fit/service"
|
||||
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type csrfResponseWriter struct {
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
28
main_test.go
28
main_test.go
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user