aboutsummaryrefslogtreecommitdiffstats
path: root/web/web_test.go
diff options
context:
space:
mode:
authorAdam Mathes <adam@adammathes.com>2026-02-14 09:20:40 -0800
committerAdam Mathes <adam@adammathes.com>2026-02-14 09:20:40 -0800
commit08032aab10f0e1429d25ecae1acf6c40d63e9ff4 (patch)
treeb4f89ec2deabb7c6bc3237d300512f1af92ea67c /web/web_test.go
parent17117617017aba1f29a1f6c8939cdc7c1fd94438 (diff)
downloadneko-08032aab10f0e1429d25ecae1acf6c40d63e9ff4.tar.gz
neko-08032aab10f0e1429d25ecae1acf6c40d63e9ff4.tar.bz2
neko-08032aab10f0e1429d25ecae1acf6c40d63e9ff4.zip
security: add HTTP security headers (fixing NK-7xuajb)
Diffstat (limited to 'web/web_test.go')
-rw-r--r--web/web_test.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/web/web_test.go b/web/web_test.go
index 89ca998..c6cf306 100644
--- a/web/web_test.go
+++ b/web/web_test.go
@@ -10,10 +10,15 @@ import (
"adammathes.com/neko/api"
"adammathes.com/neko/config"
+ "adammathes.com/neko/internal/safehttp"
"adammathes.com/neko/models"
"golang.org/x/crypto/bcrypt"
)
+func init() {
+ safehttp.AllowLocal = true
+}
+
func setupTestDB(t *testing.T) {
t.Helper()
config.Config.DBFile = filepath.Join(t.TempDir(), "test.db")
@@ -774,3 +779,23 @@ func TestCSRFMiddleware(t *testing.T) {
t.Errorf("Expected 200 for POST with valid token, got %d", rr.Code)
}
}
+
+func TestSecurityHeadersMiddleware(t *testing.T) {
+ handler := SecurityHeadersMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ w.WriteHeader(http.StatusOK)
+ }))
+
+ req := httptest.NewRequest("GET", "/", nil)
+ rr := httptest.NewRecorder()
+ handler.ServeHTTP(rr, req)
+
+ if rr.Header().Get("X-Content-Type-Options") != "nosniff" {
+ t.Error("Missing X-Content-Type-Options: nosniff")
+ }
+ if rr.Header().Get("X-Frame-Options") != "DENY" {
+ t.Error("Missing X-Frame-Options: DENY")
+ }
+ if rr.Header().Get("Content-Security-Policy") == "" {
+ t.Error("Missing Content-Security-Policy")
+ }
+}