@@ -6,7 +6,7 @@ use super::responses::announce::{Announce, Compact, DeserializedCompact};
66use super :: responses:: scrape;
77use crate :: http:: responses:: error:: Error ;
88
9- pub fn assert_error_bencoded ( response_text : & String , expected_failure_reason : & str , location : & ' static Location < ' static > ) {
9+ pub fn assert_bencoded_error ( response_text : & String , expected_failure_reason : & str , location : & ' static Location < ' static > ) {
1010 let error_failure_reason = serde_bencode:: from_str :: < Error > ( response_text)
1111 . unwrap_or_else ( |_| panic ! (
1212 "response body should be a valid bencoded string for the '{expected_failure_reason}' error, got \" {response_text}\" "
@@ -18,7 +18,7 @@ pub fn assert_error_bencoded(response_text: &String, expected_failure_reason: &s
1818 error_failure_reason. contains( expected_failure_reason) ,
1919 r#":
2020 response: `"{error_failure_reason}"`
21- dose not contain: `"{expected_failure_reason}"`, {location}"#
21+ does not contain: `"{expected_failure_reason}"`, {location}"#
2222 ) ;
2323}
2424
@@ -83,13 +83,13 @@ pub async fn assert_is_announce_response(response: Response) {
8383pub async fn assert_internal_server_error_response ( response : Response ) {
8484 assert_eq ! ( response. status( ) , 200 ) ;
8585
86- assert_error_bencoded ( & response. text ( ) . await . unwrap ( ) , "internal server" , Location :: caller ( ) ) ;
86+ assert_bencoded_error ( & response. text ( ) . await . unwrap ( ) , "internal server" , Location :: caller ( ) ) ;
8787}
8888
8989pub async fn assert_invalid_info_hash_error_response ( response : Response ) {
9090 assert_eq ! ( response. status( ) , 200 ) ;
9191
92- assert_error_bencoded (
92+ assert_bencoded_error (
9393 & response. text ( ) . await . unwrap ( ) ,
9494 "no valid infohashes found" ,
9595 Location :: caller ( ) ,
@@ -99,7 +99,7 @@ pub async fn assert_invalid_info_hash_error_response(response: Response) {
9999pub async fn assert_invalid_peer_id_error_response ( response : Response ) {
100100 assert_eq ! ( response. status( ) , 200 ) ;
101101
102- assert_error_bencoded (
102+ assert_bencoded_error (
103103 & response. text ( ) . await . unwrap ( ) ,
104104 "peer_id is either missing or invalid" ,
105105 Location :: caller ( ) ,
@@ -109,13 +109,13 @@ pub async fn assert_invalid_peer_id_error_response(response: Response) {
109109pub async fn assert_torrent_not_in_whitelist_error_response ( response : Response ) {
110110 assert_eq ! ( response. status( ) , 200 ) ;
111111
112- assert_error_bencoded ( & response. text ( ) . await . unwrap ( ) , "is not whitelisted" , Location :: caller ( ) ) ;
112+ assert_bencoded_error ( & response. text ( ) . await . unwrap ( ) , "is not whitelisted" , Location :: caller ( ) ) ;
113113}
114114
115115pub async fn assert_peer_not_authenticated_error_response ( response : Response ) {
116116 assert_eq ! ( response. status( ) , 200 ) ;
117117
118- assert_error_bencoded (
118+ assert_bencoded_error (
119119 & response. text ( ) . await . unwrap ( ) ,
120120 "The peer is not authenticated" ,
121121 Location :: caller ( ) ,
@@ -125,13 +125,13 @@ pub async fn assert_peer_not_authenticated_error_response(response: Response) {
125125pub async fn assert_invalid_authentication_key_error_response ( response : Response ) {
126126 assert_eq ! ( response. status( ) , 200 ) ;
127127
128- assert_error_bencoded ( & response. text ( ) . await . unwrap ( ) , "is not valid" , Location :: caller ( ) ) ;
128+ assert_bencoded_error ( & response. text ( ) . await . unwrap ( ) , "is not valid" , Location :: caller ( ) ) ;
129129}
130130
131131pub async fn assert_could_not_find_remote_address_on_xff_header_error_response ( response : Response ) {
132132 assert_eq ! ( response. status( ) , 200 ) ;
133133
134- assert_error_bencoded (
134+ assert_bencoded_error (
135135 & response. text ( ) . await . unwrap ( ) ,
136136 "could not find remote address: must have a x-forwarded-for when using a reverse proxy" ,
137137 Location :: caller ( ) ,
@@ -141,9 +141,51 @@ pub async fn assert_could_not_find_remote_address_on_xff_header_error_response(r
141141pub async fn assert_invalid_remote_address_on_xff_header_error_response ( response : Response ) {
142142 assert_eq ! ( response. status( ) , 200 ) ;
143143
144- assert_error_bencoded (
144+ assert_bencoded_error (
145145 & response. text ( ) . await . unwrap ( ) ,
146146 "could not find remote address: on remote proxy and unable to parse the last x-forwarded-ip" ,
147147 Location :: caller ( ) ,
148148 ) ;
149149}
150+
151+ // Specific errors for announce requests
152+
153+ pub async fn assert_missing_query_params_for_announce_request_error_response ( response : Response ) {
154+ assert_eq ! ( response. status( ) , 200 ) ;
155+
156+ assert_bencoded_error (
157+ & response. text ( ) . await . unwrap ( ) ,
158+ "missing query params for announce request" ,
159+ Location :: caller ( ) ,
160+ ) ;
161+ }
162+
163+ pub async fn assert_cannot_parse_query_param_error_response ( response : Response , failure : & str ) {
164+ assert_eq ! ( response. status( ) , 200 ) ;
165+
166+ assert_bencoded_error (
167+ & response. text ( ) . await . unwrap ( ) ,
168+ & format ! ( "Cannot parse query params: {failure}" ) ,
169+ Location :: caller ( ) ,
170+ ) ;
171+ }
172+
173+ pub async fn assert_cannot_parse_query_params_error_response ( response : Response ) {
174+ assert_eq ! ( response. status( ) , 200 ) ;
175+
176+ assert_bencoded_error (
177+ & response. text ( ) . await . unwrap ( ) ,
178+ "Cannot parse query params" ,
179+ Location :: caller ( ) ,
180+ ) ;
181+ }
182+
183+ pub async fn assert_bad_announce_request_error_response ( response : Response , failure : & str ) {
184+ assert_eq ! ( response. status( ) , 200 ) ;
185+
186+ assert_bencoded_error (
187+ & response. text ( ) . await . unwrap ( ) ,
188+ & format ! ( "Cannot parse query params for announce request: {failure}" ) ,
189+ Location :: caller ( ) ,
190+ ) ;
191+ }
0 commit comments