Commit 50a8116a authored by erio's avatar erio
Browse files

fix: update SecurityHeaders call sites to match new signature

parent bf6fe5e9
...@@ -100,7 +100,7 @@ func runSetupServer() { ...@@ -100,7 +100,7 @@ func runSetupServer() {
r := gin.New() r := gin.New()
r.Use(middleware.Recovery()) r.Use(middleware.Recovery())
r.Use(middleware.CORS(config.CORSConfig{})) r.Use(middleware.CORS(config.CORSConfig{}))
r.Use(middleware.SecurityHeaders(config.CSPConfig{Enabled: true, Policy: config.DefaultCSPPolicy})) r.Use(middleware.SecurityHeaders(config.CSPConfig{Enabled: true, Policy: config.DefaultCSPPolicy}, nil))
// Register setup routes // Register setup routes
setup.RegisterRoutes(r) setup.RegisterRoutes(r)
......
...@@ -84,7 +84,7 @@ func TestGetNonceFromContext(t *testing.T) { ...@@ -84,7 +84,7 @@ func TestGetNonceFromContext(t *testing.T) {
func TestSecurityHeaders(t *testing.T) { func TestSecurityHeaders(t *testing.T) {
t.Run("sets_basic_security_headers", func(t *testing.T) { t.Run("sets_basic_security_headers", func(t *testing.T) {
cfg := config.CSPConfig{Enabled: false} cfg := config.CSPConfig{Enabled: false}
middleware := SecurityHeaders(cfg) middleware := SecurityHeaders(cfg, nil)
w := httptest.NewRecorder() w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w) c, _ := gin.CreateTestContext(w)
...@@ -99,7 +99,7 @@ func TestSecurityHeaders(t *testing.T) { ...@@ -99,7 +99,7 @@ func TestSecurityHeaders(t *testing.T) {
t.Run("csp_disabled_no_csp_header", func(t *testing.T) { t.Run("csp_disabled_no_csp_header", func(t *testing.T) {
cfg := config.CSPConfig{Enabled: false} cfg := config.CSPConfig{Enabled: false}
middleware := SecurityHeaders(cfg) middleware := SecurityHeaders(cfg, nil)
w := httptest.NewRecorder() w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w) c, _ := gin.CreateTestContext(w)
...@@ -115,7 +115,7 @@ func TestSecurityHeaders(t *testing.T) { ...@@ -115,7 +115,7 @@ func TestSecurityHeaders(t *testing.T) {
Enabled: true, Enabled: true,
Policy: "default-src 'self'", Policy: "default-src 'self'",
} }
middleware := SecurityHeaders(cfg) middleware := SecurityHeaders(cfg, nil)
w := httptest.NewRecorder() w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w) c, _ := gin.CreateTestContext(w)
...@@ -136,7 +136,7 @@ func TestSecurityHeaders(t *testing.T) { ...@@ -136,7 +136,7 @@ func TestSecurityHeaders(t *testing.T) {
Enabled: true, Enabled: true,
Policy: "default-src 'self'; script-src 'self' __CSP_NONCE__", Policy: "default-src 'self'; script-src 'self' __CSP_NONCE__",
} }
middleware := SecurityHeaders(cfg) middleware := SecurityHeaders(cfg, nil)
w := httptest.NewRecorder() w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w) c, _ := gin.CreateTestContext(w)
...@@ -156,7 +156,7 @@ func TestSecurityHeaders(t *testing.T) { ...@@ -156,7 +156,7 @@ func TestSecurityHeaders(t *testing.T) {
Enabled: true, Enabled: true,
Policy: "script-src 'self' __CSP_NONCE__", Policy: "script-src 'self' __CSP_NONCE__",
} }
middleware := SecurityHeaders(cfg) middleware := SecurityHeaders(cfg, nil)
w := httptest.NewRecorder() w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w) c, _ := gin.CreateTestContext(w)
...@@ -180,7 +180,7 @@ func TestSecurityHeaders(t *testing.T) { ...@@ -180,7 +180,7 @@ func TestSecurityHeaders(t *testing.T) {
Enabled: true, Enabled: true,
Policy: "", Policy: "",
} }
middleware := SecurityHeaders(cfg) middleware := SecurityHeaders(cfg, nil)
w := httptest.NewRecorder() w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w) c, _ := gin.CreateTestContext(w)
...@@ -199,7 +199,7 @@ func TestSecurityHeaders(t *testing.T) { ...@@ -199,7 +199,7 @@ func TestSecurityHeaders(t *testing.T) {
Enabled: true, Enabled: true,
Policy: " \t\n ", Policy: " \t\n ",
} }
middleware := SecurityHeaders(cfg) middleware := SecurityHeaders(cfg, nil)
w := httptest.NewRecorder() w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w) c, _ := gin.CreateTestContext(w)
...@@ -217,7 +217,7 @@ func TestSecurityHeaders(t *testing.T) { ...@@ -217,7 +217,7 @@ func TestSecurityHeaders(t *testing.T) {
Enabled: true, Enabled: true,
Policy: "script-src __CSP_NONCE__; style-src __CSP_NONCE__", Policy: "script-src __CSP_NONCE__; style-src __CSP_NONCE__",
} }
middleware := SecurityHeaders(cfg) middleware := SecurityHeaders(cfg, nil)
w := httptest.NewRecorder() w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w) c, _ := gin.CreateTestContext(w)
...@@ -235,7 +235,7 @@ func TestSecurityHeaders(t *testing.T) { ...@@ -235,7 +235,7 @@ func TestSecurityHeaders(t *testing.T) {
t.Run("calls_next_handler", func(t *testing.T) { t.Run("calls_next_handler", func(t *testing.T) {
cfg := config.CSPConfig{Enabled: true, Policy: "default-src 'self'"} cfg := config.CSPConfig{Enabled: true, Policy: "default-src 'self'"}
middleware := SecurityHeaders(cfg) middleware := SecurityHeaders(cfg, nil)
nextCalled := false nextCalled := false
router := gin.New() router := gin.New()
...@@ -258,7 +258,7 @@ func TestSecurityHeaders(t *testing.T) { ...@@ -258,7 +258,7 @@ func TestSecurityHeaders(t *testing.T) {
Enabled: true, Enabled: true,
Policy: "script-src __CSP_NONCE__", Policy: "script-src __CSP_NONCE__",
} }
middleware := SecurityHeaders(cfg) middleware := SecurityHeaders(cfg, nil)
nonces := make(map[string]bool) nonces := make(map[string]bool)
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
...@@ -376,7 +376,7 @@ func BenchmarkSecurityHeadersMiddleware(b *testing.B) { ...@@ -376,7 +376,7 @@ func BenchmarkSecurityHeadersMiddleware(b *testing.B) {
Enabled: true, Enabled: true,
Policy: "script-src 'self' __CSP_NONCE__", Policy: "script-src 'self' __CSP_NONCE__",
} }
middleware := SecurityHeaders(cfg) middleware := SecurityHeaders(cfg, nil)
b.ResetTimer() b.ResetTimer()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment