Skip to content

Commit

Permalink
test: update
Browse files Browse the repository at this point in the history
  • Loading branch information
saying121 committed Oct 6, 2024
1 parent 522ebc8 commit 6ad0773
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 88 deletions.
2 changes: 1 addition & 1 deletion crates/decrypt-cookies/tests/check_it_compile.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use decrypt_cookies::{browser::Chrome, prelude::*};
use decrypt_cookies::prelude::*;

#[tokio::test]
async fn can_compile() {
Expand Down
92 changes: 49 additions & 43 deletions crates/decrypt-cookies/tests/chromium_passwd_work.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use decrypt_cookies::{Browser, ChromiumBuilder};
use strum::IntoEnumIterator;
use decrypt_cookies::prelude::*;

#[ignore = "need realy environment"]
#[tokio::test]
async fn passwd() {
let edge_getter = match ChromiumBuilder::new(Browser::Yandex)
let edge_getter = match ChromiumBuilder::new(Chrome::new())
.build()
.await
{
Expand All @@ -18,7 +17,7 @@ async fn passwd() {
.get_logins_all()
.await
.unwrap();
dbg!(&res[0]);
// dbg!(&res[0]);
for i in res.into_iter().take(6) {
println!(
"{}, {}, {}, {}",
Expand All @@ -36,45 +35,52 @@ async fn passwd() {
#[ignore = "need realy environment"]
#[tokio::test]
async fn passwd_browsers() {
for browser in Browser::iter().skip_while(|v| !v.is_chromium_base()) {
dbg!(browser);
let getter = match ChromiumBuilder::new(browser)
.build()
.await
{
Ok(it) => it,
Err(e) => {
eprintln!("{e}");
continue;
},
};
let res = match getter.get_logins_all().await {
Ok(v) => v,
Err(e) => {
eprintln!("{e}");
vec![]
},
};
match res.first() {
Some(first) => {
println!(
"{} {} {} ",
first.origin_url,
first
.username_value
.as_deref()
.unwrap_or_default(),
first
.password_value
.as_deref()
.unwrap_or_default()
);
},
None => {
macro_rules! test_chromium_pwd {
($($browser:ident), *) => {
$(
let getter = match ChromiumBuilder::new($browser::new())
.build()
.await
{
Ok(it) => it,
Err(e) => {
eprintln!("{e}");
return;
},
};
let res = match getter.get_logins_all().await {
Ok(v) => v,
Err(e) => {
eprintln!("{e}");
vec![]
},
};
match res.first() {
Some(first) => {
println!(
"{} {} {} ",
first.origin_url,
first
.username_value
.as_deref()
.unwrap_or_default(),
first
.password_value
.as_deref()
.unwrap_or_default()
);
},
None => {
println!("=============");
return;
},
};
println!("=============");
continue;
},
};
println!("=============");
)*
}
}

test_chromium_pwd!(Chrome, Edge, Chromium, Brave, Yandex, Vivaldi, Opera);
#[cfg(not(target_os = "linux"))]
test_chromium_pwd!(OperaGX, CocCoc, Arc);
}
45 changes: 22 additions & 23 deletions crates/decrypt-cookies/tests/cookies_work.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use decrypt_cookies::{browser::Browser, ChromiumBuilder, FirefoxBuilder};
use decrypt_cookies::{
browser::{Chrome, Firefox},
prelude::*,
};
use miette::Result;
use strum::IntoEnumIterator;

#[ignore = "need realy environment"]
#[tokio::test]
Expand All @@ -10,26 +12,23 @@ async fn chromium_get_all_cookie_work() -> Result<()> {
.with_test_writer()
.init();

for browser in Browser::iter().skip_while(|v| !v.is_chromium_base()) {
println!("============== {browser}");
let chrmo = ChromiumBuilder::new(browser)
.build()
.await?;
let a = match chrmo.get_cookies_all().await {
Ok(it) => it,
Err(e) => {
println!("{e}");
continue;
},
};
for i in a.iter().take(6) {
println!(
"{}, {},{}",
i.name,
i.expires_utc.unwrap(),
i.creation_utc.unwrap()
);
}
let chrmo = ChromiumBuilder::new(Chrome::new())
.build()
.await?;
let a = match chrmo.get_cookies_all().await {
Ok(it) => it,
Err(e) => {
println!("{e}");
return Ok(());
},
};
for i in a.iter().take(6) {
println!(
"{}, {},{}",
i.name,
i.expires_utc.unwrap(),
i.creation_utc.unwrap()
);
}

Ok(())
Expand All @@ -42,7 +41,7 @@ async fn ff_get_all_cookie_work() -> Result<()> {
.with_test_writer()
.init();

let ff = FirefoxBuilder::new(Browser::Firefox)
let ff = FirefoxBuilder::new(Firefox::new()?)
.build()
.await?;
let a = ff.get_cookies_all().await?;
Expand Down
25 changes: 8 additions & 17 deletions crates/decrypt-cookies/tests/get_csrf_session.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::io::Write;

use decrypt_cookies::{get_cookie, Browser, LeetCodeCookies};
use decrypt_cookies::prelude::*;
use miette::{IntoDiagnostic, Result};
use strum::{EnumProperty, IntoEnumIterator};

#[ignore = "need realy environment"]
#[tokio::test(flavor = "multi_thread", worker_threads = 10)]
Expand All @@ -16,21 +15,13 @@ async fn get_cookie_work() -> Result<()> {
let mut std_lock = stdout.lock();

let leetcode_cn = "leetcode.cn";
for browser in Browser::iter().skip_while(|v| {
!v.get_str("Based")
.unwrap()
.eq_ignore_ascii_case("chromium")
}) {
dbg!(browser);
let edge = match get_cookie(browser, leetcode_cn).await {
Ok(v) => v,
Err(err) => {
println!("{err}");
LeetCodeCookies::default()
},
};
writeln!(std_lock, "{:#?}", edge).into_diagnostic()?;
}
let edge = ChromiumBuilder::new(Edge::new())
.build()
.await?;
let ck = edge
.get_cookies_session_csrf(leetcode_cn)
.await?;
writeln!(std_lock, "{:#?}", ck).into_diagnostic()?;

Ok(())
}
2 changes: 0 additions & 2 deletions crates/decrypt-cookies/tests/inspect_service_work.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![expect(clippy::string_slice)]

#[ignore]
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
#[cfg(target_os = "linux")]
Expand Down
7 changes: 5 additions & 2 deletions crates/decrypt-cookies/tests/reqwest_jar.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::sync::Arc;

use decrypt_cookies::{browser::cookies::CookiesInfo, Browser, ChromiumBuilder};
use decrypt_cookies::{
browser::{cookies::CookiesInfo, Edge},
prelude::*,
};
use reqwest::{
cookie::{CookieStore, Jar},
Client, Url,
Expand All @@ -9,7 +12,7 @@ use reqwest::{
#[ignore]
#[tokio::test]
async fn to_jar() {
let chrmo = ChromiumBuilder::new(Browser::Edge)
let chrmo = ChromiumBuilder::new(Edge::new())
.build()
.await
.unwrap();
Expand Down

0 comments on commit 6ad0773

Please sign in to comment.