diff --git a/src/config.rs b/src/config.rs
index a3e0305..3437aaa 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -639,10 +639,14 @@ mod tests {
"#;
let busconfig = Config::parse(input).expect("should parse XML input");
- let want = HashSet::from_iter([String::from("ANONYMOUS"), String::from("EXTERNAL")]);
- let diff = busconfig.auth.symmetric_difference(&want);
- assert_eq!(diff.count(), 0);
+ assert_eq!(
+ busconfig,
+ Config {
+ auth: HashSet::from_iter([String::from("ANONYMOUS"), String::from("EXTERNAL")]),
+ ..Default::default()
+ }
+ );
}
#[test]
diff --git a/tests/config.rs b/tests/config.rs
index 25dcc92..7b6f760 100644
--- a/tests/config.rs
+++ b/tests/config.rs
@@ -1,6 +1,9 @@
-use std::collections::HashSet;
+use std::{collections::HashSet, path::PathBuf};
-use busd::config::{Access, Config, Name, Operation, OwnOperation, Policy};
+use busd::config::{
+ Access, BusType, Config, ConnectOperation, MessageType, Name, Operation, OwnOperation, Policy,
+ ReceiveOperation, SendOperation,
+};
#[test]
fn config_read_file_with_includes_ok() {
@@ -53,6 +56,385 @@ fn config_read_file_with_includes_ok() {
);
}
+#[test]
+fn config_read_file_example_session_disable_stats_conf_ok() {
+ let got = Config::read_file("./tests/fixtures/example-session-disable-stats.conf")
+ .expect("should read and parse XML input");
+
+ assert_eq!(
+ got,
+ Config {
+ policies: vec![Policy::DefaultContext(vec![(
+ Access::Deny,
+ Operation::Send(SendOperation {
+ broadcast: None,
+ destination: Some(Name::Exact(String::from("org.freedesktop.DBus"))),
+ error: None,
+ interface: Some(String::from("org.freedesktop.DBus.Debug.Stats")),
+ max_fds: None,
+ min_fds: None,
+ path: None,
+ r#type: None
+ }),
+ ),]),],
+ ..Default::default()
+ }
+ );
+}
+
+#[test]
+fn config_read_file_example_system_enable_stats_conf_ok() {
+ let got = Config::read_file("./tests/fixtures/example-system-enable-stats.conf")
+ .expect("should read and parse XML input");
+
+ assert_eq!(
+ got,
+ Config {
+ policies: vec![Policy::User(
+ vec![(
+ Access::Allow,
+ Operation::Send(SendOperation {
+ broadcast: None,
+ destination: Some(Name::Exact(String::from("org.freedesktop.DBus"))),
+ error: None,
+ interface: Some(String::from("org.freedesktop.DBus.Debug.Stats")),
+ max_fds: None,
+ min_fds: None,
+ path: None,
+ r#type: None
+ }),
+ )],
+ String::from("USERNAME"),
+ ),],
+ ..Default::default()
+ }
+ );
+}
+
+#[test]
+fn config_read_file_session_conf_ok() {
+ let mut got = Config::read_file("./tests/fixtures/session.conf")
+ .expect("should read and parse XML input");
+
+ assert!(!got.servicedirs.is_empty());
+
+ // nuking this to make it easier to `assert_eq!()`
+ got.servicedirs = vec![];
+
+ assert_eq!(
+ got,
+ Config {
+ listen: HashSet::from_iter(vec![String::from("@DBUS_SESSION_BUS_LISTEN_ADDRESS@"),]),
+ keep_umask: true,
+ policies: vec![Policy::DefaultContext(vec![
+ (
+ Access::Allow,
+ Operation::Send(SendOperation {
+ broadcast: None,
+ destination: Some(Name::Any),
+ error: None,
+ interface: None,
+ max_fds: None,
+ min_fds: None,
+ path: None,
+ r#type: None,
+ }),
+ ),
+ (
+ Access::Allow,
+ Operation::Own(OwnOperation {
+ own: Some(Name::Any),
+ }),
+ ),
+ ]),],
+ r#type: Some(BusType::Session),
+ ..Default::default()
+ }
+ );
+}
+
+#[test]
+fn config_read_file_system_conf_ok() {
+ let want = Config {
+ auth: HashSet::from_iter(vec![String::from("EXTERNAL")]),
+ fork: true,
+ listen: HashSet::from_iter(vec![String::from("@DBUS_SYSTEM_BUS_DEFAULT_ADDRESS@")]),
+ pidfile: Some(PathBuf::from("@DBUS_SYSTEM_PID_FILE@")),
+ policies: vec![
+ Policy::DefaultContext(vec![
+ (
+ Access::Allow,
+ Operation::Connect(ConnectOperation {
+ group: None,
+ user: Some(String::from("*")),
+ }),
+ ),
+ (
+ Access::Deny,
+ Operation::Own(OwnOperation {
+ own: Some(Name::Any),
+ }),
+ ),
+ (
+ Access::Deny,
+ Operation::Send(SendOperation {
+ broadcast: None,
+ destination: None,
+ error: None,
+ interface: None,
+ max_fds: None,
+ min_fds: None,
+ path: None,
+ r#type: Some(MessageType::MethodCall),
+ }),
+ ),
+ (
+ Access::Allow,
+ Operation::Send(SendOperation {
+ broadcast: None,
+ destination: None,
+ error: None,
+ interface: None,
+ max_fds: None,
+ min_fds: None,
+ path: None,
+ r#type: Some(MessageType::Signal),
+ }),
+ ),
+ (
+ Access::Allow,
+ Operation::Send(SendOperation {
+ broadcast: None,
+ destination: None,
+ error: None,
+ interface: None,
+ max_fds: None,
+ min_fds: None,
+ path: None,
+ r#type: Some(MessageType::MethodReturn),
+ }),
+ ),
+ (
+ Access::Allow,
+ Operation::Send(SendOperation {
+ broadcast: None,
+ destination: None,
+ error: None,
+ interface: None,
+ max_fds: None,
+ min_fds: None,
+ path: None,
+ r#type: Some(MessageType::Error),
+ }),
+ ),
+ (
+ Access::Allow,
+ Operation::Receive(ReceiveOperation {
+ error: None,
+ interface: None,
+ max_fds: None,
+ min_fds: None,
+ path: None,
+ sender: None,
+ r#type: Some(MessageType::MethodCall),
+ }),
+ ),
+ (
+ Access::Allow,
+ Operation::Receive(ReceiveOperation {
+ error: None,
+ interface: None,
+ max_fds: None,
+ min_fds: None,
+ path: None,
+ sender: None,
+ r#type: Some(MessageType::MethodReturn),
+ }),
+ ),
+ (
+ Access::Allow,
+ Operation::Receive(ReceiveOperation {
+ error: None,
+ interface: None,
+ max_fds: None,
+ min_fds: None,
+ path: None,
+ sender: None,
+ r#type: Some(MessageType::Error),
+ }),
+ ),
+ (
+ Access::Allow,
+ Operation::Receive(ReceiveOperation {
+ error: None,
+ interface: None,
+ max_fds: None,
+ min_fds: None,
+ path: None,
+ sender: None,
+ r#type: Some(MessageType::Signal),
+ }),
+ ),
+ (
+ Access::Allow,
+ Operation::Send(SendOperation {
+ broadcast: None,
+ destination: Some(Name::Exact(String::from("org.freedesktop.DBus"))),
+ error: None,
+ interface: Some(String::from("org.freedesktop.DBus")),
+ max_fds: None,
+ min_fds: None,
+ path: None,
+ r#type: None,
+ }),
+ ),
+ (
+ Access::Allow,
+ Operation::Send(SendOperation {
+ broadcast: None,
+ destination: Some(Name::Exact(String::from("org.freedesktop.DBus"))),
+ error: None,
+ interface: Some(String::from("org.freedesktop.DBus.Introspectable")),
+ max_fds: None,
+ min_fds: None,
+ path: None,
+ r#type: None,
+ }),
+ ),
+ (
+ Access::Allow,
+ Operation::Send(SendOperation {
+ broadcast: None,
+ destination: Some(Name::Exact(String::from("org.freedesktop.DBus"))),
+ error: None,
+ interface: Some(String::from("org.freedesktop.DBus.Properties")),
+ max_fds: None,
+ min_fds: None,
+ path: None,
+ r#type: None,
+ }),
+ ),
+ (
+ Access::Allow,
+ Operation::Send(SendOperation {
+ broadcast: None,
+ destination: Some(Name::Exact(String::from("org.freedesktop.DBus"))),
+ error: None,
+ interface: Some(String::from("org.freedesktop.DBus.Containers1")),
+ max_fds: None,
+ min_fds: None,
+ path: None,
+ r#type: None,
+ }),
+ ),
+ (
+ // TODO: this is a mistake, deny with send_member rule should be omitted
+ Access::Deny,
+ Operation::Send(SendOperation {
+ broadcast: None,
+ destination: Some(Name::Exact(String::from("org.freedesktop.DBus"))),
+ error: None,
+ interface: Some(String::from("org.freedesktop.DBus")),
+ max_fds: None,
+ min_fds: None,
+ path: None,
+ r#type: None,
+ }),
+ ),
+ (
+ Access::Deny,
+ Operation::Send(SendOperation {
+ broadcast: None,
+ destination: Some(Name::Exact(String::from("org.freedesktop.DBus"))),
+ error: None,
+ interface: Some(String::from("org.freedesktop.DBus.Debug.Stats")),
+ max_fds: None,
+ min_fds: None,
+ path: None,
+ r#type: None,
+ }),
+ ),
+ (
+ Access::Deny,
+ Operation::Send(SendOperation {
+ broadcast: None,
+ destination: Some(Name::Exact(String::from("org.freedesktop.DBus"))),
+ error: None,
+ interface: Some(String::from("org.freedesktop.systemd1.Activator")),
+ max_fds: None,
+ min_fds: None,
+ path: None,
+ r#type: None,
+ }),
+ ),
+ ]),
+ Policy::User(
+ vec![(
+ Access::Allow,
+ Operation::Send(SendOperation {
+ broadcast: None,
+ destination: Some(Name::Exact(String::from("org.freedesktop.DBus"))),
+ error: None,
+ interface: Some(String::from("org.freedesktop.systemd1.Activator")),
+ max_fds: None,
+ min_fds: None,
+ path: None,
+ r#type: None,
+ }),
+ )],
+ String::from("root"),
+ ),
+ Policy::User(
+ vec![(
+ Access::Allow,
+ Operation::Send(SendOperation {
+ broadcast: None,
+ destination: Some(Name::Exact(String::from("org.freedesktop.DBus"))),
+ error: None,
+ interface: Some(String::from("org.freedesktop.DBus.Monitoring")),
+ max_fds: None,
+ min_fds: None,
+ path: None,
+ r#type: None,
+ }),
+ )],
+ String::from("root"),
+ ),
+ Policy::User(
+ vec![(
+ Access::Allow,
+ Operation::Send(SendOperation {
+ broadcast: None,
+ destination: Some(Name::Exact(String::from("org.freedesktop.DBus"))),
+ error: None,
+ interface: Some(String::from("org.freedesktop.DBus.Debug.Stats")),
+ max_fds: None,
+ min_fds: None,
+ path: None,
+ r#type: None,
+ }),
+ )],
+ String::from("root"),
+ ),
+ ],
+ servicehelper: Some(PathBuf::from("@DBUS_LIBEXECDIR@/dbus-daemon-launch-helper")),
+ syslog: true,
+ r#type: Some(BusType::System),
+ user: Some(String::from("@DBUS_USER@")),
+ ..Default::default()
+ };
+
+ let mut got =
+ Config::read_file("./tests/fixtures/system.conf").expect("should read and parse XML input");
+
+ assert!(!got.servicedirs.is_empty());
+
+ // nuking this to make it easier to `assert_eq!()`
+ got.servicedirs = vec![];
+
+ assert_eq!(got, want,);
+}
+
#[should_panic]
#[test]
fn config_read_file_with_missing_include_err() {
diff --git a/tests/fixtures/example-session-disable-stats.conf b/tests/fixtures/example-session-disable-stats.conf
new file mode 100644
index 0000000..baafb2d
--- /dev/null
+++ b/tests/fixtures/example-session-disable-stats.conf
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/fixtures/example-system-enable-stats.conf b/tests/fixtures/example-system-enable-stats.conf
new file mode 100644
index 0000000..677f923
--- /dev/null
+++ b/tests/fixtures/example-system-enable-stats.conf
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/fixtures/session.conf b/tests/fixtures/session.conf
new file mode 100644
index 0000000..9f3e553
--- /dev/null
+++ b/tests/fixtures/session.conf
@@ -0,0 +1,83 @@
+
+
+
+
+
+
+
+
+ session
+
+
+
+
+ @DBUS_SESSION_BUS_LISTEN_ADDRESS@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ @SYSCONFDIR_FROM_PKGDATADIR@/dbus-1/session.conf
+
+
+
+
+
+
+
+ @SYSCONFDIR_FROM_PKGDATADIR@/dbus-1/session-local.conf
+
+
+
+
+
+
+ 1000000000
+ 250000000
+ 1000000000
+ 250000000
+ 1000000000
+
+ 120000
+ 240000
+ 150000
+ 100000
+ 10000
+ 100000
+ 10000
+ 50000
+ 50000
+ 50000
+
+
diff --git a/tests/fixtures/system.conf b/tests/fixtures/system.conf
new file mode 100644
index 0000000..043b57c
--- /dev/null
+++ b/tests/fixtures/system.conf
@@ -0,0 +1,145 @@
+
+
+
+
+
+
+
+
+
+
+
+ system
+
+
+ @DBUS_USER@
+
+
+
+
+
+
+
+
+ @DBUS_LIBEXECDIR@/dbus-daemon-launch-helper
+
+
+ @DBUS_SYSTEM_PID_FILE@
+
+
+
+
+
+ EXTERNAL
+
+
+ @DBUS_SYSTEM_BUS_DEFAULT_ADDRESS@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ @SYSCONFDIR_FROM_PKGDATADIR@/dbus-1/system.conf
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ @SYSCONFDIR_FROM_PKGDATADIR@/dbus-1/system-local.conf
+
+
+
+