Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add another test around a DNS Name edge case #187

Merged
merged 1 commit into from
Aug 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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