forked from baron/baron-sso
DevFront 감사로그 조회 API 추가와 액션 필터링 및 테스트 보강
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -172,3 +173,57 @@ func TestCreateClient_Success(t *testing.T) {
|
||||
secret, _ := secretRepo.GetByID(nil, "new-client-123")
|
||||
assert.Equal(t, "secret-123", secret)
|
||||
}
|
||||
|
||||
func TestListAuditLogs_FilterByActionAndClientID(t *testing.T) {
|
||||
now := time.Now().UTC()
|
||||
auditRepo := &mockAuditRepo{
|
||||
logs: []domain.AuditLog{
|
||||
{
|
||||
EventID: "evt-1",
|
||||
Timestamp: now,
|
||||
UserID: "user-a",
|
||||
EventType: "PUT /api/v1/dev/clients/client-1",
|
||||
Status: "success",
|
||||
Details: `{"action":"UPDATE_CLIENT","target_id":"client-1","tenant_id":"tenant-a"}`,
|
||||
},
|
||||
{
|
||||
EventID: "evt-2",
|
||||
Timestamp: now.Add(-time.Minute),
|
||||
UserID: "user-a",
|
||||
EventType: "DELETE /api/v1/dev/clients/client-1",
|
||||
Status: "success",
|
||||
Details: `{"action":"DELETE_CLIENT","target_id":"client-1","tenant_id":"tenant-a"}`,
|
||||
},
|
||||
{
|
||||
EventID: "evt-3",
|
||||
Timestamp: now.Add(-2 * time.Minute),
|
||||
UserID: "user-b",
|
||||
EventType: "PUT /api/v1/dev/clients/client-2",
|
||||
Status: "failure",
|
||||
Details: `{"action":"UPDATE_CLIENT","target_id":"client-2","tenant_id":"tenant-b"}`,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
h := &DevHandler{
|
||||
AuditRepo: auditRepo,
|
||||
Keto: new(MockKetoService),
|
||||
}
|
||||
app := fiber.New()
|
||||
app.Use(func(c *fiber.Ctx) error {
|
||||
c.Locals("user_profile", &domain.UserProfileResponse{ID: "test-user", Role: domain.RoleSuperAdmin})
|
||||
return c.Next()
|
||||
})
|
||||
app.Get("/api/v1/dev/audit-logs", h.ListAuditLogs)
|
||||
|
||||
req := httptest.NewRequest(http.MethodGet, "/api/v1/dev/audit-logs?action=UPDATE_CLIENT&client_id=client-1&status=success", nil)
|
||||
resp, _ := app.Test(req, -1)
|
||||
|
||||
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
|
||||
var res devAuditListResponse
|
||||
_ = json.NewDecoder(resp.Body).Decode(&res)
|
||||
assert.Len(t, res.Items, 1)
|
||||
assert.Equal(t, "evt-1", res.Items[0].EventID)
|
||||
assert.Equal(t, "success", res.Items[0].Status)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user