mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-20 11:32:19 +00:00
fix(notify): accept case-insensitive filter rule names (#2990)
This commit is contained in:
@@ -161,6 +161,39 @@ mod integration_tests {
|
||||
assert!(targets.is_empty(), "Files not in images/ should not match");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_capitalized_filter_names_xml() {
|
||||
let xml = r#"<?xml version="1.0" encoding="UTF-8"?>
|
||||
<NotificationConfiguration>
|
||||
<QueueConfiguration>
|
||||
<Id>test-queue</Id>
|
||||
<Queue>arn:rustfs:sqs:ap-northeast-1:primary:webhook</Queue>
|
||||
<Event>s3:ObjectCreated:*</Event>
|
||||
<Filter>
|
||||
<S3Key>
|
||||
<FilterRule>
|
||||
<Name>Prefix</Name>
|
||||
<Value>uploads/</Value>
|
||||
</FilterRule>
|
||||
<FilterRule>
|
||||
<Name>Suffix</Name>
|
||||
<Value>.csv</Value>
|
||||
</FilterRule>
|
||||
</S3Key>
|
||||
</Filter>
|
||||
</QueueConfiguration>
|
||||
</NotificationConfiguration>"#;
|
||||
|
||||
let current_region = "ap-northeast-1";
|
||||
let arn_list = vec!["arn:rustfs:sqs:ap-northeast-1:primary:webhook".to_string()];
|
||||
|
||||
let config = BucketNotificationConfig::from_xml(Cursor::new(xml.as_bytes()), current_region, &arn_list).unwrap();
|
||||
let rules_map = config.get_rules_map();
|
||||
|
||||
let targets = rules_map.match_rules(EventName::ObjectCreatedPut, "uploads/report.csv");
|
||||
assert!(!targets.is_empty(), "capitalized filter names should still build prefix/suffix rules");
|
||||
}
|
||||
|
||||
/// Test suffix only filter
|
||||
#[test]
|
||||
fn test_suffix_only_filter_xml() {
|
||||
|
||||
@@ -66,7 +66,7 @@ pub struct FilterRule {
|
||||
|
||||
impl FilterRule {
|
||||
fn validate(&self) -> Result<(), ParseConfigError> {
|
||||
if self.name != "prefix" && self.name != "suffix" {
|
||||
if !self.name.eq_ignore_ascii_case("prefix") && !self.name.eq_ignore_ascii_case("suffix") {
|
||||
return Err(ParseConfigError::InvalidFilterName(self.name.clone()));
|
||||
}
|
||||
// ValidateFilterRuleValue from Go:
|
||||
@@ -98,12 +98,12 @@ impl S3KeyFilter {
|
||||
let mut has_suffix = false;
|
||||
for rule in &self.filter_rule_list {
|
||||
rule.validate()?;
|
||||
if rule.name == "prefix" {
|
||||
if rule.name.eq_ignore_ascii_case("prefix") {
|
||||
if has_prefix {
|
||||
return Err(ParseConfigError::DuplicatePrefixFilter);
|
||||
}
|
||||
has_prefix = true;
|
||||
} else if rule.name == "suffix" {
|
||||
} else if rule.name.eq_ignore_ascii_case("suffix") {
|
||||
if has_suffix {
|
||||
return Err(ParseConfigError::DuplicateSuffixFilter);
|
||||
}
|
||||
@@ -126,9 +126,9 @@ impl S3KeyFilter {
|
||||
let mut suffix_val: Option<&str> = None;
|
||||
|
||||
for rule in &self.filter_rule_list {
|
||||
if rule.name == "prefix" {
|
||||
if rule.name.eq_ignore_ascii_case("prefix") {
|
||||
prefix_val = Some(&rule.value);
|
||||
} else if rule.name == "suffix" {
|
||||
} else if rule.name.eq_ignore_ascii_case("suffix") {
|
||||
suffix_val = Some(&rule.value);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user