Skip to content

Commit

Permalink
fixed user agent based searchers, drastically speed up test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
QpxDesign committed Mar 8, 2024
1 parent a92ae6c commit a16b327
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 29 deletions.
55 changes: 30 additions & 25 deletions src/utils/keep_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,36 @@ pub fn keep_line(parsed_line: &LineParseResult, cm: bool) -> bool {
{
return false;
}
if ARGS.browser.is_some()
|| ARGS.device_category.is_some()
|| ARGS.os.is_some()
|| ARGS.bot.is_some()
{
let parsed_ua = parse_user_agent(parsed_line.user_agent);
if ARGS.browser.is_some()
&& parsed_ua.browser.to_lowercase()
!= ARGS.browser.as_ref().expect("WOOP").to_lowercase()
{
return false;
}
if ARGS.os.is_some()
&& parsed_ua.operating_system.to_lowercase()
!= ARGS.os.to_owned().expect("WOOP").to_lowercase()
{
return false;
}
if ARGS.device_category.is_some()
&& ARGS.device_category.as_ref().unwrap().as_str() != parsed_ua.category
{
return false;
}
if ARGS.bot.is_some() && ARGS.bot.unwrap() == false && parsed_ua.isBot == true {
return false;
}
if ARGS.bot.is_some() && ARGS.bot.unwrap() == true && parsed_ua.isBot == false {
return false;
}
}

if cm == false {
return true;
Expand Down Expand Up @@ -90,30 +120,5 @@ pub fn keep_line(parsed_line: &LineParseResult, cm: bool) -> bool {
return false;
}
}

let parsed_ua = parse_user_agent(parsed_line.user_agent);
if ARGS.browser.is_some()
&& parsed_ua.browser.to_lowercase() != ARGS.browser.as_ref().expect("WOOP").to_lowercase()
{
return false;
}
if ARGS.os.is_some()
&& parsed_ua.operating_system.to_lowercase()
!= ARGS.os.to_owned().expect("WOOP").to_lowercase()
{
return false;
}
if ARGS.device_category.is_some()
&& ARGS.device_category.as_ref().unwrap().as_str() != parsed_ua.category
{
return false;
}
if ARGS.bot.is_some() && ARGS.bot.unwrap() == false && parsed_ua.isBot == true {
return false;
}
if ARGS.bot.is_some() && ARGS.bot.unwrap() == true && parsed_ua.isBot == false {
return false;
}

return true;
}
32 changes: 28 additions & 4 deletions tests/test_cases.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ expect = "751"
[[test_cases]]
name = "EndDate"
run_type = "lines_count"
cmd = "../target/release/ngxav -f ../tests/logs/750k.log -e 21/Jan/2024:18:00:00"
expect = "604427"
cmd = "../target/release/ngxav -f ../tests/logs/750k.log -e 16/Jan/2024:15:00:00"
expect = "1111"

[[test_cases]]
name = "StartAndEndDate"
Expand Down Expand Up @@ -91,5 +91,29 @@ expect = "4185"
[[test_cases]]
name = "ConserveMem/Normal"
run_type = "lines_count"
cmd = "../target/release/ngxav -f ../tests/logs/750k.log -s CFNetwork --cm"
expect = "552863"
cmd = "../target/release/ngxav -f ../tests/logs/750k.log -s png --cm"
expect = "1551"

[[test_cases]]
name = "UserAgent/Bot"
run_type = "checksum"
cmd = "../target/release/ngxav -f ../tests/logs/750k.log --bot true"
expect = "77d40d9d4d8f634a16a88e377e8da32d"

[[test_cases]]
name = "UserAgent/PC"
run_type = "checksum"
cmd = "../target/release/ngxav -f ../tests/logs/750k.log --device_category pc"
expect = "c1ac68c1a5686870a1e97ba53851ea5f"

[[test_cases]]
name = "UserAgent/OS"
run_type = "checksum"
cmd = "../target/release/ngxav -f ../tests/logs/750k.log --os android"
expect = "2075c103a753aad8ea74f52f70491eb0"

[[test_cases]]
name = "UserAgent/Browser"
run_type = "checksum"
cmd = "../target/release/ngxav -f ../tests/logs/750k.log --browser safari"
expect = "afc81eea18cbd8c6e836238d0a158172"

0 comments on commit a16b327

Please sign in to comment.