test: verify CSRF rejects requests with only cookie token

This commit is contained in:
2025-12-26 17:28:58 +01:00
parent 0802b9dd9d
commit fc23cbd6fd

View File

@@ -94,6 +94,23 @@ func TestCSRFTokenValidationMissingCookie(t *testing.T) {
}
}
func TestCSRFTokenValidationOnlyCookie(t *testing.T) {
token, err := CSRFToken()
if err != nil {
t.Fatalf("Failed to generate CSRF token: %v", err)
}
request := httptest.NewRequest("POST", "/test", nil)
request.AddCookie(&http.Cookie{
Name: CSRFTokenCookieName,
Value: token,
})
if ValidateCSRFToken(request) {
t.Error("Request with only cookie (no form/header token) should fail validation")
}
}
func TestCSRFTokenValidationHeader(t *testing.T) {
token, err := CSRFToken()
if err != nil {