Skip to main content

bitwarden_vault/cipher/blob/conversions/
identity.rs

1use super::{IdentityDataV1, IdentityView};
2
3impl_bidirectional_from!(
4    IdentityView,
5    IdentityDataV1,
6    [
7        title,
8        first_name,
9        middle_name,
10        last_name,
11        address1,
12        address2,
13        address3,
14        city,
15        state,
16        postal_code,
17        country,
18        company,
19        email,
20        phone,
21        ssn,
22        username,
23        passport_number,
24        license_number,
25    ]
26);
27
28#[cfg(test)]
29mod tests {
30    use super::super::{CipherBlobV1, test_support::*};
31    use crate::cipher::{cipher::CipherType, identity::IdentityView};
32
33    #[test]
34    fn test_identity_cipher_round_trip() {
35        let original = crate::CipherView {
36            name: "My Identity".to_string(),
37            notes: Some("Identity notes".to_string()),
38            r#type: CipherType::Identity,
39            identity: Some(IdentityView {
40                title: Some("Mr".to_string()),
41                first_name: Some("John".to_string()),
42                middle_name: None,
43                last_name: Some("Doe".to_string()),
44                address1: Some("123 Main St".to_string()),
45                address2: None,
46                address3: None,
47                city: Some("NYC".to_string()),
48                state: Some("NY".to_string()),
49                postal_code: Some("10001".to_string()),
50                country: Some("US".to_string()),
51                company: None,
52                email: Some("[email protected]".to_string()),
53                phone: None,
54                ssn: None,
55                username: Some("johndoe".to_string()),
56                passport_number: None,
57                license_number: None,
58            }),
59            ..create_shell_cipher_view(CipherType::Identity)
60        };
61
62        let blob = CipherBlobV1::from_cipher_view(&original).unwrap();
63        let mut restored = create_shell_cipher_view(CipherType::Identity);
64        blob.apply_to_cipher_view(&mut restored).unwrap();
65
66        assert_eq!(restored.name, "My Identity");
67        assert_eq!(restored.r#type, CipherType::Identity);
68        let identity = restored.identity.unwrap();
69        assert_eq!(identity.first_name, Some("John".to_string()));
70        assert_eq!(identity.last_name, Some("Doe".to_string()));
71        assert_eq!(identity.email, Some("[email protected]".to_string()));
72        assert!(restored.login.is_none());
73        assert!(restored.card.is_none());
74    }
75}