Disallow apostrophies in mail addresses that we push to HRZ

This commit is contained in:
Gonne 2025-03-30 09:35:09 +02:00
parent daf3a05b4e
commit e08af81f77
Signed by: Gonne
SSH key fingerprint: SHA256:J8w3ZCNyz9MoTLV+eU7YRTVw59NYig44i0IWhbsgQG8
2 changed files with 18 additions and 2 deletions

View file

@ -12,7 +12,7 @@ pub struct AliasFile {
pub default_domain: FQDN,
}
#[derive(PartialEq, Eq, Clone)]
#[derive(PartialEq, Eq, Clone, Debug)]
pub struct OrdEmailAddress(EmailAddress);
impl PartialOrd for OrdEmailAddress {
@ -48,6 +48,11 @@ pub fn parse_alias_to_map(alias_files: Vec<AliasFile>) -> Result<AliasMap, Box<d
continue;
}
if destination.contains('\'') {
return Err(format!("Mailaddress {destination} contains an apostrophe which is not allowed by HRZ.")
.into());
}
let redirects: Vec<OrdEmailAddress> = line
.split_at(line.find(char::is_whitespace).unwrap_or(0))
.1
@ -95,7 +100,7 @@ pub fn parse_alias_to_map(alias_files: Vec<AliasFile>) -> Result<AliasMap, Box<d
}
}
if iterations == max_iterations {
return Err(String::from("Possibly infinite recursion detected in parse_alias_map. Did not terminate after {max_iterations} rounds.").into());
return Err(format!("Possibly infinite recursion detected in parse_alias_map. Did not terminate after {max_iterations} rounds.").into());
}
Ok(redirect_map)
}
@ -190,6 +195,15 @@ mod tests {
assert!(result.is_err());
}
#[test]
fn apostrophe_detection() {
let result = parse_alias_to_map(vec![AliasFile {
content: read_lines("testdata/apostrophe.aliases").unwrap(),
default_domain: FQDN::from_str("example.com").unwrap(),
}]);
assert!(result.is_err());
}
#[test]
fn basic_parsing() {
let result = parse_alias_to_map(vec![AliasFile {

View file

@ -0,0 +1,2 @@
# Apostrophes are not allowed by HRZ
'orga me@example.com