1
0
forked from baron/baron-sso

Fix hydra consent session parsing and audit detail tests

This commit is contained in:
Lectom C Han
2026-02-06 17:29:27 +09:00
parent 3a6ae4948a
commit 226de652e3
2 changed files with 47 additions and 2 deletions

View File

@@ -69,6 +69,45 @@ func TestAuditMiddleware(t *testing.T) {
mockRepo.AssertExpectations(t)
})
t.Run("POST request - Merge extra audit details", func(t *testing.T) {
app := fiber.New()
mockRepo := new(MockAuditRepository)
app.Use(AuditMiddleware(AuditConfig{
Repo: mockRepo,
}))
app.Post("/test", func(c *fiber.Ctx) error {
c.Locals("audit_details_extra", map[string]any{
"client_id": "rp-1",
"client_name": "Demo App",
})
c.Locals("auth_timeline_skip", true)
return c.SendStatus(fiber.StatusOK)
})
mockRepo.On("Create", mock.MatchedBy(func(log *domain.AuditLog) bool {
var details map[string]any
if err := json.Unmarshal([]byte(log.Details), &details); err != nil {
return false
}
if details["client_id"] != "rp-1" {
return false
}
if details["client_name"] != "Demo App" {
return false
}
skip, ok := details["auth_timeline_skip"].(bool)
return ok && skip
})).Return(nil)
req := httptest.NewRequest("POST", "/test", nil)
resp, _ := app.Test(req)
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
mockRepo.AssertExpectations(t)
})
t.Run("POST request - Sync Failure (Strict Mode)", func(t *testing.T) {
app := fiber.New()
mockRepo := new(MockAuditRepository)