|
@@ -89,3 +89,72 @@ impl Wire for NAPTR {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+#[cfg(test)]
|
|
|
+mod test {
|
|
|
+ use super::*;
|
|
|
+ use pretty_assertions::assert_eq;
|
|
|
+
|
|
|
+ #[test]
|
|
|
+ fn parses() {
|
|
|
+ let buf = &[
|
|
|
+ 0x00, 0x05, // order
|
|
|
+ 0x00, 0x0a, // preference
|
|
|
+ 0x01, // flags length
|
|
|
+ 0x73, // flags
|
|
|
+ 0x03, // service length
|
|
|
+ 0x53, 0x52, 0x56, // service
|
|
|
+ 0x0e, // regex length
|
|
|
+ 0x5c, 0x64, 0x5c, 0x64, 0x3a, 0x5c, 0x64, 0x5c, 0x64, 0x3a, 0x5c,
|
|
|
+ 0x64, 0x5c, 0x64, // regex
|
|
|
+ 0x0b, 0x73, 0x72, 0x76, 0x2d, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c,
|
|
|
+ 0x65, 0x06, 0x6c, 0x6f, 0x6f, 0x6b, 0x75, 0x70, 0x03, 0x64, 0x6f,
|
|
|
+ 0x67, 0x00, // replacement
|
|
|
+ ];
|
|
|
+
|
|
|
+ assert_eq!(NAPTR::read(buf.len() as _, &mut Cursor::new(buf)).unwrap(),
|
|
|
+ NAPTR {
|
|
|
+ order: 5,
|
|
|
+ preference: 10,
|
|
|
+ flags: "s".into(),
|
|
|
+ service: "SRV".into(),
|
|
|
+ regex: "\\d\\d:\\d\\d:\\d\\d".into(),
|
|
|
+ replacement: Labels::encode("srv-example.lookup.dog").unwrap(),
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ #[test]
|
|
|
+ fn incorrect_length() {
|
|
|
+ let buf = &[
|
|
|
+ 0x00, 0x05, // order
|
|
|
+ 0x00, 0x0a, // preference
|
|
|
+ 0x01, // flags length
|
|
|
+ 0x73, // flags
|
|
|
+ 0x03, // service length
|
|
|
+ 0x53, 0x52, 0x56, // service
|
|
|
+ 0x01, // regex length
|
|
|
+ 0x64, // regex,
|
|
|
+ 0x00, // replacement
|
|
|
+ ];
|
|
|
+
|
|
|
+ assert_eq!(NAPTR::read(11, &mut Cursor::new(buf)),
|
|
|
+ Err(WireError::WrongLabelLength { stated_length: 11, length_after_labels: 13 }));
|
|
|
+ }
|
|
|
+
|
|
|
+ #[test]
|
|
|
+ fn record_empty() {
|
|
|
+ assert_eq!(NAPTR::read(0, &mut Cursor::new(&[])),
|
|
|
+ Err(WireError::IO));
|
|
|
+ }
|
|
|
+
|
|
|
+ #[test]
|
|
|
+ fn buffer_ends_abruptly() {
|
|
|
+ let buf = &[
|
|
|
+ 0x00, 0x0A, // order
|
|
|
+ ];
|
|
|
+
|
|
|
+ assert_eq!(NAPTR::read(23, &mut Cursor::new(buf)),
|
|
|
+ Err(WireError::IO));
|
|
|
+ }
|
|
|
+}
|