forked from Fachschaft/nixConfig
Disallow apostrophies in mail addresses that we push to HRZ
This commit is contained in:
parent
daf3a05b4e
commit
e08af81f77
2 changed files with 18 additions and 2 deletions
|
@ -12,7 +12,7 @@ pub struct AliasFile {
|
||||||
pub default_domain: FQDN,
|
pub default_domain: FQDN,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Clone)]
|
#[derive(PartialEq, Eq, Clone, Debug)]
|
||||||
pub struct OrdEmailAddress(EmailAddress);
|
pub struct OrdEmailAddress(EmailAddress);
|
||||||
|
|
||||||
impl PartialOrd for OrdEmailAddress {
|
impl PartialOrd for OrdEmailAddress {
|
||||||
|
@ -48,6 +48,11 @@ pub fn parse_alias_to_map(alias_files: Vec<AliasFile>) -> Result<AliasMap, Box<d
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if destination.contains('\'') {
|
||||||
|
return Err(format!("Mailaddress {destination} contains an apostrophe which is not allowed by HRZ.")
|
||||||
|
.into());
|
||||||
|
}
|
||||||
|
|
||||||
let redirects: Vec<OrdEmailAddress> = line
|
let redirects: Vec<OrdEmailAddress> = line
|
||||||
.split_at(line.find(char::is_whitespace).unwrap_or(0))
|
.split_at(line.find(char::is_whitespace).unwrap_or(0))
|
||||||
.1
|
.1
|
||||||
|
@ -95,7 +100,7 @@ pub fn parse_alias_to_map(alias_files: Vec<AliasFile>) -> Result<AliasMap, Box<d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if iterations == max_iterations {
|
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)
|
Ok(redirect_map)
|
||||||
}
|
}
|
||||||
|
@ -190,6 +195,15 @@ mod tests {
|
||||||
assert!(result.is_err());
|
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]
|
#[test]
|
||||||
fn basic_parsing() {
|
fn basic_parsing() {
|
||||||
let result = parse_alias_to_map(vec![AliasFile {
|
let result = parse_alias_to_map(vec![AliasFile {
|
||||||
|
|
2
packages/alias-to-sieve/testdata/apostrophe.aliases
vendored
Normal file
2
packages/alias-to-sieve/testdata/apostrophe.aliases
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
# Apostrophes are not allowed by HRZ
|
||||||
|
'orga me@example.com
|
Loading…
Add table
Reference in a new issue