mirror of
https://github.com/lukaszraczylo/traefikoidc.git
synced 2026-10-17 04:37:48 +00:00
R56: honor RateLimit config as sustained req rate
This commit is contained in:
@@ -296,7 +296,7 @@ func NewWithContext(ctx context.Context, config *Config, next http.Handler, name
|
|||||||
defaultSystemScopes := []string{"openid", "profile", "email"}
|
defaultSystemScopes := []string{"openid", "profile", "email"}
|
||||||
return deduplicateScopes(mergeScopes(defaultSystemScopes, userProvidedScopes))
|
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(),
|
tokenCache: cacheManager.GetSharedTokenCache(),
|
||||||
httpClient: httpClient,
|
httpClient: httpClient,
|
||||||
tokenHTTPClient: tokenHTTPClient,
|
tokenHTTPClient: tokenHTTPClient,
|
||||||
|
|||||||
@@ -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())
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user