Skip to content

Commit

Permalink
Add a test for non-spoofed gateway search
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaszklak committed Dec 5, 2024
1 parent cbfb3b7 commit a98baa9
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/common/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,28 @@ const RESP_SPOOFED_CONTROL_URL: &'static str = r#"<?xml version="1.0" ?>
</root>
"#;

const RESP: &'static str = r#"<?xml version="1.0" ?>
<root xmlns="urn:schemas-upnp-org:device-1-0">
<device>
<deviceList>
<device>
<deviceList>
<device>
<serviceList>
<service>
<serviceType>urn:schemas-upnp-org:service:WANIPConnection:1</serviceType>
<controlURL>/igdupnp/control/WANIPConn1</controlURL>
<SCPDURL>/igdupnp/control/WANIPConn1</SCPDURL>
</service>
</serviceList>
</device>
</deviceList>
</device>
</deviceList>
</device>
</root>
"#;

const RESP_CONTROL_SCHEMA: &'static str = r#"<?xml version="1.0" ?>
<root xmlns="urn:schemas-upnp-org:device-1-0">
<actionList>
Expand Down Expand Up @@ -219,3 +241,28 @@ async fn ip_spoofing_in_getxml_body_control_url() {
#[cfg(feature = "aio")]
aux(|opt| async { crate::aio::search_gateway(opt).await.map(|_| ()) }).await;
}

#[test(tokio::test)]
async fn non_spoofed_urls_result_in_search_gateway_success() {
async fn aux<F, Fut>(search_gateway: F)
where
Fut: Future<Output = Result<(), SearchError>>,
F: Fn(SearchOptions) -> Fut,
{
let http_port = start_http_server(vec![RESP.to_owned(), RESP_CONTROL_SCHEMA.to_owned()]).await;

let local_free_port = start_broadcast_reply_sender(format!("http://127.0.0.1:{http_port}")).await;

let options = default_options_with_using_free_port(local_free_port);

assert!(search_gateway(options).await.is_ok());
}
aux(|opt| async {
tokio::task::spawn_blocking(|| search_gateway(opt).map(|_| ()))
.await
.unwrap()
})
.await;
#[cfg(feature = "aio")]
aux(|opt| async { crate::aio::search_gateway(opt).await.map(|_| ()) }).await;
}

0 comments on commit a98baa9

Please sign in to comment.