use crate::dialog::{
authenticate::Credential,
client_dialog::ClientInviteDialog,
dialog::{DialogState, TerminatedReason},
dialog_layer::DialogLayer,
invitation::InviteOption,
};
use crate::sip::{headers::*, Header, HeadersExt, Method, Response, StatusCode, Uri};
use crate::transaction::TransactionReceiver;
use crate::transport::{udp::UdpConnection, TransportLayer};
use crate::EndpointBuilder;
use std::time::Duration;
use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver};
use tokio_util::sync::CancellationToken;
const PROMPT: Duration = Duration::from_secs(5);
const CHALLENGE: &str =
r#"Digest realm="example.com", nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", algorithm=MD5"#;
struct Peers {
token: CancellationToken,
uac_layer: DialogLayer,
uas_port: u16,
uac_port: u16,
}
async fn udp_endpoint(
token: &CancellationToken,
ua: &str,
) -> crate::Result<(crate::transaction::endpoint::Endpoint, u16)> {
let tl = TransportLayer::new(token.child_token());
let udp = UdpConnection::create_connection(
"127.0.0.1:0".parse().unwrap(),
None,
Some(token.child_token()),
)
.await?;
let port = udp.get_addr().addr.port.map(u16::from).unwrap_or(0);
tl.add_transport(udp.into());
let endpoint = EndpointBuilder::new()
.with_user_agent(ua)
.with_transport_layer(tl)
.with_cancel_token(token.child_token())
.build();
let inner = endpoint.inner.clone();
tokio::spawn(async move {
let _ = inner.serve().await;
});
Ok((endpoint, port))
}
async fn peers() -> crate::Result<(Peers, TransactionReceiver)> {
let token = CancellationToken::new();
let (uas, uas_port) = udp_endpoint(&token, "rsipstack-uas").await?;
let (uac, uac_port) = udp_endpoint(&token, "rsipstack-uac").await?;
let uas_incoming = uas.incoming_transactions()?;
let peers = Peers {
token,
uac_layer: DialogLayer::new(uac.inner.clone()),
uas_port,
uac_port,
};
Ok((peers, uas_incoming))
}
fn invite_option(p: &Peers, credential: Option<Credential>) -> InviteOption {
InviteOption {
caller: Uri::try_from("sip:alice@example.com").unwrap(),
callee: Uri::try_from(format!("sip:bob@127.0.0.1:{};transport=udp", p.uas_port)).unwrap(),
contact: Uri::try_from(format!("sip:alice@127.0.0.1:{}", p.uac_port)).unwrap(),
credential,
..Default::default()
}
}
fn challenge_header(status: &StatusCode) -> Header {
match status {
StatusCode::ProxyAuthenticationRequired => ProxyAuthenticate::new(CHALLENGE).into(),
_ => WwwAuthenticate::new(CHALLENGE).into(),
}
}
fn answers_challenge(status: &StatusCode, headers: &Headers) -> bool {
headers.iter().any(|h| match status {
StatusCode::ProxyAuthenticationRequired => matches!(h, Header::ProxyAuthorization(_)),
_ => matches!(h, Header::Authorization(_)),
})
}
fn spawn_uas(
mut incoming: TransactionReceiver,
status: StatusCode,
uas_port: u16,
accept_credentials: bool,
) -> UnboundedReceiver<bool> {
let (seen_tx, seen_rx) = unbounded_channel();
tokio::spawn(async move {
while let Some(mut tx) = incoming.recv().await {
if tx.original.method != Method::Invite {
continue;
}
let authed = answers_challenge(&status, &tx.original.headers);
let _ = seen_tx.send(authed);
let status = status.clone();
tokio::spawn(async move {
if authed && accept_credentials {
let contact = Contact::new(format!("<sip:bob@127.0.0.1:{}>", uas_port));
tx.reply_with(StatusCode::OK, vec![contact.into()], None)
.await
.expect("reply 200");
} else {
tx.reply_with(status.clone(), vec![challenge_header(&status)], None)
.await
.expect("reply challenge");
}
while tx.receive().await.is_some() {}
});
}
});
seen_rx
}
async fn assert_no_more_invites(seen: &mut UnboundedReceiver<bool>) {
let next = tokio::time::timeout(Duration::from_millis(300), seen.recv()).await;
assert!(next.is_err(), "unexpected further INVITE: {next:?}");
}
fn credential() -> Credential {
Credential {
username: "alice".to_string(),
password: "secret".to_string(),
realm: None,
auth_username: None,
}
}
async fn assert_in_dialog_auth(
status: StatusCode,
with_credential: bool,
accept_credentials: bool,
) -> crate::Result<()> {
for method in [
Method::Invite,
Method::Update,
Method::Info,
Method::Options,
] {
let (p, mut incoming) = peers().await?;
let (seen_tx, mut seen) = unbounded_channel();
let challenged = status.clone();
let port = p.uas_port;
let server_method = method.clone();
tokio::spawn(async move {
while let Some(mut tx) = incoming.recv().await {
let initial = tx.original.to_header().unwrap().tag().unwrap().is_none();
let authed = answers_challenge(&challenged, &tx.original.headers);
let is_test_request = !initial && tx.original.method == server_method;
let requires_auth = is_test_request || tx.original.method == Method::Bye;
if is_test_request {
seen_tx.send(authed).unwrap();
}
let status = challenged.clone();
tokio::spawn(async move {
if requires_auth && !(authed && accept_credentials) {
tx.reply_with(status.clone(), vec![challenge_header(&status)], None)
.await
.unwrap();
} else {
tx.reply_with(
StatusCode::OK,
vec![Contact::new(format!("<sip:bob@127.0.0.1:{port}>")).into()],
None,
)
.await
.unwrap();
}
while tx.receive().await.is_some() {}
});
}
});
let (states, mut events) = unbounded_channel();
let (dialog, response) = tokio::time::timeout(
PROMPT,
p.uac_layer
.do_invite(invite_option(&p, with_credential.then(credential)), states),
)
.await
.expect("initial INVITE did not complete")?;
assert_eq!(response.unwrap().status_code, StatusCode::OK);
while events.try_recv().is_ok() {}
let before = dialog.snapshot();
let response = tokio::time::timeout(PROMPT, async {
match method {
Method::Invite => dialog.reinvite(None, None).await,
Method::Update => dialog.update(None, None).await,
Method::Info => dialog.info(None, None).await,
Method::Options => dialog.options(None).await,
_ => unreachable!(),
}
})
.await
.expect("in-dialog auth result must return promptly")?
.expect("the final response must be returned");
let expected = if with_credential && accept_credentials {
StatusCode::OK
} else {
status.clone()
};
assert_eq!(response.status_code, expected, "{method}");
assert!(dialog.state().is_confirmed(), "{method} ended the call");
let after = dialog.snapshot();
assert_eq!(after.id, before.id);
assert_eq!(after.remote_uri, before.remote_uri);
assert!(!seen.try_recv().unwrap());
if with_credential {
assert!(seen.try_recv().unwrap());
}
assert!(seen.try_recv().is_err(), "unexpected extra auth retry");
while let Ok(event) = events.try_recv() {
assert!(!matches!(event, DialogState::Terminated(..)));
}
tokio::time::timeout(PROMPT, dialog.bye())
.await
.expect("BYE did not complete")?;
assert!(dialog.state().is_terminated());
p.token.cancel();
}
Ok(())
}
#[tokio::test]
async fn in_dialog_auth_without_credentials_preserves_session() -> crate::Result<()> {
for status in [
StatusCode::Unauthorized,
StatusCode::ProxyAuthenticationRequired,
] {
assert_in_dialog_auth(status, false, false).await?;
}
Ok(())
}
#[tokio::test]
async fn in_dialog_auth_rejected_credentials_preserves_session() -> crate::Result<()> {
for status in [
StatusCode::Unauthorized,
StatusCode::ProxyAuthenticationRequired,
] {
assert_in_dialog_auth(status, true, false).await?;
}
Ok(())
}
#[tokio::test]
async fn in_dialog_auth_successful_retry_preserves_session() -> crate::Result<()> {
for status in [
StatusCode::Unauthorized,
StatusCode::ProxyAuthenticationRequired,
] {
assert_in_dialog_auth(status, true, true).await?;
}
Ok(())
}
fn is_auth_terminated(state: &DialogState) -> bool {
matches!(
state,
DialogState::Terminated(_, TerminatedReason::ProxyAuthRequired)
)
}
async fn assert_challenge_returned_without_credential(status: StatusCode) -> crate::Result<()> {
let (p, uas_incoming) = peers().await?;
let mut seen = spawn_uas(uas_incoming, status.clone(), p.uas_port, true);
let (state_tx, mut state_rx) = unbounded_channel();
let opt = invite_option(&p, None);
let (dialog, resp) = tokio::time::timeout(PROMPT, p.uac_layer.do_invite(opt, state_tx))
.await
.unwrap_or_else(|_| panic!("do_invite did not return the {status} challenge promptly"))?;
let resp = resp.unwrap_or_else(|| panic!("the {status} challenge must be the final response"));
assert_eq!(resp.status_code, status);
assert!(is_auth_terminated(&dialog.state()));
let mut terminated = false;
while let Ok(state) = state_rx.try_recv() {
terminated |= is_auth_terminated(&state);
}
assert!(terminated, "ProxyAuthRequired termination must be emitted");
assert_eq!(seen.recv().await, Some(false));
assert_no_more_invites(&mut seen).await;
p.token.cancel();
Ok(())
}
#[tokio::test]
async fn test_invite_401_without_credential_is_final_response() -> crate::Result<()> {
assert_challenge_returned_without_credential(StatusCode::Unauthorized).await
}
#[tokio::test]
async fn test_invite_407_without_credential_is_final_response() -> crate::Result<()> {
assert_challenge_returned_without_credential(StatusCode::ProxyAuthenticationRequired).await
}
#[tokio::test]
async fn test_legacy_client_dialog_401_without_credential_is_final_response() -> crate::Result<()> {
let (p, uas_incoming) = peers().await?;
let mut seen = spawn_uas(uas_incoming, StatusCode::Unauthorized, p.uas_port, true);
let (state_tx, _state_rx) = unbounded_channel();
let opt = invite_option(&p, None);
let (dialog, mut tx) = p.uac_layer.create_client_invite_dialog(opt, state_tx)?;
let legacy = ClientInviteDialog::try_from(dialog)?;
let (_, resp) = tokio::time::timeout(PROMPT, legacy.process_invite(&mut tx))
.await
.expect("process_invite did not return the 401 promptly")?;
let resp = resp.expect("the 401 must be the final response");
assert_eq!(resp.status_code, StatusCode::Unauthorized);
assert!(is_auth_terminated(&legacy.state()));
assert_eq!(seen.recv().await, Some(false));
assert_no_more_invites(&mut seen).await;
p.token.cancel();
Ok(())
}
async fn assert_challenge_retried_with_credential(status: StatusCode) -> crate::Result<()> {
let (p, uas_incoming) = peers().await?;
let mut seen = spawn_uas(uas_incoming, status.clone(), p.uas_port, true);
let (state_tx, _state_rx) = unbounded_channel();
let opt = invite_option(&p, Some(credential()));
let (dialog, resp) = tokio::time::timeout(PROMPT, p.uac_layer.do_invite(opt, state_tx))
.await
.expect("authenticated INVITE did not complete")?;
let resp: Response = resp.expect("final response after the authenticated retry");
assert_eq!(resp.status_code, StatusCode::OK);
assert!(dialog.inner.is_confirmed());
assert_eq!(
seen.recv().await,
Some(false),
"first INVITE is unauthenticated"
);
assert_eq!(seen.recv().await, Some(true), "retry answers the challenge");
assert_no_more_invites(&mut seen).await;
p.token.cancel();
Ok(())
}
#[tokio::test]
async fn test_invite_401_with_credential_retries() -> crate::Result<()> {
assert_challenge_retried_with_credential(StatusCode::Unauthorized).await
}
#[tokio::test]
async fn test_invite_407_with_credential_retries() -> crate::Result<()> {
assert_challenge_retried_with_credential(StatusCode::ProxyAuthenticationRequired).await
}
#[tokio::test]
async fn test_invite_challenge_after_authenticated_retry_is_final_response() -> crate::Result<()> {
let status = StatusCode::Unauthorized;
let (p, uas_incoming) = peers().await?;
let mut seen = spawn_uas(uas_incoming, status.clone(), p.uas_port, false);
let (state_tx, _state_rx) = unbounded_channel();
let opt = invite_option(&p, Some(credential()));
let (dialog, resp) = tokio::time::timeout(PROMPT, p.uac_layer.do_invite(opt, state_tx))
.await
.expect("challenged retry did not complete")?;
let resp = resp.expect("the second challenge must be the final response");
assert_eq!(resp.status_code, status);
assert!(is_auth_terminated(&dialog.state()));
assert_eq!(
seen.recv().await,
Some(false),
"first INVITE is unauthenticated"
);
assert_eq!(seen.recv().await, Some(true), "retry answers the challenge");
assert_no_more_invites(&mut seen).await;
p.token.cancel();
Ok(())
}
#[tokio::test]
async fn test_cancelled_invite_is_not_retried_with_credential() -> crate::Result<()> {
let (p, uas_incoming) = peers().await?;
let mut seen = spawn_uas(uas_incoming, StatusCode::Unauthorized, p.uas_port, true);
let (state_tx, _state_rx) = unbounded_channel();
let opt = invite_option(&p, Some(credential()));
let layer = std::sync::Arc::new(p.uac_layer);
let (dialog, join) = layer.do_invite_async(opt, state_tx)?;
dialog.cancel().await?;
let (_, resp) = tokio::time::timeout(PROMPT, join)
.await
.expect("cancelled INVITE did not complete")
.expect("invite task")?;
assert_eq!(resp.map(|r| r.status_code), Some(StatusCode::Unauthorized));
assert!(dialog.state().is_terminated());
assert_eq!(seen.recv().await, Some(false));
assert_no_more_invites(&mut seen).await;
p.token.cancel();
Ok(())
}
const STALE_CHALLENGE: &str =
r#"Digest realm="example.com", nonce="0f9e8d7c6b5a", stale=true, algorithm=MD5"#;
fn spawn_stale_uas(
mut incoming: TransactionReceiver,
uas_port: u16,
stale_rounds: usize,
) -> UnboundedReceiver<bool> {
let (seen_tx, seen_rx) = unbounded_channel();
tokio::spawn(async move {
let mut authed_count = 0;
while let Some(mut tx) = incoming.recv().await {
if tx.original.method != Method::Invite {
continue;
}
let authed = answers_challenge(&StatusCode::Unauthorized, &tx.original.headers);
let _ = seen_tx.send(authed);
let reply = if !authed {
Some(WwwAuthenticate::new(CHALLENGE))
} else {
authed_count += 1;
(authed_count <= stale_rounds).then(|| WwwAuthenticate::new(STALE_CHALLENGE))
};
tokio::spawn(async move {
match reply {
Some(challenge) => tx
.reply_with(StatusCode::Unauthorized, vec![challenge.into()], None)
.await
.expect("reply challenge"),
None => {
let contact = Contact::new(format!("<sip:bob@127.0.0.1:{}>", uas_port));
tx.reply_with(StatusCode::OK, vec![contact.into()], None)
.await
.expect("reply 200")
}
}
while tx.receive().await.is_some() {}
});
}
});
seen_rx
}
#[tokio::test]
async fn test_invite_stale_nonce_is_retried() -> crate::Result<()> {
let (p, uas_incoming) = peers().await?;
let mut seen = spawn_stale_uas(uas_incoming, p.uas_port, 1);
let (state_tx, _state_rx) = unbounded_channel();
let opt = invite_option(&p, Some(credential()));
let (dialog, resp) = tokio::time::timeout(PROMPT, p.uac_layer.do_invite(opt, state_tx))
.await
.expect("stale-nonce retry did not complete")?;
assert_eq!(resp.map(|r| r.status_code), Some(StatusCode::OK));
assert!(dialog.inner.is_confirmed());
assert_eq!(
seen.recv().await,
Some(false),
"first INVITE is unauthenticated"
);
assert_eq!(seen.recv().await, Some(true), "authenticated retry");
assert_eq!(seen.recv().await, Some(true), "retry with the fresh nonce");
assert_no_more_invites(&mut seen).await;
p.token.cancel();
Ok(())
}
#[tokio::test]
async fn test_invite_stale_nonce_retries_are_bounded() -> crate::Result<()> {
let (p, uas_incoming) = peers().await?;
let mut seen = spawn_stale_uas(uas_incoming, p.uas_port, usize::MAX);
let (state_tx, _state_rx) = unbounded_channel();
let opt = invite_option(&p, Some(credential()));
let (dialog, resp) = tokio::time::timeout(PROMPT, p.uac_layer.do_invite(opt, state_tx))
.await
.expect("bounded stale retries did not complete")?;
assert_eq!(resp.map(|r| r.status_code), Some(StatusCode::Unauthorized));
assert!(is_auth_terminated(&dialog.state()));
assert_eq!(
seen.recv().await,
Some(false),
"first INVITE is unauthenticated"
);
for _ in 0..3 {
assert_eq!(seen.recv().await, Some(true));
}
assert_no_more_invites(&mut seen).await;
p.token.cancel();
Ok(())
}
mod restored_dialogs {
use super::*;
use crate::dialog::authenticate::verify_digest;
use crate::dialog::dialog::{Dialog, DialogInner, DialogSnapshot, DialogSnapshotState};
use crate::dialog::tests::test_dialog_states::create_invite_request;
use crate::dialog::DialogId;
use crate::sip::{prelude::HeadersExt, Request};
use crate::transaction::key::TransactionRole;
use std::sync::Arc;
fn snapshot(p: &Peers, role: TransactionRole) -> crate::Result<DialogSnapshot> {
let request = create_invite_request("alice-tag", "bob-tag", "restore-auth");
let id = DialogId::try_from((&request, role))?;
let (states, _) = unbounded_channel();
let (transactions, _) = unbounded_channel();
let inner = DialogInner::new(
role,
id,
request,
p.uac_layer.endpoint.clone(),
states,
Some(Credential {
password: "old-secret".into(),
..credential()
}),
Some(Uri::try_from(format!(
"sip:local@127.0.0.1:{}",
p.uac_port
))?),
transactions,
)?;
let mut snapshot = inner.snapshot();
snapshot.state = DialogSnapshotState::Confirmed;
snapshot.local_cseq = 42;
snapshot.remote_cseq = 17;
snapshot.remote_uri = Uri::try_from(format!("sip:peer@127.0.0.1:{}", p.uas_port))?;
snapshot.remote_contact = Some(Contact::new(format!("<{}>", snapshot.remote_uri)));
Ok(snapshot)
}
fn restored(p: &Peers, id: &DialogId) -> crate::dialog::invite_dialog::InviteDialog {
match p.uac_layer.get_dialog(id) {
Some(Dialog::Invite(dialog)) => dialog,
_ => panic!("restored INVITE dialog missing"),
}
}
fn digest(request: &Request, status: &StatusCode) -> Option<String> {
request
.headers
.iter()
.find_map(|header| match (status, header) {
(StatusCode::Unauthorized, Header::Authorization(value)) => {
Some(value.value().to_string())
}
(StatusCode::ProxyAuthenticationRequired, Header::ProxyAuthorization(value)) => {
Some(value.value().to_string())
}
_ => None,
})
}
async fn assert_restored_request_authenticates(method: Method) -> crate::Result<()> {
for role in [TransactionRole::Client, TransactionRole::Server] {
for status in [
StatusCode::Unauthorized,
StatusCode::ProxyAuthenticationRequired,
] {
let (p, mut incoming) = peers().await?;
let snapshot = snapshot(&p, role)?;
let (states, _) = unbounded_channel();
let cred = Credential {
auth_username: Some("trunk-auth".into()),
..credential()
};
assert!(p.uac_layer.restore_from_snapshot_with_credential(
snapshot.clone(),
states,
Some(cred.clone()),
)?);
let dialog = restored(&p, &snapshot.id);
let (seen_tx, mut seen) = unbounded_channel();
let challenged = status.clone();
let contact = Contact::new(format!("<{}>", snapshot.remote_uri));
let server_cred = cred.clone();
let server_method = method.clone();
tokio::spawn(async move {
while let Some(mut tx) = incoming.recv().await {
if tx.original.method != server_method {
continue;
}
let raw = digest(&tx.original, &challenged);
let valid = raw.as_ref().is_some_and(|raw| {
let auth = crate::sip::typed::Authorization::parse(raw).unwrap();
auth.username == server_cred.digest_username()
&& verify_digest(&auth, &server_cred.password, &server_method, raw)
});
seen_tx.send(tx.original.clone()).unwrap();
let challenged = challenged.clone();
let contact = contact.clone();
tokio::spawn(async move {
if valid {
tx.reply_with(StatusCode::OK, vec![contact.into()], None)
.await
.unwrap();
} else {
tx.reply_with(
challenged.clone(),
vec![challenge_header(&challenged)],
None,
)
.await
.unwrap();
}
while tx.receive().await.is_some() {}
});
}
});
let response = tokio::time::timeout(PROMPT, async {
match method {
Method::Invite => dialog.reinvite(None, None).await,
Method::Options => dialog.request(Method::Options, None, None).await,
Method::Bye => dialog.bye().await.map(|_| None),
_ => unreachable!(),
}
})
.await
.expect("restored request did not complete")?;
if method == Method::Bye {
assert!(dialog.state().is_terminated());
} else {
assert_eq!(response.map(|r| r.status_code), Some(StatusCode::OK));
assert!(dialog.state().is_confirmed());
}
let first = seen.try_recv().expect("first request");
let retry = seen.try_recv().expect("authenticated retry");
assert!(digest(&first, &status).is_none());
let raw = digest(&retry, &status).expect("matching authentication header");
let auth = crate::sip::typed::Authorization::parse(&raw)?;
assert_eq!(auth.username, cred.digest_username());
assert!(verify_digest(&auth, &cred.password, &method, &raw));
assert_eq!(first.cseq_header()?.seq()?, 43);
assert_eq!(retry.cseq_header()?.seq()?, 44);
assert_eq!(retry.uri, snapshot.remote_uri);
assert_eq!(dialog.id(), snapshot.id);
assert_eq!(dialog.snapshot().local_cseq, 44);
assert_eq!(dialog.snapshot().remote_cseq, snapshot.remote_cseq);
assert!(seen.try_recv().is_err(), "unexpected further retry");
p.token.cancel();
}
}
Ok(())
}
#[tokio::test]
async fn restored_options_authenticates_for_both_roles() -> crate::Result<()> {
assert_restored_request_authenticates(Method::Options).await
}
#[tokio::test]
async fn restored_reinvite_authenticates_for_both_roles() -> crate::Result<()> {
assert_restored_request_authenticates(Method::Invite).await
}
#[tokio::test]
async fn restored_bye_authenticates_for_both_roles() -> crate::Result<()> {
assert_restored_request_authenticates(Method::Bye).await
}
#[tokio::test]
async fn legacy_and_none_restore_leave_credentials_unset() -> crate::Result<()> {
for role in [TransactionRole::Client, TransactionRole::Server] {
let (p, _) = peers().await?;
let snapshot = snapshot(&p, role)?;
let (states, _) = unbounded_channel();
assert!(p
.uac_layer
.restore_from_snapshot(snapshot.clone(), states.clone())?);
assert!(restored(&p, &snapshot.id).inner.credential.is_none());
p.uac_layer.remove_dialog(&snapshot.id);
assert!(p.uac_layer.restore_from_snapshot_with_credential(
snapshot.clone(),
states,
None,
)?);
assert!(restored(&p, &snapshot.id).inner.credential.is_none());
p.token.cancel();
}
Ok(())
}
#[tokio::test]
async fn skipped_restore_keeps_existing_credentials_and_state() -> crate::Result<()> {
for role in [TransactionRole::Client, TransactionRole::Server] {
let (p, _) = peers().await?;
let mut snapshot = snapshot(&p, role)?;
let (states, _) = unbounded_channel();
snapshot.state = DialogSnapshotState::Early;
assert!(!p.uac_layer.restore_from_snapshot_with_credential(
snapshot.clone(),
states.clone(),
Some(credential()),
)?);
assert!(p.uac_layer.is_empty());
snapshot.state = DialogSnapshotState::Confirmed;
assert!(p.uac_layer.restore_from_snapshot_with_credential(
snapshot.clone(),
states.clone(),
Some(credential()),
)?);
let live = restored(&p, &snapshot.id);
let seq = live.inner.increment_local_seq();
assert!(!p.uac_layer.restore_from_snapshot_with_credential(
snapshot.clone(),
states.clone(),
Some(Credential {
password: "replacement".into(),
..credential()
}),
)?);
let retained = restored(&p, &snapshot.id);
assert!(Arc::ptr_eq(&live.inner, &retained.inner));
assert_eq!(
retained.inner.credential.as_ref().unwrap().password,
"secret"
);
assert_eq!(retained.snapshot().local_cseq, seq);
let next_snapshot = retained.snapshot();
p.uac_layer.remove_dialog(&snapshot.id);
assert!(p.uac_layer.restore_from_snapshot(next_snapshot, states)?);
assert!(restored(&p, &snapshot.id).inner.credential.is_none());
p.token.cancel();
}
Ok(())
}
}