Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ sea-orm = { version = "2", features = [
"sqlx-sqlite",
"sqlx-mysql",
"sqlx-postgres",
"mock",
] }
sea-orm-migration = { version = "2", features = [
"runtime-tokio-rustls",
Expand Down
46 changes: 43 additions & 3 deletions src/proxy/locator_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,8 @@ impl Locator for DbLocator {
active_model.instance_id = Set(location.instance_id.clone());

// Insert without specifying id
active_model
.insert(&self.db)
Entity::insert(active_model)
.exec(&self.db)
.await
.map_err(|e| anyhow::anyhow!("Database error on register insert: {}", e))?;
}
Expand Down Expand Up @@ -792,8 +792,48 @@ impl Locator for DbLocator {
#[cfg(test)]
mod tests {
use super::*;
use rsipstack::sip::transport::Transport;
use rsipstack::sip::{Auth, HostWithPort, Scheme, transport::Transport};
use rsipstack::transport::SipAddr;
use sea_orm::{DbBackend, MockDatabase, MockExecResult};

#[tokio::test]
async fn register_succeeds_when_inserted_row_is_not_immediately_visible() {
let db = MockDatabase::new(DbBackend::MySql)
.append_query_results([Vec::<Model>::new(), Vec::<Model>::new()])
.append_exec_results([MockExecResult {
last_insert_id: 1,
rows_affected: 1,
}])
.into_connection();
let locator = DbLocator {
db,
realm_checker: Mutex::new(None),
};
let location = Location {
aor: rsipstack::sip::Uri {
scheme: Some(Scheme::Sip),
auth: Some(Auth {
user: "alice".to_string(),
password: None,
}),
host_with_port: HostWithPort::try_from("client.example.com")
.expect("valid aor host"),
params: vec![],
headers: vec![],
},
expires: 60,
destination: Some(SipAddr {
r#type: Some(Transport::Udp),
addr: "192.0.2.10:5060".try_into().expect("valid destination"),
}),
..Default::default()
};

locator
.register("alice", Some("pbx.example.com"), location)
.await
.expect("successful insert must complete registration");
}

#[tokio::test]
async fn register_prefers_destination_transport_for_websocket_connections() {
Expand Down
Loading