Skip to main content

bitwarden_policies/policies/
automatic_app_log_in.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{Policy, PolicyType, policy_type::PolicyDataType};
4
5/// Automatic App Log-in policy.
6pub struct AutomaticAppLogInPolicy;
7
8impl Policy for AutomaticAppLogInPolicy {
9    type Data = AutomaticAppLogInPolicyData;
10
11    fn policy_type(&self) -> PolicyType {
12        PolicyType::AutomaticAppLogIn
13    }
14
15    fn to_erased(&self, data: Self::Data) -> PolicyDataType {
16        PolicyDataType::AutomaticAppLogIn(data)
17    }
18}
19
20/// Configuration data for the Automatic App Log-in policy.
21#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
22#[serde(rename_all = "camelCase")]
23#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
24#[cfg_attr(
25    feature = "wasm",
26    derive(tsify::Tsify),
27    tsify(into_wasm_abi, from_wasm_abi)
28)]
29pub struct AutomaticAppLogInPolicyData {
30    /// The identity provider host used for automatic single sign-on into apps.
31    #[serde(skip_serializing_if = "Option::is_none")]
32    pub idp_host: Option<String>,
33}
34
35#[cfg(test)]
36mod tests {
37    use super::*;
38
39    #[test]
40    fn round_trips() {
41        let data = AutomaticAppLogInPolicyData {
42            idp_host: Some("https://idp.example.com".to_string()),
43        };
44        let json = serde_json::to_string(&data).unwrap();
45        assert_eq!(json, r#"{"idpHost":"https://idp.example.com"}"#);
46        assert_eq!(
47            serde_json::from_str::<AutomaticAppLogInPolicyData>(&json).unwrap(),
48            data
49        );
50    }
51
52    #[test]
53    fn empty_serializes_to_empty_object() {
54        assert_eq!(
55            serde_json::to_string(&AutomaticAppLogInPolicyData::default()).unwrap(),
56            "{}"
57        );
58    }
59}