use pocketscion::util::topologies::{IA132, UnderlayType, minimal::two_path_topology};
use scion_stack::stack::{
ScionSocketBindError, ScionStackBuilder, SnapConnectionError, builder::BuildScionStackError,
};
use snap_tokens::v0::dummy_snap_token;
use test_log::test;
#[test(tokio::test)]
#[ntest::timeout(10_000)]
async fn endhost_api_unreachable_should_error() {
scion_sdk_utils::rustls::select_ring_crypto_provider();
let unreachable_url = "http://127.0.0.1:1".parse().unwrap();
let result = ScionStackBuilder::new()
.with_endhost_api(unreachable_url)
.with_auth_token(dummy_snap_token())
.build()
.await;
match result {
Err(BuildScionStackError::AllEndhostApisFailed(failed))
if failed.is_transient()
&& failed.failures().iter().all(|(_, err)| err.is_transient()) => {}
_ => {
panic!(
"expected transient BuildScionStackError::AllEndhostApisFailed for unreachable server, got {result:?}"
)
}
};
}
#[test(tokio::test)]
#[ntest::timeout(10_000)]
async fn test_invalid_snap_token() {
let ps_handle = two_path_topology(UnderlayType::Snap).await;
let result = ScionStackBuilder::new()
.with_endhost_api(ps_handle.endhost_api(IA132).unwrap())
.with_auth_token("invalid token".to_string())
.build()
.await
.unwrap()
.bind(None)
.await;
assert!(
matches!(
result,
Err(ScionSocketBindError::SnapConnectionError(
SnapConnectionError::DataPlaneDiscovery(_)
))
),
"expected Snap::DataPlaneDiscovery with Unauthenticated code for invalid token, got {result:?}"
);
}