|
1 | 1 | use std::{error::Error, process::exit, time::Duration}; |
2 | 2 |
|
3 | 3 | use colored::Colorize; |
4 | | -use differ::{Differ, Tag}; |
5 | 4 | use governor::{Quota, RateLimiter}; |
6 | 5 | use indicatif::ProgressBar; |
7 | 6 | use itertools::iproduct; |
8 | 7 | use regex::Regex; |
9 | 8 | use reqwest::{redirect, Proxy}; |
10 | 9 | use tokio::{fs::File, io::AsyncWriteExt, sync::mpsc}; |
11 | 10 |
|
12 | | -use crate::utils; |
13 | | - |
14 | 11 | // the Job struct which will be used to define our settings for the detection jobs |
15 | 12 | #[derive(Clone, Debug)] |
16 | 13 | pub struct JobSettings { |
@@ -149,7 +146,6 @@ pub async fn run_tester( |
149 | 146 | let new_url = String::from(&job_url); |
150 | 147 | let mut track_status_codes = 0; |
151 | 148 | for _ in 0..path_cnt { |
152 | | - let job_url_without_path = job_url_without_path.clone(); |
153 | 149 | let mut new_url = new_url.clone(); |
154 | 150 | if !new_url.as_str().ends_with("/") { |
155 | 151 | new_url.push_str("/"); |
@@ -195,19 +191,6 @@ pub async fn run_tester( |
195 | 191 | continue; |
196 | 192 | } |
197 | 193 | }; |
198 | | - let pub_get = client.get(job_url_without_path); |
199 | | - let pub_req = match pub_get.build() { |
200 | | - Ok(pub_req) => pub_req, |
201 | | - Err(_) => { |
202 | | - continue; |
203 | | - } |
204 | | - }; |
205 | | - let pub_resp = match client.execute(pub_req).await { |
206 | | - Ok(pub_resp) => pub_resp, |
207 | | - Err(_) => { |
208 | | - continue; |
209 | | - } |
210 | | - }; |
211 | 194 |
|
212 | 195 | let content_length = match resp.content_length() { |
213 | 196 | Some(content_length) => content_length.to_string(), |
@@ -251,38 +234,8 @@ pub async fn run_tester( |
251 | 234 | } |
252 | 235 | }; |
253 | 236 |
|
254 | | - let internal_get = client.get(backonemore); |
255 | | - |
256 | | - let internal_req = match internal_get.build() { |
257 | | - Ok(internal_req) => internal_req, |
258 | | - Err(_) => { |
259 | | - continue; |
260 | | - } |
261 | | - }; |
262 | | - let internal_resp = match client.execute(internal_req).await { |
263 | | - Ok(internal_resp) => internal_resp, |
264 | | - Err(_) => { |
265 | | - continue; |
266 | | - } |
267 | | - }; |
268 | | - |
269 | | - let internal_cl = match internal_resp.text().await { |
270 | | - Ok(internal_cl) => internal_cl, |
271 | | - Err(_) => continue, |
272 | | - }; |
273 | | - |
274 | | - let public_cl = match pub_resp.text().await { |
275 | | - Ok(public_cl) => public_cl, |
276 | | - Err(_) => continue, |
277 | | - }; |
278 | | - |
279 | 237 | // we hit the internal doc root. |
280 | | - let (ok, distance_between_responses) = |
281 | | - utils::get_response_change(&internal_cl, &public_cl); |
282 | | - if response.status().as_str() != "400" |
283 | | - && ok |
284 | | - && result_url.contains(&job_payload_new) |
285 | | - { |
| 238 | + if response.status().as_str() != "400" && result_url.contains(&job_payload_new) { |
286 | 239 | // track the status codes |
287 | 240 | if job_settings.drop_after_fail == response.status().as_str() { |
288 | 241 | track_status_codes += 1; |
@@ -314,41 +267,9 @@ pub async fn run_tester( |
314 | 267 | }, |
315 | 268 | None => "Unknown", |
316 | 269 | }; |
317 | | - |
318 | | - let internal_resp_text_lines = internal_cl.lines().collect::<Vec<_>>(); |
319 | | - let public_resp_text_lines = public_cl.lines().collect::<Vec<_>>(); |
320 | | - let character_differences = |
321 | | - Differ::new(&public_resp_text_lines, &internal_resp_text_lines); |
322 | | - if character_differences.spans().len() > 0 { |
323 | | - pb.println(format!( |
324 | | - "\n{}{}{} {}", |
325 | | - "(".bold().white(), |
326 | | - "*".bold().blue(), |
327 | | - ")".bold().white(), |
328 | | - "found some response changes:".bold().green(), |
329 | | - )); |
330 | | - for span in character_differences.spans() { |
331 | | - match span.tag { |
332 | | - Tag::Equal => (), // ignore |
333 | | - Tag::Insert => (), // ignore |
334 | | - Tag::Delete => (), // ignore |
335 | | - Tag::Replace => { |
336 | | - for line in &internal_resp_text_lines[span.b_start..span.b_end] |
337 | | - { |
338 | | - if line.to_string() == "" { |
339 | | - pb.println(format!("\n{}", line.bold().white(),)); |
340 | | - } else { |
341 | | - pb.println(format!("{}", line.bold().white(),)); |
342 | | - } |
343 | | - } |
344 | | - } |
345 | | - } |
346 | | - } |
347 | | - } |
348 | | - pb.println(format!("\n")); |
349 | 270 | if response.status().is_client_error() { |
350 | 271 | pb.println(format!( |
351 | | - "{}{}{} {}{}{}\n{}{}{} {}\n\t {} {}{}{}\n\t {} {}{}{}\n\t {} {}{}{}\n\t {} {}{}{}\n\t {} {}{}{}\n\t {} {}{}{}\n\t", |
| 272 | + "{}{}{} {}{}{}\n{}{}{} {}\n\t {} {}{}{}\n\t {} {}{}{}\n\t {} {}{}{}\n\t {} {}{}{}\n\t {} {}{}{}\n\t", |
352 | 273 | "[".bold().white(), |
353 | 274 | "OK".bold().green(), |
354 | 275 | "]".bold().white(), |
@@ -379,15 +300,11 @@ pub async fn run_tester( |
379 | 300 | "[".bold().white(), |
380 | 301 | title.bold().purple(), |
381 | 302 | "]".bold().white(), |
382 | | - "deviation:".bold().white(), |
383 | | - "[".bold().white(), |
384 | | - distance_between_responses.to_string().bold().purple(), |
385 | | - "]".bold().white(), |
386 | 303 | )); |
387 | 304 | } |
388 | 305 | if response.status().is_success() { |
389 | 306 | pb.println(format!( |
390 | | - "{}{}{} {}{}{}\n{}{}{} {}\n\t {} {}{}{}\n\t {} {}{}{}\n\t {} {}{}{}\n\t {} {}{}{}\n\t {} {}{}{}\n\t {} {}{}{}\n\t", |
| 307 | + "{}{}{} {}{}{}\n{}{}{} {}\n\t {} {}{}{}\n\t {} {}{}{}\n\t {} {}{}{}\n\t {} {}{}{}\n\t {} {}{}{}\n\t", |
391 | 308 | "[".bold().white(), |
392 | 309 | "OK".bold().green(), |
393 | 310 | "]".bold().white(), |
@@ -418,15 +335,11 @@ pub async fn run_tester( |
418 | 335 | "[".bold().white(), |
419 | 336 | title.bold().purple(), |
420 | 337 | "]".bold().white(), |
421 | | - "deviation:".bold().white(), |
422 | | - "[".bold().white(), |
423 | | - distance_between_responses.to_string().bold().purple(), |
424 | | - "]".bold().white(), |
425 | 338 | )); |
426 | 339 | } |
427 | 340 | if response.status().is_redirection() { |
428 | 341 | pb.println(format!( |
429 | | - "{}{}{} {}{}{}\n{}{}{} {}\n\t {} {}{}{}\n\t {} {}{}{}\n\t {} {}{}{}\n\t {} {}{}{}\n\t {} {}{}{}\n\t {} {}{}{}\n\t", |
| 342 | + "{}{}{} {}{}{}\n{}{}{} {}\n\t {} {}{}{}\n\t {} {}{}{}\n\t {} {}{}{}\n\t {} {}{}{}\n\t {} {}{}{}\n\t", |
430 | 343 | "[".bold().white(), |
431 | 344 | "OK".bold().green(), |
432 | 345 | "]".bold().white(), |
@@ -457,15 +370,11 @@ pub async fn run_tester( |
457 | 370 | "[".bold().white(), |
458 | 371 | title.bold().purple(), |
459 | 372 | "]".bold().white(), |
460 | | - "deviation:".bold().white(), |
461 | | - "[".bold().white(), |
462 | | - distance_between_responses.to_string().bold().purple(), |
463 | | - "]".bold().white(), |
464 | 373 | )); |
465 | 374 | } |
466 | 375 | if response.status().is_server_error() { |
467 | 376 | pb.println(format!( |
468 | | - "{}{}{} {}{}{}\n{}{}{} {}\n\t {} {}{}{}\n\t {} {}{}{}\n\t {} {}{}{}\n\t {} {}{}{}\n\t {} {}{}{}\n\t {} {}{}{}\n\t", |
| 377 | + "{}{}{} {}{}{}\n{}{}{} {}\n\t {} {}{}{}\n\t {} {}{}{}\n\t {} {}{}{}\n\t {} {}{}{}\n\t {} {}{}{}\n\t", |
469 | 378 | "[".bold().white(), |
470 | 379 | "OK".bold().green(), |
471 | 380 | "]".bold().white(), |
@@ -496,15 +405,11 @@ pub async fn run_tester( |
496 | 405 | "[".bold().white(), |
497 | 406 | title.bold().purple(), |
498 | 407 | "]".bold().white(), |
499 | | - "deviation:".bold().white(), |
500 | | - "[".bold().white(), |
501 | | - distance_between_responses.to_string().bold().purple(), |
502 | | - "]".bold().white(), |
503 | 408 | )); |
504 | 409 | } |
505 | 410 | if response.status().is_informational() { |
506 | 411 | pb.println(format!( |
507 | | - "{}{}{} {}{}{}\n{}{}{} {}\n\t {} {}{}{}\n\t {} {}{}{}\n\t {} {}{}{}\n\t {} {}{}{}\n\t {} {}{}{}\n\t {} {}{}{}\n\t", |
| 412 | + "{}{}{} {}{}{}\n{}{}{} {}\n\t {} {}{}{}\n\t {} {}{}{}\n\t {} {}{}{}\n\t {} {}{}{}\n\t {} {}{}{}\n\t", |
508 | 413 | "[".bold().white(), |
509 | 414 | "OK".bold().green(), |
510 | 415 | "]".bold().white(), |
@@ -535,10 +440,6 @@ pub async fn run_tester( |
535 | 440 | "[".bold().white(), |
536 | 441 | title.bold().purple(), |
537 | 442 | "]".bold().white(), |
538 | | - "deviation:".bold().white(), |
539 | | - "[".bold().white(), |
540 | | - distance_between_responses.to_string().bold().purple(), |
541 | | - "]".bold().white(), |
542 | 443 | )); |
543 | 444 | } |
544 | 445 | // send the result message through the channel to the workers. |
|
0 commit comments