fix: remove deprecated middleware helper usages
- commit
- 1489816637d2db7c7d4194a00cceb03ee8524d5f
- author
- brice · · 2026-04-08 17:42 UTC
- parent
- eae8025
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
4 files · +14 -11
M internal/adapters/in/http/admin/middleware_test.go +2 -2
| @@ -10,7 +10,7 @@ import ( | |||
| 10 | 10 | "github.com/stretchr/testify/assert" | |
| 11 | 11 | "github.com/stretchr/testify/mock" | |
| 12 | 12 | ||
| 13 | - | "github.com/bnema/gordon/internal/adapters/in/http/middleware" | |
| 13 | + | "github.com/bnema/gordon/internal/adapters/in/http/httphelper" | |
| 14 | 14 | inmocks "github.com/bnema/gordon/internal/boundaries/in/mocks" | |
| 15 | 15 | outmocks "github.com/bnema/gordon/internal/boundaries/out/mocks" | |
| 16 | 16 | "github.com/bnema/gordon/internal/domain" | |
| @@ -78,7 +78,7 @@ func TestAuthMiddleware_TrustedProxy(t *testing.T) { | |||
| 78 | 78 | ipLimiter := outmocks.NewMockRateLimiter(t) | |
| 79 | 79 | ||
| 80 | 80 | // Request from trusted proxy, should use X-Forwarded-For IP | |
| 81 | - | trustedNets := middleware.ParseTrustedProxies([]string{"127.0.0.1"}) | |
| 81 | + | trustedNets := httphelper.ParseTrustedProxies([]string{"127.0.0.1"}) | |
| 82 | 82 | ||
| 83 | 83 | globalLimiter.EXPECT().Allow(context.Background(), "global").Return(true) | |
| 84 | 84 | ipLimiter.EXPECT().Allow(context.Background(), "ip:203.0.113.50").Return(true) | |
| @@ -10,7 +10,7 @@ import ( | |||||
| 10 | "github.com/stretchr/testify/assert" | 10 | "github.com/stretchr/testify/assert" | ||
| 11 | "github.com/stretchr/testify/mock" | 11 | "github.com/stretchr/testify/mock" | ||
| 12 | 12 | ||||
| 13 | - | "github.com/bnema/gordon/internal/adapters/in/http/middleware" | 13 | + | "github.com/bnema/gordon/internal/adapters/in/http/httphelper" |
| 14 | inmocks "github.com/bnema/gordon/internal/boundaries/in/mocks" | 14 | inmocks "github.com/bnema/gordon/internal/boundaries/in/mocks" | ||
| 15 | outmocks "github.com/bnema/gordon/internal/boundaries/out/mocks" | 15 | outmocks "github.com/bnema/gordon/internal/boundaries/out/mocks" | ||
| 16 | "github.com/bnema/gordon/internal/domain" | 16 | "github.com/bnema/gordon/internal/domain" | ||
| @@ -78,7 +78,7 @@ func TestAuthMiddleware_TrustedProxy(t *testing.T) { | |||||
| 78 | ipLimiter := outmocks.NewMockRateLimiter(t) | 78 | ipLimiter := outmocks.NewMockRateLimiter(t) | ||
| 79 | 79 | ||||
| 80 | // Request from trusted proxy, should use X-Forwarded-For IP | 80 | // Request from trusted proxy, should use X-Forwarded-For IP | ||
| 81 | - | trustedNets := middleware.ParseTrustedProxies([]string{"127.0.0.1"}) | 81 | + | trustedNets := httphelper.ParseTrustedProxies([]string{"127.0.0.1"}) |
| 82 | 82 | ||||
| 83 | globalLimiter.EXPECT().Allow(context.Background(), "global").Return(true) | 83 | globalLimiter.EXPECT().Allow(context.Background(), "global").Return(true) | ||
| 84 | ipLimiter.EXPECT().Allow(context.Background(), "ip:203.0.113.50").Return(true) | 84 | ipLimiter.EXPECT().Allow(context.Background(), "ip:203.0.113.50").Return(true) | ||
M internal/adapters/in/http/registry/ratelimit.go +2 -1
| @@ -8,6 +8,7 @@ import ( | |||
| 8 | 8 | "github.com/bnema/zerowrap" | |
| 9 | 9 | ||
| 10 | 10 | "github.com/bnema/gordon/internal/adapters/dto" | |
| 11 | + | "github.com/bnema/gordon/internal/adapters/in/http/httphelper" | |
| 11 | 12 | "github.com/bnema/gordon/internal/adapters/in/http/middleware" | |
| 12 | 13 | "github.com/bnema/gordon/internal/boundaries/out" | |
| 13 | 14 | ) | |
| @@ -29,7 +30,7 @@ func RateLimitMiddleware( | |||
| 29 | 30 | } | |
| 30 | 31 | ||
| 31 | 32 | // Parse trusted proxy CIDRs once at middleware creation | |
| 32 | - | trustedNets := middleware.ParseTrustedProxies(trustedProxies) | |
| 33 | + | trustedNets := httphelper.ParseTrustedProxies(trustedProxies) | |
| 33 | 34 | ||
| 34 | 35 | return func(next http.Handler) http.Handler { | |
| 35 | 36 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
| @@ -8,6 +8,7 @@ import ( | |||||
| 8 | "github.com/bnema/zerowrap" | 8 | "github.com/bnema/zerowrap" | ||
| 9 | 9 | ||||
| 10 | "github.com/bnema/gordon/internal/adapters/dto" | 10 | "github.com/bnema/gordon/internal/adapters/dto" | ||
| 11 | + | "github.com/bnema/gordon/internal/adapters/in/http/httphelper" | |||
| 11 | "github.com/bnema/gordon/internal/adapters/in/http/middleware" | 12 | "github.com/bnema/gordon/internal/adapters/in/http/middleware" | ||
| 12 | "github.com/bnema/gordon/internal/boundaries/out" | 13 | "github.com/bnema/gordon/internal/boundaries/out" | ||
| 13 | ) | 14 | ) | ||
| @@ -29,7 +30,7 @@ func RateLimitMiddleware( | |||||
| 29 | } | 30 | } | ||
| 30 | 31 | ||||
| 31 | // Parse trusted proxy CIDRs once at middleware creation | 32 | // Parse trusted proxy CIDRs once at middleware creation | ||
| 32 | - | trustedNets := middleware.ParseTrustedProxies(trustedProxies) | 33 | + | trustedNets := httphelper.ParseTrustedProxies(trustedProxies) |
| 33 | 34 | ||||
| 34 | return func(next http.Handler) http.Handler { | 35 | return func(next http.Handler) http.Handler { | ||
| 35 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | 36 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
M internal/adapters/in/http/registry/ratelimit_test.go +4 -3
| @@ -9,6 +9,7 @@ import ( | |||
| 9 | 9 | ||
| 10 | 10 | "github.com/stretchr/testify/assert" | |
| 11 | 11 | ||
| 12 | + | "github.com/bnema/gordon/internal/adapters/in/http/httphelper" | |
| 12 | 13 | "github.com/bnema/gordon/internal/adapters/in/http/middleware" | |
| 13 | 14 | "github.com/bnema/gordon/internal/adapters/out/ratelimit" | |
| 14 | 15 | outmocks "github.com/bnema/gordon/internal/boundaries/out/mocks" | |
| @@ -221,7 +222,7 @@ func TestRateLimitMiddleware_Integration(t *testing.T) { | |||
| 221 | 222 | ||
| 222 | 223 | func TestGetClientIP(t *testing.T) { | |
| 223 | 224 | // Parse trusted proxies for tests | |
| 224 | - | trustedNets := middleware.ParseTrustedProxies([]string{"127.0.0.1", "10.0.0.0/8"}) | |
| 225 | + | trustedNets := httphelper.ParseTrustedProxies([]string{"127.0.0.1", "10.0.0.0/8"}) | |
| 225 | 226 | noTrustedNets := []*net.IPNet{} | |
| 226 | 227 | ||
| 227 | 228 | tests := []struct { | |
| @@ -373,8 +374,8 @@ func TestParseTrustedProxies(t *testing.T) { | |||
| 373 | 374 | ||
| 374 | 375 | for _, tt := range tests { | |
| 375 | 376 | t.Run(tt.name, func(t *testing.T) { | |
| 376 | - | nets := middleware.ParseTrustedProxies(tt.proxies) | |
| 377 | - | got := middleware.IsTrustedProxy(tt.testIP, nets) | |
| 377 | + | nets := httphelper.ParseTrustedProxies(tt.proxies) | |
| 378 | + | got := httphelper.IsTrustedProxy(tt.testIP, nets) | |
| 378 | 379 | assert.Equal(t, tt.want, got) | |
| 379 | 380 | }) | |
| 380 | 381 | } | |
| @@ -9,6 +9,7 @@ import ( | |||||
| 9 | 9 | ||||
| 10 | "github.com/stretchr/testify/assert" | 10 | "github.com/stretchr/testify/assert" | ||
| 11 | 11 | ||||
| 12 | + | "github.com/bnema/gordon/internal/adapters/in/http/httphelper" | |||
| 12 | "github.com/bnema/gordon/internal/adapters/in/http/middleware" | 13 | "github.com/bnema/gordon/internal/adapters/in/http/middleware" | ||
| 13 | "github.com/bnema/gordon/internal/adapters/out/ratelimit" | 14 | "github.com/bnema/gordon/internal/adapters/out/ratelimit" | ||
| 14 | outmocks "github.com/bnema/gordon/internal/boundaries/out/mocks" | 15 | outmocks "github.com/bnema/gordon/internal/boundaries/out/mocks" | ||
| @@ -221,7 +222,7 @@ func TestRateLimitMiddleware_Integration(t *testing.T) { | |||||
| 221 | 222 | ||||
| 222 | func TestGetClientIP(t *testing.T) { | 223 | func TestGetClientIP(t *testing.T) { | ||
| 223 | // Parse trusted proxies for tests | 224 | // Parse trusted proxies for tests | ||
| 224 | - | trustedNets := middleware.ParseTrustedProxies([]string{"127.0.0.1", "10.0.0.0/8"}) | 225 | + | trustedNets := httphelper.ParseTrustedProxies([]string{"127.0.0.1", "10.0.0.0/8"}) |
| 225 | noTrustedNets := []*net.IPNet{} | 226 | noTrustedNets := []*net.IPNet{} | ||
| 226 | 227 | ||||
| 227 | tests := []struct { | 228 | tests := []struct { | ||
| @@ -373,8 +374,8 @@ func TestParseTrustedProxies(t *testing.T) { | |||||
| 373 | 374 | ||||
| 374 | for _, tt := range tests { | 375 | for _, tt := range tests { | ||
| 375 | t.Run(tt.name, func(t *testing.T) { | 376 | t.Run(tt.name, func(t *testing.T) { | ||
| 376 | - | nets := middleware.ParseTrustedProxies(tt.proxies) | 377 | + | nets := httphelper.ParseTrustedProxies(tt.proxies) |
| 377 | - | got := middleware.IsTrustedProxy(tt.testIP, nets) | 378 | + | got := httphelper.IsTrustedProxy(tt.testIP, nets) |
| 378 | assert.Equal(t, tt.want, got) | 379 | assert.Equal(t, tt.want, got) | ||
| 379 | }) | 380 | }) | ||
| 380 | } | 381 | } | ||
M internal/app/run.go +6 -5
| @@ -46,6 +46,7 @@ import ( | |||
| 46 | 46 | "github.com/bnema/gordon/internal/adapters/dto" | |
| 47 | 47 | "github.com/bnema/gordon/internal/adapters/in/http/admin" | |
| 48 | 48 | authhandler "github.com/bnema/gordon/internal/adapters/in/http/auth" | |
| 49 | + | "github.com/bnema/gordon/internal/adapters/in/http/httphelper" | |
| 49 | 50 | "github.com/bnema/gordon/internal/adapters/in/http/middleware" | |
| 50 | 51 | "github.com/bnema/gordon/internal/adapters/in/http/onboarding" | |
| 51 | 52 | proxyadapter "github.com/bnema/gordon/internal/adapters/in/http/proxy" | |
| @@ -1680,7 +1681,7 @@ func loopbackOnly(next http.Handler, log zerowrap.Logger) http.Handler { | |||
| 1680 | 1681 | func createHTTPHandlers(svc *services, cfg Config, log zerowrap.Logger, accessWriter out.AccessLogWriter) (http.Handler, http.Handler, http.Handler) { | |
| 1681 | 1682 | // Parse trusted proxies once for all middleware chains. | |
| 1682 | 1683 | // This ensures consistent IP extraction across logging, rate limiting, and auth. | |
| 1683 | - | trustedNets := middleware.ParseTrustedProxies(cfg.API.RateLimit.TrustedProxies) | |
| 1684 | + | trustedNets := httphelper.ParseTrustedProxies(cfg.API.RateLimit.TrustedProxies) | |
| 1684 | 1685 | ||
| 1685 | 1686 | // Registry handler (unchanged) | |
| 1686 | 1687 | registryHandler := registry.NewHandler(svc.registrySvc, log, svc.maxBlobChunkSize) | |
| @@ -1812,8 +1813,8 @@ func directHTTPOnboardingGate(ob *onboarding.Handler, proxyNets []*net.IPNet, pr | |||
| 1812 | 1813 | )(onboardingMux) | |
| 1813 | 1814 | ||
| 1814 | 1815 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
| 1815 | - | remoteIP := middleware.ExtractRemoteIP(r.RemoteAddr) | |
| 1816 | - | if middleware.IsTrustedOrLocal(remoteIP, proxyNets) { | |
| 1816 | + | remoteIP := httphelper.ExtractRemoteIP(r.RemoteAddr) | |
| 1817 | + | if httphelper.IsTrustedOrLocal(remoteIP, proxyNets) { | |
| 1817 | 1818 | proxyChain.ServeHTTP(w, r) | |
| 1818 | 1819 | return | |
| 1819 | 1820 | } | |
| @@ -1868,10 +1869,10 @@ func parseCIDRAllowlist(ips []string, label string, log zerowrap.Logger) ([]*net | |||
| 1868 | 1869 | return nil, false | |
| 1869 | 1870 | } | |
| 1870 | 1871 | ||
| 1871 | - | allowedNets := middleware.ParseTrustedProxies(ips) | |
| 1872 | + | allowedNets := httphelper.ParseTrustedProxies(ips) | |
| 1872 | 1873 | if len(allowedNets) != len(ips) { | |
| 1873 | 1874 | for _, entry := range ips { | |
| 1874 | - | if nets := middleware.ParseTrustedProxies([]string{entry}); len(nets) == 0 { | |
| 1875 | + | if nets := httphelper.ParseTrustedProxies([]string{entry}); len(nets) == 0 { | |
| 1875 | 1876 | log.Warn().Str("entry", entry).Msgf("ignoring invalid %s entry", label) | |
| 1876 | 1877 | } | |
| 1877 | 1878 | } | |
| @@ -46,6 +46,7 @@ import ( | |||||
| 46 | "github.com/bnema/gordon/internal/adapters/dto" | 46 | "github.com/bnema/gordon/internal/adapters/dto" | ||
| 47 | "github.com/bnema/gordon/internal/adapters/in/http/admin" | 47 | "github.com/bnema/gordon/internal/adapters/in/http/admin" | ||
| 48 | authhandler "github.com/bnema/gordon/internal/adapters/in/http/auth" | 48 | authhandler "github.com/bnema/gordon/internal/adapters/in/http/auth" | ||
| 49 | + | "github.com/bnema/gordon/internal/adapters/in/http/httphelper" | |||
| 49 | "github.com/bnema/gordon/internal/adapters/in/http/middleware" | 50 | "github.com/bnema/gordon/internal/adapters/in/http/middleware" | ||
| 50 | "github.com/bnema/gordon/internal/adapters/in/http/onboarding" | 51 | "github.com/bnema/gordon/internal/adapters/in/http/onboarding" | ||
| 51 | proxyadapter "github.com/bnema/gordon/internal/adapters/in/http/proxy" | 52 | proxyadapter "github.com/bnema/gordon/internal/adapters/in/http/proxy" | ||
| @@ -1680,7 +1681,7 @@ func loopbackOnly(next http.Handler, log zerowrap.Logger) http.Handler { | |||||
| 1680 | func createHTTPHandlers(svc *services, cfg Config, log zerowrap.Logger, accessWriter out.AccessLogWriter) (http.Handler, http.Handler, http.Handler) { | 1681 | func createHTTPHandlers(svc *services, cfg Config, log zerowrap.Logger, accessWriter out.AccessLogWriter) (http.Handler, http.Handler, http.Handler) { | ||
| 1681 | // Parse trusted proxies once for all middleware chains. | 1682 | // Parse trusted proxies once for all middleware chains. | ||
| 1682 | // This ensures consistent IP extraction across logging, rate limiting, and auth. | 1683 | // This ensures consistent IP extraction across logging, rate limiting, and auth. | ||
| 1683 | - | trustedNets := middleware.ParseTrustedProxies(cfg.API.RateLimit.TrustedProxies) | 1684 | + | trustedNets := httphelper.ParseTrustedProxies(cfg.API.RateLimit.TrustedProxies) |
| 1684 | 1685 | ||||
| 1685 | // Registry handler (unchanged) | 1686 | // Registry handler (unchanged) | ||
| 1686 | registryHandler := registry.NewHandler(svc.registrySvc, log, svc.maxBlobChunkSize) | 1687 | registryHandler := registry.NewHandler(svc.registrySvc, log, svc.maxBlobChunkSize) | ||
| @@ -1812,8 +1813,8 @@ func directHTTPOnboardingGate(ob *onboarding.Handler, proxyNets []*net.IPNet, pr | |||||
| 1812 | )(onboardingMux) | 1813 | )(onboardingMux) | ||
| 1813 | 1814 | ||||
| 1814 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | 1815 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| 1815 | - | remoteIP := middleware.ExtractRemoteIP(r.RemoteAddr) | 1816 | + | remoteIP := httphelper.ExtractRemoteIP(r.RemoteAddr) |
| 1816 | - | if middleware.IsTrustedOrLocal(remoteIP, proxyNets) { | 1817 | + | if httphelper.IsTrustedOrLocal(remoteIP, proxyNets) { |
| 1817 | proxyChain.ServeHTTP(w, r) | 1818 | proxyChain.ServeHTTP(w, r) | ||
| 1818 | return | 1819 | return | ||
| 1819 | } | 1820 | } | ||
| @@ -1868,10 +1869,10 @@ func parseCIDRAllowlist(ips []string, label string, log zerowrap.Logger) ([]*net | |||||
| 1868 | return nil, false | 1869 | return nil, false | ||
| 1869 | } | 1870 | } | ||
| 1870 | 1871 | ||||
| 1871 | - | allowedNets := middleware.ParseTrustedProxies(ips) | 1872 | + | allowedNets := httphelper.ParseTrustedProxies(ips) |
| 1872 | if len(allowedNets) != len(ips) { | 1873 | if len(allowedNets) != len(ips) { | ||
| 1873 | for _, entry := range ips { | 1874 | for _, entry := range ips { | ||
| 1874 | - | if nets := middleware.ParseTrustedProxies([]string{entry}); len(nets) == 0 { | 1875 | + | if nets := httphelper.ParseTrustedProxies([]string{entry}); len(nets) == 0 { |
| 1875 | log.Warn().Str("entry", entry).Msgf("ignoring invalid %s entry", label) | 1876 | log.Warn().Str("entry", entry).Msgf("ignoring invalid %s entry", label) | ||
| 1876 | } | 1877 | } | ||
| 1877 | } | 1878 | } | ||