This commit is contained in:
Mateusz Gruszczyński committed 2026-10-04 11:15:58 +02:00
1 parent 87e571c170
commit fa7abc9e53
308 files changed
+49746 -50237

No files matched your search

+36
View File
@@ -0,0 +1,36 @@
mod tests {
use super::*;
#[test]
fn access_modes_are_fail_closed_for_allow_lists() {
let mut settings = Settings::default();
settings.country_access.mode = CountryMode::Allow;
settings.country_access.countries = vec!["pl".into()];
settings.validate().unwrap();
assert!(settings.country_allowed(Some("PL")));
assert!(!settings.country_allowed(Some("DE")));
assert!(!settings.country_allowed(None));
settings.country_access.mode = CountryMode::Block;
assert!(!settings.country_allowed(Some("PL")));
assert!(settings.country_allowed(None));
}
#[test]
fn country_limit_overrides_base_limit() {
let mut settings = Settings {
enabled: true,
requests: 10,
burst: 0,
country_limits: vec![CountryLimit {
country: "PL".into(),
requests: 1,
window_seconds: 60,
burst: 0,
}],
..Default::default()
};
settings.validate().unwrap();
let limiter = Limiter::new();
let ip = "192.0.2.1".parse().unwrap();
assert!(limiter.check(1, "site", ip, Some("PL"), &settings).is_ok());
assert!(limiter.check(1, "site", ip, Some("PL"), &settings).is_err());
}
}