R56: honor RateLimit config as sustained req rate

This commit is contained in:
2026-08-13 15:49:47 +01:00
parent ac2fdfe09d
commit 49d1942de9
2 changed files with 37 additions and 1 deletions
+1 -1
View File
@@ -296,7 +296,7 @@ func NewWithContext(ctx context.Context, config *Config, next http.Handler, name
defaultSystemScopes := []string{"openid", "profile", "email"}
return deduplicateScopes(mergeScopes(defaultSystemScopes, userProvidedScopes))
}(),
limiter: rate.NewLimiter(rate.Every(time.Second), config.RateLimit),
limiter: rate.NewLimiter(rate.Limit(config.RateLimit), config.RateLimit),
tokenCache: cacheManager.GetSharedTokenCache(),
httpClient: httpClient,
tokenHTTPClient: tokenHTTPClient,
+36
View File
@@ -0,0 +1,36 @@
package traefikoidc
import (
"context"
"testing"
"github.com/stretchr/testify/require"
"golang.org/x/time/rate"
)
// Review regression: the RateLimit config is documented as "requests per
// second" (default 100). The plugin must honor it as the sustained token
// rate, not silently cap sustained throughput at 1 rps by using the value
// only as burst with a fixed rate.Every(time.Second) refill.
func TestRateLimitConfigSetsSustainedRate(t *testing.T) {
require := require.New(t)
cfg := &Config{
ProviderURL: "https://accounts.google.com",
ClientID: "test-client",
ClientSecret: "test-secret",
CallbackURL: "/callback",
SessionEncryptionKey: "this-is-a-valid-session-key-32b!",
RateLimit: 50,
}
p, err := NewWithContext(context.Background(), cfg, nil, "test")
require.NoError(err)
defer p.Close()
// The configured requests-per-second must be the limiter's actual rate,
// with a matching burst.
require.Equal(rate.Limit(50), p.limiter.Limit(),
"sustained rate must equal configured RateLimit (was fixed at 1 rps)")
require.Equal(50, p.limiter.Burst())
}