33 lines
961 B
Go
33 lines
961 B
Go
package api
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
"time"
|
|
|
|
sharedlimit "git.sendico.io/tech/sxchnge/bff/edge/shared/interface/ratelimit"
|
|
"git.sendico.io/tech/sxchnge/bff/pkg/merrors"
|
|
)
|
|
|
|
func TestVerificationRateLimitsDefaults(t *testing.T) {
|
|
got, err := (*VerificationConfig)(nil).ResolveRateLimits()
|
|
if err != nil {
|
|
t.Fatalf("resolve defaults: %v", err)
|
|
}
|
|
if got.PerDestination.Limit != 5 || got.PerDestination.Window != time.Hour ||
|
|
got.PerIP.Limit != 20 || got.PerIP.Window != time.Hour {
|
|
t.Fatalf("unexpected defaults: %+v", got)
|
|
}
|
|
}
|
|
|
|
func TestVerificationRateLimitsRejectInvalidPolicy(t *testing.T) {
|
|
cfg := &VerificationConfig{RateLimits: &VerificationRateLimitsConfig{
|
|
PerDestination: sharedlimit.WindowConfig{Limit: 5, Window: "1h"},
|
|
PerIP: sharedlimit.WindowConfig{Limit: 0, Window: "1h"},
|
|
}}
|
|
_, err := cfg.ResolveRateLimits()
|
|
if !errors.Is(err, merrors.ErrInvalidArg) {
|
|
t.Fatalf("expected invalid argument, got %v", err)
|
|
}
|
|
}
|