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 44c7291390
Signed by: Gonne
SSH key fingerprint: SHA256:J8w3ZCNyz9MoTLV+eU7YRTVw59NYig44i0IWhbsgQG8
2 changed files with 19 additions and 1 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,13 @@ pub fn parse_alias_to_map(alias_files: Vec<AliasFile>) -> Result<AliasMap, Box<d
continue;
}
if destination.contains('\'') {
return Err(String::from(
"Mailaddress {addr} 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
@ -190,6 +197,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