#![cfg(feature = "js")]
use pyrograph::analyze;
#[test]
fn interprocedural_argument_taint() {
let js = r#"
function f(x) { eval(x); }
f(process.env.TOKEN);
"#;
let graph = pyrograph::parse::parse_js(js, "t.js").unwrap();
assert!(
!analyze(&graph).unwrap().is_empty(),
"Taint must flow from argument to parameter interprocedurally"
);
}
#[test]
fn class_method_body_taint() {
let js = r#"
class C {
run() {
var x = process.env.TOKEN;
eval(x);
}
}
new C().run();
"#;
let graph = pyrograph::parse::parse_js(js, "t.js").unwrap();
assert!(
!analyze(&graph).unwrap().is_empty(),
"Class method body must be visited for taint analysis"
);
}
#[test]
fn throw_expression_taint() {
let js = r#"
throw eval(process.env.TOKEN);
"#;
let graph = pyrograph::parse::parse_js(js, "t.js").unwrap();
assert!(
!analyze(&graph).unwrap().is_empty(),
"Throw expression must be evaluated for taint"
);
}
#[test]
fn do_while_taint() {
let js = r#"
do {
fetch(process.env.TOKEN);
} while (false);
"#;
let graph = pyrograph::parse::parse_js(js, "t.js").unwrap();
assert!(
!analyze(&graph).unwrap().is_empty(),
"Do-while body must be visited for taint analysis"
);
}