bitwarden_vault/cipher/blob/conversions/
secure_note.rs1use super::{SecureNoteDataV1, SecureNoteView};
2
3impl_bidirectional_from!(SecureNoteView, SecureNoteDataV1, [r#type]);
4
5#[cfg(test)]
6mod tests {
7 use chrono::{TimeZone, Utc};
8
9 use super::super::{CipherBlobV1, test_support::*};
10 use crate::{
11 PasswordHistoryView,
12 cipher::{
13 cipher::CipherType,
14 field::{FieldType, FieldView},
15 secure_note::{SecureNoteType, SecureNoteView},
16 },
17 };
18
19 #[test]
20 fn test_secure_note_cipher_round_trip() {
21 let original = crate::CipherView {
22 name: "My Secure Note".to_string(),
23 notes: Some("Secret notes".to_string()),
24 r#type: CipherType::SecureNote,
25 secure_note: Some(SecureNoteView {
26 r#type: SecureNoteType::Generic,
27 }),
28 fields: Some(vec![FieldView {
29 name: Some("field1".to_string()),
30 value: Some("value1".to_string()),
31 r#type: FieldType::Text,
32 linked_id: None,
33 }]),
34 password_history: Some(vec![PasswordHistoryView {
35 password: "old-pass".to_string(),
36 last_used_date: Utc.with_ymd_and_hms(2023, 6, 1, 0, 0, 0).unwrap(),
37 }]),
38 ..create_shell_cipher_view(CipherType::SecureNote)
39 };
40
41 let blob = CipherBlobV1::from_cipher_view(&original).unwrap();
42 let mut restored = create_shell_cipher_view(CipherType::SecureNote);
43 blob.apply_to_cipher_view(&mut restored).unwrap();
44
45 assert_eq!(restored.name, original.name);
46 assert_eq!(restored.notes, original.notes);
47 assert_eq!(restored.r#type, CipherType::SecureNote);
48 assert!(restored.secure_note.is_some());
49 assert!(restored.login.is_none());
50 assert!(restored.card.is_none());
51 assert!(restored.identity.is_none());
52 assert!(restored.ssh_key.is_none());
53 assert_eq!(restored.fields.as_ref().unwrap().len(), 1);
54 assert_eq!(
55 restored.fields.as_ref().unwrap()[0].name,
56 Some("field1".to_string())
57 );
58 assert_eq!(restored.password_history.as_ref().unwrap().len(), 1);
59 assert_eq!(
60 restored.password_history.as_ref().unwrap()[0].password,
61 "old-pass"
62 );
63 }
64}