bitwarden_policies/policies/
automatic_app_log_in.rs1use bitwarden_organizations::OrganizationUserType;
2use serde::{Deserialize, Serialize};
3
4use crate::{PolicyDefinition, PolicyType, policy_type::PolicyDataType};
5
6pub struct AutomaticAppLogInPolicy;
8
9impl PolicyDefinition for AutomaticAppLogInPolicy {
10 type Data = AutomaticAppLogInPolicyData;
11
12 fn policy_type(&self) -> PolicyType {
13 PolicyType::AutomaticAppLogIn
14 }
15
16 fn exempt_roles(&self) -> &[OrganizationUserType] {
17 &[]
18 }
19
20 fn to_erased(&self, data: Self::Data) -> PolicyDataType {
21 PolicyDataType::AutomaticAppLogIn(data)
22 }
23}
24
25#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
27#[serde(rename_all = "camelCase")]
28#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
29#[bitwarden_ffi::wasm_record]
30pub struct AutomaticAppLogInPolicyData {
31 #[serde(skip_serializing_if = "Option::is_none")]
33 pub idp_host: Option<String>,
34}
35
36#[cfg(test)]
37mod tests {
38 use super::*;
39
40 #[test]
41 fn round_trips() {
42 let data = AutomaticAppLogInPolicyData {
43 idp_host: Some("https://idp.example.com".to_string()),
44 };
45 let json = serde_json::to_string(&data).unwrap();
46 assert_eq!(json, r#"{"idpHost":"https://idp.example.com"}"#);
47 assert_eq!(
48 serde_json::from_str::<AutomaticAppLogInPolicyData>(&json).unwrap(),
49 data
50 );
51 }
52
53 #[test]
54 fn empty_serializes_to_empty_object() {
55 assert_eq!(
56 serde_json::to_string(&AutomaticAppLogInPolicyData::default()).unwrap(),
57 "{}"
58 );
59 }
60}