Move HTTP tests into a module

This commit is contained in:
_Frky 2021-12-16 22:25:31 +01:00
parent dfb4707577
commit c116c7bfdb

View file

@ -267,8 +267,12 @@ WWW-Authenticate: Basic realm=\"Access to admin page\"
Some(repl_data) Some(repl_data)
} }
#[test] #[cfg(test)]
fn test_http_verb() { mod tests {
use super::*;
#[test]
fn test_http_verb() {
/* all at once */ /* all at once */
for verb in HTTP_VERBS.iter() { for verb in HTTP_VERBS.iter() {
let mut pstate = ProtocolState::new(); let mut pstate = ProtocolState::new();
@ -333,10 +337,10 @@ fn test_http_verb() {
assert!(pstate.state == HTTP_STATE_FAIL); assert!(pstate.state == HTTP_STATE_FAIL);
assert!(pstate.smack_state == UNANCHORED_STATE); assert!(pstate.smack_state == UNANCHORED_STATE);
assert!(pstate.smack_id == NO_MATCH); assert!(pstate.smack_id == NO_MATCH);
} }
#[test] #[test]
fn test_http_request_line() { fn test_http_request_line() {
let mut pstate = ProtocolState::new(); let mut pstate = ProtocolState::new();
let data = "GET /index.php HTTP/1.1\r\n".as_bytes(); let data = "GET /index.php HTTP/1.1\r\n".as_bytes();
for i in 0..data.len() { for i in 0..data.len() {
@ -357,10 +361,10 @@ fn test_http_request_line() {
assert!(pstate.state == HTTP_STATE_FIELD_START); assert!(pstate.state == HTTP_STATE_FIELD_START);
} }
} }
} }
#[test] #[test]
fn test_http_request_field() { fn test_http_request_field() {
let mut pstate = ProtocolState::new(); let mut pstate = ProtocolState::new();
let req = "POST /index.php HTTP/2.0\r\n".as_bytes(); let req = "POST /index.php HTTP/2.0\r\n".as_bytes();
http_parse(&mut pstate, req); http_parse(&mut pstate, req);
@ -374,10 +378,10 @@ fn test_http_request_field() {
let value = b": 0\r\n"; let value = b": 0\r\n";
http_parse(&mut pstate, value); http_parse(&mut pstate, value);
assert!(pstate.state == HTTP_STATE_FIELD_START); assert!(pstate.state == HTTP_STATE_FIELD_START);
} }
#[test] #[test]
fn test_http_request_no_field() { fn test_http_request_no_field() {
let mut pstate = ProtocolState::new(); let mut pstate = ProtocolState::new();
let req = "POST /index.php HTTP/2.0\r\n".as_bytes(); let req = "POST /index.php HTTP/2.0\r\n".as_bytes();
http_parse(&mut pstate, req); http_parse(&mut pstate, req);
@ -385,4 +389,5 @@ fn test_http_request_no_field() {
let crlf = "\r\n".as_bytes(); let crlf = "\r\n".as_bytes();
http_parse(&mut pstate, crlf); http_parse(&mut pstate, crlf);
assert!(pstate.state == HTTP_STATE_CONTENT); assert!(pstate.state == HTTP_STATE_CONTENT);
}
} }