Use a p2p dbus connection during tests
This removes the requirement of having the DBus daemon running locally, which is particularly helpful e.g. in a container or for CI.
This commit is contained in:
parent
256267c213
commit
20072cf1ea
5 changed files with 101 additions and 64 deletions
|
@ -36,14 +36,30 @@ pub async fn restrictions_for(user: Uid) -> anyhow::Result<Vec<Restriction>, any
|
|||
|
||||
#[cfg(feature = "integration_test")]
|
||||
let proxy = {
|
||||
use tokio::net::UnixStream;
|
||||
|
||||
// During integration testing, we want to connect to a private
|
||||
// bus name to avoid clashes with existing system services.
|
||||
let connection = zbus::Connection::session().await?;
|
||||
let dbus_name = std::env::var("TEST_DBUS_SERVICE_NAME")
|
||||
.expect("The test has not set the TEST_DBUS_SERVICE_NAME environment variable to the private bus name prior to attempting name resolution");
|
||||
let socket_path = std::env::var("TEST_DBUS_SOCKET")
|
||||
.expect("The test has not set the TEST_DBUS_SOCKET environment variable to the unix socket to connect to");
|
||||
|
||||
let socket = loop {
|
||||
match UnixStream::connect(&socket_path).await {
|
||||
Ok(stream) => break stream,
|
||||
Err(e) if e.kind() == std::io::ErrorKind::ConnectionRefused => {
|
||||
tokio::task::yield_now().await;
|
||||
continue;
|
||||
}
|
||||
Err(e) => anyhow::bail!(e),
|
||||
}
|
||||
};
|
||||
|
||||
let connection = zbus::ConnectionBuilder::unix_stream(socket)
|
||||
.p2p()
|
||||
.build()
|
||||
.await?;
|
||||
|
||||
MalcontentDnsProxy::builder(&connection)
|
||||
.destination(zbus_names::UniqueName::try_from(dbus_name).unwrap())
|
||||
.unwrap()
|
||||
.build()
|
||||
.await
|
||||
.expect("Unable to build DBus proxy object")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue