Skip to content

Commit

Permalink
Merge pull request #187 from 56quarters/name-test
Browse files Browse the repository at this point in the history
Add another test around a DNS Name edge case
  • Loading branch information
56quarters authored Aug 24, 2024
2 parents 5faf1b9 + 91cd06d commit efc9725
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions mtop-client/src/dns/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl Name {
}

pub fn size(&self) -> usize {
(self.labels.iter().map(|l| l.len()).sum::<usize>() + self.labels.len()) + 1
self.labels.iter().map(|l| l.len()).sum::<usize>() + self.labels.len() + 1
}

pub fn is_root(&self) -> bool {
Expand Down Expand Up @@ -98,10 +98,7 @@ impl Name {
} else {
// Binary labels are deprecated (RFC 6891) and there are (currently) no other
// types of labels that we should expect. Return an error to make this obvious.
return Err(MtopError::runtime(format!(
"unsupported Name label type found: {}",
len
)));
return Err(MtopError::runtime(format!("unsupported Name label type: {}", len)));
}
}

Expand Down Expand Up @@ -454,6 +451,21 @@ mod test {
assert_eq!(13, name.size());
}

#[test]
fn test_name_size_non_root_fqdn() {
let name = Name::from_str("example.com").unwrap();
assert!(!name.is_fqdn());
assert_eq!(13, name.size());

// The purpose of the .size() method is to figure out how many bytes this
// name would be when serialized to binary message format. Only FQDN can be
// serialized so we expect the size to be the same between the non-FQDN and
// FQDN version of this name.
let name = name.to_fqdn();
assert!(name.is_fqdn());
assert_eq!(13, name.size());
}

#[test]
fn test_name_write_network_bytes_root() {
let mut cur = Cursor::new(Vec::new());
Expand Down

0 comments on commit efc9725

Please sign in to comment.