test: Add LogAuditEvent tests
Cover success and failure logging branches (66.7% to 100%)
This commit is contained in:
parent
8f42156781
commit
24fbce1281
1 changed files with 33 additions and 0 deletions
|
|
@ -1036,3 +1036,36 @@ func TestSecurityHeadersWithConfig_NextHandlerCalled(t *testing.T) {
|
||||||
t.Error("next handler was not called")
|
t.Error("next handler was not called")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLogAuditEvent_Success(t *testing.T) {
|
||||||
|
// Should not panic and should log at Info level
|
||||||
|
LogAuditEvent(
|
||||||
|
"test_event",
|
||||||
|
"testuser",
|
||||||
|
"192.168.1.100",
|
||||||
|
"/api/test",
|
||||||
|
true,
|
||||||
|
"test details",
|
||||||
|
)
|
||||||
|
// If we got here without panic, the test passes
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLogAuditEvent_Failure(t *testing.T) {
|
||||||
|
// Should not panic and should log at Warn level
|
||||||
|
LogAuditEvent(
|
||||||
|
"failed_login",
|
||||||
|
"attacker",
|
||||||
|
"203.0.113.42",
|
||||||
|
"/api/login",
|
||||||
|
false,
|
||||||
|
"invalid credentials",
|
||||||
|
)
|
||||||
|
// If we got here without panic, the test passes
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLogAuditEvent_EmptyFields(t *testing.T) {
|
||||||
|
// Should handle empty strings gracefully
|
||||||
|
LogAuditEvent("", "", "", "", true, "")
|
||||||
|
LogAuditEvent("", "", "", "", false, "")
|
||||||
|
// If we got here without panic, the test passes
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue