Skip to main content

keystate_core/model/entities/
realm.rs

1//! The `Realm` entity.
2
3use serde::{Deserialize, Serialize};
4use serde_json::Value;
5
6/// A realm: the top-level configuration container.
7#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
8pub struct Realm {
9    /// The realm's identity key: its name.
10    #[serde(default)]
11    pub name: String,
12    /// Whether the realm is active.
13    #[serde(default)]
14    pub enabled: bool,
15    /// Backend-faithful representation of this realm and its settings.
16    #[serde(default)]
17    pub native: Value,
18}
19
20#[cfg(test)]
21mod tests {
22    use super::*;
23
24    #[test]
25    fn realm_serializes_common_and_native() {
26        let realm = Realm {
27            name: "master".into(),
28            enabled: true,
29            native: serde_json::json!({ "registrationAllowed": false }),
30        };
31        let value = serde_json::to_value(&realm).unwrap();
32        assert_eq!(value["name"], "master");
33        assert_eq!(value["enabled"], true);
34        assert_eq!(value["native"]["registrationAllowed"], false);
35    }
36}