Add reusable strict JSON, rate limiting, and sealed secrets
This commit is contained in:
10 files changed
+778
-40
No files matched your search
@@ -35,7 +35,7 @@ namespace
|
||||
Void::Testing::expect(rl.allow(1));
|
||||
Void::Testing::expect(rl.allow(1));
|
||||
Void::Testing::expect(!rl.allow(1)); // key 1 exhausted
|
||||
Void::Testing::expect(rl.allow(2)); // key 2 still full
|
||||
Void::Testing::expect(rl.allow(2)); // key 2 still full
|
||||
}
|
||||
|
||||
Test refills_per_key_over_time()
|
||||
@@ -60,16 +60,43 @@ namespace
|
||||
|
||||
Test cleanup_drops_stale_keys()
|
||||
{
|
||||
KeyedRateLimiter<int> rl{1.0, 1.0};
|
||||
ManualClock clk;
|
||||
KeyedRateLimiter<int> rl{1.0, 1.0, clk.fn()};
|
||||
(void)rl.allow(1);
|
||||
(void)rl.allow(2);
|
||||
Void::Testing::expect_eq(rl.tracked(), std::size_t{2});
|
||||
// Nothing is older than an hour yet.
|
||||
Void::Testing::expect_eq(rl.cleanup(1h), std::size_t{0});
|
||||
Void::Testing::expect_eq(rl.tracked(), std::size_t{2});
|
||||
// Everything is older than 0ns.
|
||||
Void::Testing::expect_eq(rl.cleanup(0ns), std::size_t{2});
|
||||
clk.advance(2h);
|
||||
Void::Testing::expect_eq(rl.cleanup(1h), std::size_t{2});
|
||||
Void::Testing::expect_eq(rl.tracked(), std::size_t{0});
|
||||
}
|
||||
|
||||
Test bounds_untrusted_key_cardinality()
|
||||
{
|
||||
ManualClock clk;
|
||||
KeyedRateLimiter<std::string> rl{2.0, 0.0, clk.fn(),
|
||||
std::size_t{2}};
|
||||
Void::Testing::expect(rl.allow("a"));
|
||||
Void::Testing::expect(rl.allow("b"));
|
||||
Void::Testing::expect(!rl.allow("c"));
|
||||
Void::Testing::expect_eq(rl.tracked(), std::size_t{2});
|
||||
clk.advance(2min);
|
||||
Void::Testing::expect_eq(rl.cleanup(1min), std::size_t{2});
|
||||
Void::Testing::expect(rl.allow("c"));
|
||||
}
|
||||
|
||||
Test explicit_time_is_shared_by_tracking_and_refill()
|
||||
{
|
||||
ManualClock clk;
|
||||
KeyedRateLimiter<int> rl{1.0, 1.0, clk.fn(), std::size_t{1}};
|
||||
const TP start = *clk.now;
|
||||
Void::Testing::expect(rl.allow_at(1, start));
|
||||
Void::Testing::expect(!rl.allow_at(1, start));
|
||||
Void::Testing::expect(rl.allow_at(1, start + 1s));
|
||||
Void::Testing::expect_eq(rl.cleanup_at(start + 3s, 1s),
|
||||
std::size_t{1});
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
Reference in new issue
Block a user