37 lines
1.1 KiB
Rust
37 lines
1.1 KiB
Rust
//! Helpers for error-path tests.
|
|
use crate::support::{default_test_credentials, test_auth_manager};
|
|
use niom_turn::alloc::AllocationManager;
|
|
use niom_turn::auth::{AuthManager, InMemoryStore};
|
|
use std::net::SocketAddr;
|
|
use std::sync::Arc;
|
|
use tokio::net::UdpSocket;
|
|
|
|
pub fn malformed_stun_frame() -> Vec<u8> {
|
|
vec![0x00, 0x01, 0x02] // too short for STUN header
|
|
}
|
|
|
|
pub fn oversized_payload() -> Vec<u8> {
|
|
vec![0u8; 4096]
|
|
}
|
|
|
|
pub fn build_auth_manager() -> AuthManager<InMemoryStore> {
|
|
let (user, password) = default_test_credentials();
|
|
test_auth_manager(user, password)
|
|
}
|
|
|
|
pub async fn spawn_udp_server(
|
|
auth: AuthManager<InMemoryStore>,
|
|
allocs: AllocationManager,
|
|
) -> SocketAddr {
|
|
let server = UdpSocket::bind("127.0.0.1:0").await.expect("udp bind");
|
|
let addr = server.local_addr().expect("udp addr");
|
|
let arc = Arc::new(server);
|
|
let reader = arc.clone();
|
|
let auth_clone = auth.clone();
|
|
let alloc_clone = allocs.clone();
|
|
tokio::spawn(async move {
|
|
let _ = niom_turn::server::udp_reader_loop(reader, auth_clone, alloc_clone).await;
|
|
});
|
|
addr
|
|
}
|