Skip to content

Commit bfe9341

Browse files
committed
Rust: Add web framework tests for Warp
1 parent 7670a2b commit bfe9341

File tree

3 files changed

+131
-0
lines changed

3 files changed

+131
-0
lines changed

rust/ql/test/library-tests/dataflow/sources/Cargo.lock

Lines changed: 72 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/ql/test/library-tests/dataflow/sources/options.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ qltest_dependencies:
1616
- rustls = { version = "0.23.27" }
1717
- futures-rustls = { version = "0.26.0" }
1818
- async-std = { version = "1.13.1" }
19+
- warp = { version = "0.4.2", features = ["server"] }

rust/ql/test/library-tests/dataflow/sources/web_frameworks.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,61 @@ mod axum_test {
229229
// ...
230230
}
231231
}
232+
233+
mod warp_test {
234+
use super::sink;
235+
use warp::Filter;
236+
237+
#[tokio::main]
238+
#[rustfmt::skip]
239+
async fn test_warp() {
240+
// A route with parameter and `map`
241+
let map_route =
242+
warp::path::param().map(|a: String| // $ MISSING: Alert[rust/summary/taint-sources]
243+
{
244+
sink(a); // $ MISSING: hasTaintFlow
245+
246+
"".to_string()
247+
});
248+
249+
// A route with parameter and `then`
250+
let then_route = warp::path::param().then( // $ MISSING: Alert[rust/summary/taint-sources]
251+
|a: String| async move {
252+
sink(a); // $ MISSING: hasTaintFlow
253+
254+
"".to_string()
255+
},
256+
);
257+
258+
// A route with parameter and `and_then`
259+
let and_then_route = warp::path::param().and_then( // $ MISSING: Alert[rust/summary/taint-sources]
260+
| id: u64 |
261+
async move {
262+
if id != 0 {
263+
sink(id); // $ MISSING: hasTaintFlow
264+
Ok("".to_string())
265+
} else {
266+
Err(warp::reject::not_found())
267+
}
268+
},
269+
);
270+
271+
// A route with path, parameter, and `and_then`
272+
let path_and_map_route = warp::path("1").and(warp::path::param()).map( // $ MISSING: Alert[rust/summary/taint-sources]
273+
| a: String |
274+
{
275+
sink(a); // $ MISSING: hasTaintFlow
276+
277+
"".to_string()
278+
},
279+
);
280+
281+
let routes = warp::get().and(
282+
map_route
283+
.or(then_route)
284+
.or(and_then_route)
285+
.or(path_and_map_route),
286+
);
287+
warp::serve(routes).run(([127, 0, 0, 1], 3030)).await;
288+
}
289+
}

0 commit comments

Comments
 (0)