Skip to content

Commit 26a6bf4

Browse files
committed
fix tests
1 parent ddb4b3b commit 26a6bf4

10 files changed

Lines changed: 96 additions & 95 deletions

File tree

examples/client/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use rsipstack::dialog::dialog_layer::DialogLayer;
77
use rsipstack::dialog::invitation::InviteOption;
88
use rsipstack::dialog::server_dialog::ServerInviteDialog;
99
use rsipstack::transaction::endpoint::EndpointInnerRef;
10-
use rsipstack::transaction::key::TransactionRole;
1110
use rsipstack::Result;
1211
use rsipstack::{
1312
dialog::{authenticate::Credential, registration::Registration},

src/dialog/dialog.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ impl TransactionHandle {
105105
/// # fn example() {
106106
/// # let dialog_id = DialogId {
107107
/// # call_id: "test@example.com".to_string(),
108-
/// # from_tag: "from-tag".to_string(),
109-
/// # to_tag: "to-tag".to_string(),
108+
/// # local_tag: "from-tag".to_string(),
109+
/// # remote_tag: "to-tag".to_string(),
110110
/// # };
111111
/// let state = DialogState::Confirmed(dialog_id, rsip::Response::default());
112112
/// if state.is_confirmed() {

src/dialog/dialog_layer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ pub type DialogLayerInnerRef = Arc<DialogLayerInner>;
9393
/// # async fn example() -> rsipstack::Result<()> {
9494
/// # let dialog_layer: DialogLayer = todo!();
9595
/// # let request = todo!();
96-
/// # let transaction = todo!();
96+
/// # let mut transaction = todo!();
9797
/// // Find existing dialog for incoming request
98-
/// if let Some(mut dialog) = dialog_layer.match_dialog(&request) {
98+
/// if let Some(mut dialog) = dialog_layer.match_dialog(&transaction) {
9999
/// // Route to existing dialog
100-
/// dialog.handle(transaction).await?;
100+
/// dialog.handle(&mut transaction).await?;
101101
/// } else {
102102
/// // Create new dialog or reject
103103
/// }

src/dialog/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ mod tests;
2828
/// # Fields
2929
///
3030
/// * `call_id` - The Call-ID header field value from SIP messages, identifying a call session
31-
/// * `from_tag` - The tag parameter from the From header field, identifying the dialog initiator
32-
/// * `to_tag` - The tag parameter from the To header field, identifying the dialog recipient
31+
/// * `local_tag` - The local tag for this endpoint (From tag for client role, To tag for server role)
32+
/// * `remote_tag` - The remote tag for the peer (To tag for client role, From tag for server role)
3333
///
3434
/// # Examples
3535
///
@@ -38,16 +38,16 @@ mod tests;
3838
///
3939
/// let dialog_id = DialogId {
4040
/// call_id: "1234567890@example.com".to_string(),
41-
/// from_tag: "alice-tag-123".to_string(),
42-
/// to_tag: "bob-tag-456".to_string(),
41+
/// local_tag: "alice-tag-123".to_string(),
42+
/// remote_tag: "bob-tag-456".to_string(),
4343
/// };
4444
///
4545
/// println!("Dialog ID: {}", dialog_id);
4646
/// ```
4747
///
4848
/// # Notes
4949
///
50-
/// - During early dialog establishment, `to_tag` may be an empty string
50+
/// - During early dialog establishment, `remote_tag` may be an empty string
5151
/// - Dialog ID remains constant throughout the dialog lifetime
5252
/// - Used for managing and routing SIP messages at the dialog layer
5353
#[derive(Clone, Debug, Hash, PartialEq, Eq)]

src/dialog/tests/test_client_dialog.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ async fn test_client_dialog_creation() -> crate::Result<()> {
5555

5656
let dialog_id = DialogId {
5757
call_id: "test-call-id".to_string(),
58-
from_tag: "alice-tag".to_string(),
59-
to_tag: "bob-tag".to_string(),
58+
local_tag: "alice-tag".to_string(),
59+
remote_tag: "bob-tag".to_string(),
6060
};
6161

6262
let invite_req = create_invite_request("alice-tag", "", "test-call-id");
@@ -90,8 +90,8 @@ async fn test_client_dialog_sequence_handling() -> crate::Result<()> {
9090

9191
let dialog_id = DialogId {
9292
call_id: "test-call-seq".to_string(),
93-
from_tag: "alice-tag".to_string(),
94-
to_tag: "bob-tag".to_string(),
93+
local_tag: "alice-tag".to_string(),
94+
remote_tag: "bob-tag".to_string(),
9595
};
9696

9797
let invite_req = create_invite_request("alice-tag", "bob-tag", "test-call-seq");
@@ -130,8 +130,8 @@ async fn test_client_dialog_state_transitions() -> crate::Result<()> {
130130

131131
let dialog_id = DialogId {
132132
call_id: "test-call-flow".to_string(),
133-
from_tag: "alice-tag".to_string(),
134-
to_tag: "".to_string(),
133+
local_tag: "alice-tag".to_string(),
134+
remote_tag: "".to_string(),
135135
};
136136

137137
let invite_req = create_invite_request("alice-tag", "", "test-call-flow");
@@ -208,8 +208,8 @@ async fn test_client_dialog_termination_scenarios() -> crate::Result<()> {
208208
// Test 1: Early termination (before confirmed)
209209
let dialog_id_1 = DialogId {
210210
call_id: "test-call-term-early".to_string(),
211-
from_tag: "alice-tag".to_string(),
212-
to_tag: "".to_string(),
211+
local_tag: "alice-tag".to_string(),
212+
remote_tag: "".to_string(),
213213
};
214214

215215
let invite_req_1 = create_invite_request("alice-tag", "", "test-call-term-early");
@@ -245,8 +245,8 @@ async fn test_client_dialog_termination_scenarios() -> crate::Result<()> {
245245
// Test 2: Normal termination after confirmed
246246
let dialog_id_2 = DialogId {
247247
call_id: "test-call-term-normal".to_string(),
248-
from_tag: "alice-tag".to_string(),
249-
to_tag: "bob-tag".to_string(),
248+
local_tag: "alice-tag".to_string(),
249+
remote_tag: "bob-tag".to_string(),
250250
};
251251

252252
let invite_req_2 = create_invite_request("alice-tag", "bob-tag", "test-call-term-normal");
@@ -294,8 +294,8 @@ async fn test_make_request_preserves_remote_target_and_route_order() -> crate::R
294294

295295
let dialog_id = DialogId {
296296
call_id: "route-order-call".to_string(),
297-
from_tag: "from-tag".to_string(),
298-
to_tag: "to-tag".to_string(),
297+
local_tag: "from-tag".to_string(),
298+
remote_tag: "to-tag".to_string(),
299299
};
300300

301301
let invite_req = create_invite_request("from-tag", "to-tag", "route-order-call");
@@ -378,8 +378,8 @@ async fn test_route_set_updates_from_200_ok_response() -> crate::Result<()> {
378378

379379
let dialog_id = DialogId {
380380
call_id: "route-update-call".to_string(),
381-
from_tag: "from-tag".to_string(),
382-
to_tag: "".to_string(),
381+
local_tag: "from-tag".to_string(),
382+
remote_tag: "".to_string(),
383383
};
384384

385385
let invite_req = create_invite_request("from-tag", "", "route-update-call");

src/dialog/tests/test_dialog_layer.rs

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ async fn test_server_invite_dialog_creation() -> crate::Result<()> {
103103
// Dialog ID should have generated to-tag
104104
let dialog_id = dialog.id();
105105
assert_eq!(dialog_id.call_id, "call-id-456");
106-
assert_eq!(dialog_id.from_tag, "alice-tag-123");
107-
assert!(!dialog_id.to_tag.is_empty());
106+
assert_eq!(dialog_id.remote_tag, "alice-tag-123");
107+
assert!(!dialog_id.local_tag.is_empty());
108108

109109
Ok(())
110110
}
@@ -139,7 +139,7 @@ async fn test_existing_server_invite_dialog_retrieval() -> crate::Result<()> {
139139
// Second request with same dialog identifiers should retrieve existing dialog
140140
let invite_req2 = create_invite_request(
141141
"alice-tag-123",
142-
&dialog_id.to_tag,
142+
&dialog_id.local_tag,
143143
"call-id-456",
144144
"z9hG4bKnashds2",
145145
);
@@ -173,7 +173,7 @@ async fn test_dialog_retrieval_and_matching() -> crate::Result<()> {
173173
key,
174174
invite_req.clone(),
175175
endpoint.inner.clone(),
176-
Some(mock_conn),
176+
Some(mock_conn.clone()),
177177
);
178178

179179
let (state_sender, _) = unbounded_channel();
@@ -196,15 +196,16 @@ async fn test_dialog_retrieval_and_matching() -> crate::Result<()> {
196196
method: rsip::Method::Bye,
197197
uri: rsip::Uri::try_from("sip:bob@example.com:5060")?,
198198
headers: vec![
199+
Via::new("SIP/2.0/UDP alice.example.com:5060;branch=z9hG4bKbye").into(),
199200
CSeq::new("2 BYE").into(),
200201
From::new(&format!(
201202
"Alice <sip:alice@example.com>;tag={}",
202-
dialog_id.from_tag
203+
dialog_id.remote_tag
203204
))
204205
.into(),
205206
To::new(&format!(
206207
"Bob <sip:bob@example.com>;tag={}",
207-
dialog_id.to_tag
208+
dialog_id.local_tag
208209
))
209210
.into(),
210211
CallId::new(&dialog_id.call_id).into(),
@@ -214,7 +215,9 @@ async fn test_dialog_retrieval_and_matching() -> crate::Result<()> {
214215
body: vec![],
215216
};
216217

217-
let matched_dialog = dialog_layer.match_dialog(&bye_req);
218+
let bye_key = TransactionKey::from_request(&bye_req, TransactionRole::Server)?;
219+
let bye_tx = Transaction::new_server(bye_key, bye_req, endpoint.inner.clone(), Some(mock_conn));
220+
let matched_dialog = dialog_layer.match_dialog(&bye_tx);
218221
assert!(matched_dialog.is_some());
219222

220223
Ok(())
@@ -281,13 +284,13 @@ async fn test_dialog_layer_with_swapped_tags() -> crate::Result<()> {
281284
// Create a swapped dialog ID (as if from the other perspective)
282285
let swapped_id = DialogId {
283286
call_id: dialog_id.call_id.clone(),
284-
from_tag: dialog_id.to_tag.clone(),
285-
to_tag: dialog_id.from_tag.clone(),
287+
local_tag: dialog_id.remote_tag.clone(),
288+
remote_tag: dialog_id.local_tag.clone(),
286289
};
287290

288-
// Should be able to find dialog with swapped tags
291+
// Swapped tags should NOT match the server-side dialog ID
289292
let found_dialog = dialog_layer.get_dialog(&swapped_id);
290-
assert!(found_dialog.is_some());
293+
assert!(found_dialog.is_none());
291294

292295
Ok(())
293296
}
@@ -329,8 +332,8 @@ async fn test_multiple_dialogs_management() -> crate::Result<()> {
329332
// Remove one dialog
330333
let _test_id = DialogId {
331334
call_id: "test-call-2".to_string(),
332-
from_tag: "alice-tag-2".to_string(),
333-
to_tag: "".to_string(), // We need to find the actual dialog first
335+
local_tag: "".to_string(),
336+
remote_tag: "alice-tag-2".to_string(), // We need to find the actual dialog first
334337
};
335338

336339
// Find all dialogs to get the actual IDs
@@ -340,13 +343,20 @@ async fn test_multiple_dialogs_management() -> crate::Result<()> {
340343
let from_tag = format!("alice-tag-{}", i);
341344
let _partial_id = DialogId {
342345
call_id: call_id.clone(),
343-
from_tag: from_tag.clone(),
344-
to_tag: "".to_string(),
346+
local_tag: "".to_string(),
347+
remote_tag: from_tag.clone(),
345348
};
346349

347350
// Try to find dialog by creating a request and matching
348351
let test_req = create_invite_request(&from_tag, "", &call_id, "test-branch");
349-
if let Some(dialog) = dialog_layer.match_dialog(&test_req) {
352+
let test_key = TransactionKey::from_request(&test_req, TransactionRole::Server)?;
353+
let test_tx = Transaction::new_server(
354+
test_key,
355+
test_req,
356+
endpoint.inner.clone(),
357+
Some(mock_conn.clone()),
358+
);
359+
if let Some(dialog) = dialog_layer.match_dialog(&test_tx) {
350360
dialog_ids.push(dialog.id());
351361
}
352362
}

src/dialog/tests/test_dialog_states.rs

Lines changed: 30 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -72,30 +72,22 @@ pub async fn create_test_endpoint() -> crate::Result<crate::transaction::endpoin
7272
fn test_dialog_id_eq() {
7373
let dialog_id_1 = DialogId {
7474
call_id: "test-call-id-123".to_string(),
75-
from_tag: "456".to_string(),
76-
to_tag: "789".to_string(),
75+
local_tag: "456".to_string(),
76+
remote_tag: "789".to_string(),
7777
};
78-
assert!("456" < "789");
79-
assert_eq!(dialog_id_1.to_string(), "test-call-id-123-789-456");
80-
let dialog_id_2 = DialogId {
81-
call_id: "test-call-id-123".to_string(),
82-
from_tag: "789".to_string(),
83-
to_tag: "456".to_string(),
84-
};
85-
assert_eq!(dialog_id_2.to_string(), "test-call-id-123-789-456");
86-
assert_eq!(dialog_id_1, dialog_id_2);
78+
assert_eq!(dialog_id_1.to_string(), "test-call-id-123-456-789");
8779

88-
let dialog_id_3 = DialogId {
80+
let dialog_id_4 = DialogId {
8981
call_id: "mock".to_string(),
90-
from_tag: "M3wnsBf".to_string(),
91-
to_tag: "1NyRqPt1".to_string(),
82+
local_tag: "M3wnsBf".to_string(),
83+
remote_tag: "1NyRqPt1".to_string(),
9284
};
93-
let dialog_id_4 = DialogId {
85+
let dialog_id_5 = DialogId {
9486
call_id: "mock".to_string(),
95-
from_tag: "1NyRqPt1".to_string(),
96-
to_tag: "M3wnsBf".to_string(),
87+
local_tag: "1NyRqPt1".to_string(),
88+
remote_tag: "M3wnsBf".to_string(),
9789
};
98-
assert_eq!(dialog_id_3, dialog_id_4);
90+
assert_ne!(dialog_id_4, dialog_id_5);
9991
}
10092
#[tokio::test]
10193
async fn test_dialog_state_transitions() -> crate::Result<()> {
@@ -105,8 +97,8 @@ async fn test_dialog_state_transitions() -> crate::Result<()> {
10597
// Create dialog ID
10698
let dialog_id = DialogId {
10799
call_id: "test-call-id-123".to_string(),
108-
from_tag: "alice-tag-456".to_string(),
109-
to_tag: "bob-tag-789".to_string(),
100+
local_tag: "alice-tag-456".to_string(),
101+
remote_tag: "bob-tag-789".to_string(),
110102
};
111103

112104
// Create INVITE request
@@ -173,8 +165,8 @@ async fn test_server_dialog_state_transitions() -> crate::Result<()> {
173165
// Create dialog ID
174166
let dialog_id = DialogId {
175167
call_id: "test-call-id-server-123".to_string(),
176-
from_tag: "alice-tag-456".to_string(),
177-
to_tag: "bob-tag-789".to_string(),
168+
local_tag: "bob-tag-789".to_string(),
169+
remote_tag: "alice-tag-456".to_string(),
178170
};
179171

180172
// Create INVITE request
@@ -230,8 +222,8 @@ async fn test_dialog_in_dialog_requests() -> crate::Result<()> {
230222
// Create dialog ID
231223
let dialog_id = DialogId {
232224
call_id: "test-call-id-in-dialog-123".to_string(),
233-
from_tag: "alice-tag-456".to_string(),
234-
to_tag: "bob-tag-789".to_string(),
225+
local_tag: "alice-tag-456".to_string(),
226+
remote_tag: "bob-tag-789".to_string(),
235227
};
236228

237229
// Create initial INVITE request
@@ -329,8 +321,8 @@ async fn test_dialog_termination_scenarios() -> crate::Result<()> {
329321
// Test 1: Termination with error status code
330322
let dialog_id_1 = DialogId {
331323
call_id: "test-call-id-term-1".to_string(),
332-
from_tag: "alice-tag-456".to_string(),
333-
to_tag: "bob-tag-789".to_string(),
324+
local_tag: "alice-tag-456".to_string(),
325+
remote_tag: "bob-tag-789".to_string(),
334326
};
335327

336328
let invite_req_1 = create_invite_request("alice-tag-456", "", "test-call-id-term-1");
@@ -361,8 +353,8 @@ async fn test_dialog_termination_scenarios() -> crate::Result<()> {
361353
// Test 2: Normal termination (BYE)
362354
let dialog_id_2 = DialogId {
363355
call_id: "test-call-id-term-2".to_string(),
364-
from_tag: "alice-tag-456".to_string(),
365-
to_tag: "bob-tag-789".to_string(),
356+
local_tag: "alice-tag-456".to_string(),
357+
remote_tag: "bob-tag-789".to_string(),
366358
};
367359

368360
let invite_req_2 = create_invite_request("alice-tag-456", "bob-tag-789", "test-call-id-term-2");
@@ -404,8 +396,8 @@ async fn test_dialog_sequence_numbers() -> crate::Result<()> {
404396

405397
let dialog_id = DialogId {
406398
call_id: "test-call-id-seq-123".to_string(),
407-
from_tag: "alice-tag-456".to_string(),
408-
to_tag: "bob-tag-789".to_string(),
399+
local_tag: "alice-tag-456".to_string(),
400+
remote_tag: "bob-tag-789".to_string(),
409401
};
410402

411403
let invite_req = create_invite_request("alice-tag-456", "bob-tag-789", "test-call-id-seq-123");
@@ -438,8 +430,8 @@ async fn test_dialog_sequence_numbers() -> crate::Result<()> {
438430
async fn test_dialog_state_display() -> crate::Result<()> {
439431
let dialog_id = DialogId {
440432
call_id: "test-call-id-display".to_string(),
441-
from_tag: "alice-tag".to_string(),
442-
to_tag: "bob-tag".to_string(),
433+
local_tag: "alice-tag".to_string(),
434+
remote_tag: "bob-tag".to_string(),
443435
};
444436

445437
// Test all state display formats
@@ -464,10 +456,10 @@ async fn test_dialog_state_display() -> crate::Result<()> {
464456
async fn test_dialog_id_creation() -> crate::Result<()> {
465457
// Test from Request
466458
let request = create_invite_request("alice-tag-123", "", "call-id-456");
467-
let dialog_id = DialogId::try_from(&request)?;
459+
let dialog_id = DialogId::try_from((&request, TransactionRole::Client))?;
468460
assert_eq!(dialog_id.call_id, "call-id-456");
469-
assert_eq!(dialog_id.from_tag, "alice-tag-123");
470-
assert_eq!(dialog_id.to_tag, "");
461+
assert_eq!(dialog_id.local_tag, "alice-tag-123");
462+
assert_eq!(dialog_id.remote_tag, "");
471463

472464
// Test from Response
473465
let response = create_response(
@@ -476,10 +468,10 @@ async fn test_dialog_id_creation() -> crate::Result<()> {
476468
"bob-tag-789",
477469
"call-id-456",
478470
);
479-
let dialog_id_resp = DialogId::try_from(&response)?;
471+
let dialog_id_resp = DialogId::try_from((&response, TransactionRole::Client))?;
480472
assert_eq!(dialog_id_resp.call_id, "call-id-456");
481-
assert_eq!(dialog_id_resp.from_tag, "alice-tag-123");
482-
assert_eq!(dialog_id_resp.to_tag, "bob-tag-789");
473+
assert_eq!(dialog_id_resp.local_tag, "alice-tag-123");
474+
assert_eq!(dialog_id_resp.remote_tag, "bob-tag-789");
483475

484476
// Test display
485477
let display_str = dialog_id_resp.to_string();

0 commit comments

Comments
 (0)