From fc9b4c8e0d5e17156e5792bc4f9777b7c9f50469 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Sun, 19 Jul 2020 14:27:50 +0200 Subject: [PATCH] aquatic_http: protocol: add test for scrape request parsing --- TODO.md | 3 ++- aquatic_http/src/lib/protocol/request.rs | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/TODO.md b/TODO.md index 2610c45..3d9ba62 100644 --- a/TODO.md +++ b/TODO.md @@ -10,7 +10,8 @@ ## aquatic_http * request parsing: - * add test of scrape request parsing with multiple info hashes + * test multiple scrape hashes + * test with strange/bad inputs, with and without quickcheck * test torrent transfer with real clients * test tls * current serialized byte strings valid diff --git a/aquatic_http/src/lib/protocol/request.rs b/aquatic_http/src/lib/protocol/request.rs index 793fd73..d3d3137 100644 --- a/aquatic_http/src/lib/protocol/request.rs +++ b/aquatic_http/src/lib/protocol/request.rs @@ -278,6 +278,7 @@ mod tests { use super::*; static ANNOUNCE_REQUEST_PATH: &str = "/announce?info_hash=%04%0bkV%3f%5cr%14%a6%b7%98%adC%c3%c9.%40%24%00%b9&peer_id=-ABC940-5ert69muw5t8&port=12345&uploaded=0&downloaded=0&left=1&numwant=0&key=4ab4b877&compact=1&supportcrypto=1&event=started"; + static SCRAPE_REQUEST_PATH: &str = "/scrape?info_hash=%04%0bkV%3f%5cr%14%a6%b7%98%adC%c3%c9.%40%24%00%b9"; static REFERENCE_INFO_HASH: [u8; 20] = [0x04, 0x0b, b'k', b'V', 0x3f, 0x5c, b'r', 0x14, 0xa6, 0xb7, 0x98, 0xad, b'C', 0xc3, 0xc9, b'.', 0x40, 0x24, 0x00, 0xb9]; static REFERENCE_PEER_ID: [u8; 20] = [b'-', b'A', b'B', b'C', b'9', b'4', b'0', b'-', b'5', b'e', b'r', b't', b'6', b'9', b'm', b'u', b'w', b'5', b't', b'8']; @@ -313,4 +314,17 @@ mod tests { assert_eq!(parsed_request, reference_request); } + + #[test] + fn test_scrape_request_from_path(){ + let parsed_request = Request::from_http_get_path( + SCRAPE_REQUEST_PATH + ).unwrap(); + + let reference_request = Request::Scrape(ScrapeRequest { + info_hashes: vec![InfoHash(REFERENCE_INFO_HASH)], + }); + + assert_eq!(parsed_request, reference_request); + } } \ No newline at end of file