Skip to content

Commit

Permalink
🦺 Support <auth> elements
Browse files Browse the repository at this point in the history
  • Loading branch information
jokeyrhyme committed Oct 27, 2024
1 parent 9973229 commit eaa48f6
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::PathBuf;
use std::{collections::HashSet, path::PathBuf};

use anyhow::{Error, Result};
use quick_xml::{events::Event, Reader};
Expand Down Expand Up @@ -27,6 +27,14 @@ pub struct BusConfig {
// TODO: consider finding a way to make this `bool` instead of `Option<()>`
pub allow_anonymous: Option<()>,

/// Lists permitted authorization mechanisms.
/// If this element doesn't exist, then all known mechanisms are allowed.
/// If there are multiple <auth> elements, all the listed mechanisms are allowed.
#[query(r#".auth.[].["$value"]"#)]
#[serde(default)]
// TODO: if there is a fixed set of possible values, consider using an `enum`
pub auth: HashSet<String>,

/// If `Some`, the bus daemon becomes a real daemon (forks into the background, etc.).
#[query(".fork")]
// TODO: consider finding a way to make this `bool` instead of `Option<()>`
Expand Down Expand Up @@ -199,6 +207,23 @@ mod tests {
);
}

#[test]
fn bus_config_parse_with_auth_ok() {
let input = r#"<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<auth>ANONYMOUS</auth>
<auth>EXTERNAL</auth>
</busconfig>
"#;

let busconfig = BusConfig::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);
}

#[test]
fn bus_config_parse_with_listen_ok() {
let input = r#"<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN"
Expand Down

0 comments on commit eaa48f6

Please sign in to comment.