group tests #23
33
src/proto.rs
33
src/proto.rs
@ -229,10 +229,13 @@ pub enum DNSParseError {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use super::*;
|
mod from_udp_datagram {
|
||||||
|
|
||||||
|
mod header_length {
|
||||||
|
use super::super::super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_dns_header_too_short() {
|
fn too_short() {
|
||||||
// minimal header with 1 byte missing
|
// minimal header with 1 byte missing
|
||||||
let dns_query = [
|
let dns_query = [
|
||||||
0x13, 0x37, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0x13, 0x37, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
@ -240,9 +243,13 @@ mod tests {
|
|||||||
let parse_result = DNSHeader::from_udp_datagram(&dns_query);
|
let parse_result = DNSHeader::from_udp_datagram(&dns_query);
|
||||||
assert_eq!(parse_result.err().unwrap(), DNSParseError::DatagramTooShort);
|
assert_eq!(parse_result.err().unwrap(), DNSParseError::DatagramTooShort);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod opcode {
|
||||||
|
use super::super::super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_dns_header_opcode_invalid() {
|
fn invalid() {
|
||||||
let mut dns_query = [
|
let mut dns_query = [
|
||||||
0xff, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0xff, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
];
|
];
|
||||||
@ -262,7 +269,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_dns_header_opcode_valid() -> Result<(), DNSParseError> {
|
fn valid() -> Result<(), DNSParseError> {
|
||||||
let mut dns_query = [
|
let mut dns_query = [
|
||||||
0xff, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0xff, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
];
|
];
|
||||||
@ -285,9 +292,13 @@ mod tests {
|
|||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod message_type {
|
||||||
|
use super::super::super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_dns_header_message_type_query() -> Result<(), DNSParseError> {
|
fn query() -> Result<(), DNSParseError> {
|
||||||
let dns_query = [
|
let dns_query = [
|
||||||
0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
];
|
];
|
||||||
@ -297,7 +308,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_dns_header_message_type_response() -> Result<(), DNSParseError> {
|
fn response() -> Result<(), DNSParseError> {
|
||||||
let dns_query = [
|
let dns_query = [
|
||||||
0xff, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0xff, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
];
|
];
|
||||||
@ -305,9 +316,13 @@ mod tests {
|
|||||||
assert_eq!(parse_result?.message_type, DNSMessageType::Response);
|
assert_eq!(parse_result?.message_type, DNSMessageType::Response);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod response_code {
|
||||||
|
use super::super::super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_dns_header_response_code_invalid() {
|
fn invalid() {
|
||||||
let mut dns_query = [
|
let mut dns_query = [
|
||||||
0xff, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0xff, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
];
|
];
|
||||||
@ -329,7 +344,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_dns_header_response_code_valid() -> Result<(), DNSParseError> {
|
fn valid() -> Result<(), DNSParseError> {
|
||||||
let mut dns_query = [
|
let mut dns_query = [
|
||||||
0xff, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0xff, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
];
|
];
|
||||||
@ -361,3 +376,5 @@ mod tests {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user