//! UDP allocation lifecycle integration tests. #[path = "../support/mod.rs"] mod support; mod helpers; use crate::support::stun_builders::{ build_allocate_request, build_refresh_request, extract_lifetime, new_transaction_id, parse, }; use helpers::*; use niom_turn::alloc::AllocationManager; use niom_turn::auth; use support::{default_test_credentials, init_tracing, test_auth_manager}; use tokio::net::UdpSocket; #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn refresh_request_is_clamped_to_maximum_lifetime() { init_tracing(); let (username, password) = default_test_credentials(); let auth_manager = test_auth_manager(username, password); let allocs = AllocationManager::new(); let server_addr = spawn_udp_server(auth_manager.clone(), allocs.clone()).await; let client = UdpSocket::bind("127.0.0.1:0").await.expect("client bind"); let mut buf = [0u8; 1500]; // Challenge for nonce let challenge = build_allocate_request(None, None, None, None, None); client .send_to(&challenge, server_addr) .await .expect("send challenge"); let (len, _) = client.recv_from(&mut buf).await.expect("recv nonce"); let resp = parse(&buf[..len]); let nonce = helpers::extract_nonce(&resp).expect("nonce attr"); // Successful allocation let key = auth::compute_a1_md5(username, auth_manager.realm(), password); let allocate = build_allocate_request( Some(username), Some(auth_manager.realm()), Some(&nonce), Some(&key), Some(600), ); client .send_to(&allocate, server_addr) .await .expect("send auth allocate"); client.recv_from(&mut buf).await.expect("recv alloc success"); // Request refresh with value exceeding MAX (7200s) and assert server clamps to 3600 let refresh = build_refresh_request( new_transaction_id(), username, auth_manager.realm(), &nonce, &key, 7200, ); client .send_to(&refresh, server_addr) .await .expect("send refresh"); let (len, _) = client.recv_from(&mut buf).await.expect("recv refresh"); let resp = parse(&buf[..len]); let lifetime = extract_lifetime(&resp).expect("lifetime attr"); assert_eq!(lifetime, 3600); }