Some checks failed
gitleaks / scan (push) Failing after 2s
- nsig name resolution: route direct-vs-array on capture-group PARTICIPATION,
not declared-group count (regexes 6/7 carry an optional array group) — a
direct-call player.js shape no longer hard-fails NsigArrayLookupFailed.
- nsig fixup_function: also strip the `if(typeof X==="undefined")return a;`
guard on the `function name(a){...}` body shape (previously required a
leading `;`), so the regex-fallback shape no longer silently yields an
identity result that gets cached as a permanent throttle.
- player_manager: never hold the state lock across the network; serialize
player.js downloads behind a fetch gate; add a per-artifact failure memo
(5-min cooldown) so a persistently-broken player.js costs one refetch per
open instead of a ~20-25 x 1.7MB storm. Transient-rotation self-heal
preserved (eval failure -> invalidate + refetch, no memo).
- errors no longer leak watch URLs / video ids: From<reqwest::Error> uses
without_url(); Recaptcha + link errors reduce to scheme+host (paths like
/embed/<id> and /shorts/<id> carried the id in the path).
- revive tests/ after the strawcore-core rename; js_phase2_offline green.
133 lib + 7 integration tests, clippy -D clean.
100 lines
3.6 KiB
Rust
100 lines
3.6 KiB
Rust
// Foundation smoke — exercises the downloader/service-spine against
|
|
// live httpbin.org. Builds a Request, sends through default Downloader,
|
|
// parses Response, confirms latest_url follows redirects.
|
|
//
|
|
// These tests hit the network — gated on the `online-tests` feature so
|
|
// CI offline runs aren't broken.
|
|
|
|
#![cfg(feature = "online-tests")]
|
|
|
|
use std::sync::Arc;
|
|
|
|
use strawcore_core::downloader::request::Request;
|
|
use strawcore_core::downloader::ReqwestDownloader;
|
|
use strawcore_core::exceptions::NetworkError;
|
|
use strawcore_core::localization::{ContentCountry, Localization};
|
|
use strawcore_core::{Downloader, NewPipe};
|
|
|
|
/// The Downloader trait dropped its `get` convenience (commit f917e4a);
|
|
/// mirror it here so the suite reads as before.
|
|
fn get(dl: &impl Downloader, url: &str) -> Result<strawcore_core::Response, NetworkError> {
|
|
dl.execute(Request::get(url).build())
|
|
}
|
|
|
|
#[test]
|
|
fn get_through_default_downloader() {
|
|
let dl = ReqwestDownloader::new().expect("build downloader");
|
|
let resp = get(&dl, "https://httpbin.org/get").expect("transport");
|
|
assert_eq!(resp.response_code(), 200);
|
|
assert!(resp.response_body().contains("\"url\""));
|
|
}
|
|
|
|
#[test]
|
|
fn latest_url_follows_redirects() {
|
|
let dl = ReqwestDownloader::new().expect("build downloader");
|
|
let resp = get(&dl, "https://httpbin.org/redirect/3").expect("transport");
|
|
assert_eq!(resp.response_code(), 200);
|
|
assert!(
|
|
resp.latest_url().ends_with("/get"),
|
|
"latest_url should land at /get after 3 redirects, got {}",
|
|
resp.latest_url()
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn non_2xx_returns_ok_not_err() {
|
|
let dl = ReqwestDownloader::new().expect("build downloader");
|
|
let resp = get(&dl, "https://httpbin.org/status/404").expect("transport");
|
|
assert_eq!(resp.response_code(), 404);
|
|
}
|
|
|
|
#[test]
|
|
fn http_429_surfaces_as_recaptcha_err() {
|
|
let dl = ReqwestDownloader::new().expect("build downloader");
|
|
let err = get(&dl, "https://httpbin.org/status/429").expect_err("429 must be NetworkError");
|
|
match err {
|
|
NetworkError::Recaptcha { url } => assert!(url.contains("/status/429")),
|
|
other => panic!("expected Recaptcha, got {other:?}"),
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn localization_header_attached_when_enabled() {
|
|
let dl = ReqwestDownloader::new().expect("build downloader");
|
|
let req = Request::get("https://httpbin.org/headers")
|
|
.localization(Some(Localization::new("en", Some("GB".into()))))
|
|
.build();
|
|
let resp = dl.execute(req).expect("transport");
|
|
assert_eq!(resp.response_code(), 200);
|
|
assert!(
|
|
resp.response_body().to_ascii_lowercase().contains("accept-language"),
|
|
"Accept-Language should be echoed by httpbin"
|
|
);
|
|
assert!(resp.response_body().contains("en-GB"));
|
|
}
|
|
|
|
#[test]
|
|
fn header_keys_lowercased_in_response() {
|
|
let dl = ReqwestDownloader::new().expect("build downloader");
|
|
let resp = get(&dl, "https://httpbin.org/get").expect("transport");
|
|
for k in resp.response_headers().keys() {
|
|
assert_eq!(k, &k.to_ascii_lowercase(), "header key {k} not lowercased");
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn newpipe_singleton_wires_downloader() {
|
|
let dl = Arc::new(ReqwestDownloader::new().expect("build downloader"));
|
|
NewPipe::init_full(
|
|
dl.clone(),
|
|
Localization::default(),
|
|
ContentCountry::default(),
|
|
);
|
|
|
|
let from_global = NewPipe::downloader().expect("downloader registered");
|
|
let resp = from_global
|
|
.execute(Request::get("https://httpbin.org/get").build())
|
|
.expect("transport");
|
|
assert_eq!(resp.response_code(), 200);
|
|
assert_eq!(NewPipe::preferred_localization().localization_code(), "en-GB");
|
|
}
|