1
0
forked from baron/baron-sso

세션 IP 표시와 로그아웃 처리 보강

This commit is contained in:
2026-04-06 13:25:36 +09:00
parent 6a3bb19e7d
commit 2ca26cafb2
11 changed files with 292 additions and 63 deletions

View File

@@ -7,7 +7,6 @@ import (
"fmt"
"log/slog"
"reflect"
"strings"
"sync"
"time"
@@ -217,16 +216,5 @@ func AuditMiddleware(config AuditConfig) fiber.Handler {
}
func extractClientIP(c *fiber.Ctx) string {
if forwarded := c.Get("X-Forwarded-For"); forwarded != "" {
parts := strings.Split(forwarded, ",")
if len(parts) > 0 {
if ip := strings.TrimSpace(parts[0]); ip != "" {
return ip
}
}
}
if realIP := strings.TrimSpace(c.Get("X-Real-IP")); realIP != "" {
return realIP
}
return c.IP()
return utils.ResolveClientIP(c.Get("X-Forwarded-For"), c.Get("X-Real-IP"), c.IP())
}

View File

@@ -117,6 +117,30 @@ func TestAuditMiddleware(t *testing.T) {
mockRepo.AssertExpectations(t)
})
t.Run("POST request - Prefer public forwarded IP", func(t *testing.T) {
app := fiber.New()
mockRepo := new(MockAuditRepository)
app.Use(AuditMiddleware(AuditConfig{
Repo: mockRepo,
}))
app.Post("/test", func(c *fiber.Ctx) error {
return c.SendStatus(fiber.StatusOK)
})
mockRepo.On("Create", mock.MatchedBy(func(log *domain.AuditLog) bool {
return log.IPAddress == "203.0.113.25"
})).Return(nil)
req := httptest.NewRequest("POST", "/test", nil)
req.Header.Set("X-Forwarded-For", "100.100.100.1, 203.0.113.25")
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)