test: pin the documented limits and close gaps found by mutation checks
- Test the lockout, the confirmation cap and Retry-After with literal numbers, not the constants - Test that failed deliveries are listed before the most retried ones
This commit is contained in:
parent
2b66937ac7
commit
7005edcb9b
1 changed files with 54 additions and 1 deletions
|
|
@ -180,3 +180,37 @@ func TestTheLimiterForgetsOldAddresses(t *testing.T) {
|
|||
t.Fatalf("the limiter keeps %d expired addresses: memory grows without bound", n)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTheLimitIsTenWrongTokensInFiveMinutes(t *testing.T) {
|
||||
// The numbers are part of the documented behaviour: do not derive them from the constants.
|
||||
h, clk := limited(t)
|
||||
for i := 1; i <= 10; i++ {
|
||||
if rec := attempt(h, "203.0.113.7", "wrong"); rec.Code != 401 {
|
||||
t.Fatalf("wrong token number %d must still be a plain 401, got %d", i, rec.Code)
|
||||
}
|
||||
}
|
||||
if rec := attempt(h, "203.0.113.7", token); rec.Code != 429 {
|
||||
t.Fatalf("the 11th attempt is locked out: %d", rec.Code)
|
||||
}
|
||||
clk.advance(4*time.Minute + 59*time.Second)
|
||||
if rec := attempt(h, "203.0.113.7", token); rec.Code != 429 {
|
||||
t.Fatalf("still locked just before 5 minutes: %d", rec.Code)
|
||||
}
|
||||
clk.advance(2 * time.Second)
|
||||
if rec := attempt(h, "203.0.113.7", token); rec.Code != 200 {
|
||||
t.Fatalf("free after 5 minutes: %d", rec.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRetryAfterCountsDown(t *testing.T) {
|
||||
h, clk := limited(t)
|
||||
for i := 0; i < 10; i++ {
|
||||
attempt(h, "203.0.113.7", "wrong")
|
||||
}
|
||||
first, _ := strconv.Atoi(attempt(h, "203.0.113.7", token).Header().Get("Retry-After"))
|
||||
clk.advance(2 * time.Minute)
|
||||
later, _ := strconv.Atoi(attempt(h, "203.0.113.7", token).Header().Get("Retry-After"))
|
||||
if first != 300 || later != 180 {
|
||||
t.Fatalf("Retry-After is the time left: %d then %d, want 300 then 180", first, later)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue