mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 09:20:22 +08:00
Merge branch 'fawney19:main' into main
This commit is contained in:
@@ -2000,7 +2000,7 @@ fn resolve_effective_rate_limit_policy(
|
||||
groups: &[aether_data::repository::users::StoredUserGroup],
|
||||
) -> Option<i32> {
|
||||
let group_policy = groups.iter().fold(None, |effective, group| {
|
||||
intersect_rate_limit_policies(
|
||||
union_rate_limit_policies(
|
||||
effective,
|
||||
rate_limit_restriction_from_mode(&group.rate_limit_mode, group.rate_limit),
|
||||
)
|
||||
@@ -2073,6 +2073,22 @@ fn intersect_rate_limit_policies(
|
||||
}
|
||||
}
|
||||
|
||||
fn union_rate_limit_policies(
|
||||
left: Option<RateLimitRestriction>,
|
||||
right: Option<RateLimitRestriction>,
|
||||
) -> Option<RateLimitRestriction> {
|
||||
match (left, right) {
|
||||
(None, None) => None,
|
||||
(Some(value), None) | (None, Some(value)) => Some(value),
|
||||
(Some(RateLimitRestriction::Unlimited), _) | (_, Some(RateLimitRestriction::Unlimited)) => {
|
||||
Some(RateLimitRestriction::Unlimited)
|
||||
}
|
||||
(Some(RateLimitRestriction::Limited(left)), Some(RateLimitRestriction::Limited(right))) => {
|
||||
Some(RateLimitRestriction::Limited(left.max(right)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn rate_limit_policy_value(policy: Option<RateLimitRestriction>) -> Option<i32> {
|
||||
match policy {
|
||||
None => None,
|
||||
@@ -2358,35 +2374,44 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rate_limit_policy_uses_most_restrictive_custom_limit() {
|
||||
let groups = vec![sample_group(
|
||||
"restricted",
|
||||
10,
|
||||
None,
|
||||
"unrestricted",
|
||||
Some(60),
|
||||
"custom",
|
||||
)];
|
||||
fn rate_limit_policy_uses_highest_group_limit_before_user_restriction() {
|
||||
let groups = vec![
|
||||
sample_group("default", 10, None, "unrestricted", Some(30), "custom"),
|
||||
sample_group("tier-1", 20, None, "unrestricted", Some(100), "custom"),
|
||||
];
|
||||
|
||||
assert_eq!(
|
||||
resolve_effective_rate_limit_policy(Some(120), "custom", &groups),
|
||||
Some(60)
|
||||
Some(100)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rate_limit_unlimited_does_not_bypass_limited_group() {
|
||||
fn rate_limit_unlimited_group_overrides_limited_groups() {
|
||||
let groups = vec![
|
||||
sample_group("default", 10, None, "unrestricted", Some(30), "custom"),
|
||||
sample_group("tier-2", 20, None, "unrestricted", Some(0), "custom"),
|
||||
];
|
||||
|
||||
assert_eq!(
|
||||
resolve_effective_rate_limit_policy(None, "system", &groups),
|
||||
Some(0)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rate_limit_user_policy_still_restricts_group_grants() {
|
||||
let groups = vec![sample_group(
|
||||
"restricted",
|
||||
"tier-1",
|
||||
10,
|
||||
None,
|
||||
"unrestricted",
|
||||
Some(60),
|
||||
Some(100),
|
||||
"custom",
|
||||
)];
|
||||
|
||||
assert_eq!(
|
||||
resolve_effective_rate_limit_policy(Some(0), "custom", &groups),
|
||||
resolve_effective_rate_limit_policy(Some(60), "custom", &groups),
|
||||
Some(60)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user