From 41443bb7f91c3087fecf2d7d3854a3eeb4937b89 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Wed, 30 Oct 2019 15:15:56 +0100 Subject: [PATCH] fix sending of autocrypt setup message --- python/tests/test_account.py | 21 +++++++++++++++++++++ src/blob.rs | 20 ++++++++++++++++---- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/python/tests/test_account.py b/python/tests/test_account.py index 545ba04ab..d4f146a4e 100644 --- a/python/tests/test_account.py +++ b/python/tests/test_account.py @@ -682,6 +682,27 @@ class TestOnlineAccount: msg.continue_key_transfer(setup_code) assert ac1.get_info()["fingerprint"] == ac2.get_info()["fingerprint"] + def test_ac_setup_message_twice(self, acfactory, lp): + ac1 = acfactory.get_online_configuring_account() + ac2 = acfactory.clone_online_account(ac1) + ac2._evlogger.set_timeout(30) + wait_configuration_progress(ac2, 1000) + wait_configuration_progress(ac1, 1000) + lp.sec("trigger ac setup message but ignore") + assert ac1.get_info()["fingerprint"] != ac2.get_info()["fingerprint"] + ac1.initiate_key_transfer() + ac2._evlogger.get_matching("DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED") + + lp.sec("trigger second ac setup message, wait for receive ") + setup_code2 = ac1.initiate_key_transfer() + ev = ac2._evlogger.get_matching("DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED") + msg = ac2.get_message_by_id(ev[2]) + assert msg.is_setup_message() + assert msg.get_setupcodebegin() == setup_code2[:2] + lp.sec("process second setup message") + msg.continue_key_transfer(setup_code2) + assert ac1.get_info()["fingerprint"] == ac2.get_info()["fingerprint"] + def test_qr_setup_contact(self, acfactory, lp): ac1, ac2 = acfactory.get_two_online_accounts() lp.sec("ac1: create QR code and let ac2 scan it, starting the securejoin") diff --git a/src/blob.rs b/src/blob.rs index a01432216..2ee9798fc 100644 --- a/src/blob.rs +++ b/src/blob.rs @@ -254,12 +254,13 @@ impl<'a> BlobObject<'a> { windows: true, replacement: "", }; + let clean = sanitize_filename::sanitize_with_options(name, opts); let mut iter = clean.rsplitn(2, '.'); let mut ext = iter.next().unwrap_or_default().to_string(); let mut stem = iter.next().unwrap_or_default().to_string(); ext.truncate(32); - stem.truncate(32); + stem.truncate(64); match stem.len() { 0 => (ext, "".to_string()), _ => (stem, format!(".{}", ext).to_lowercase()), @@ -563,10 +564,10 @@ mod tests { #[test] fn test_create_long_names() { let t = dummy_context(); - let s = "12312312039182039182039812039810293810293810293810293801293801293123123"; - let blob = BlobObject::create(&t.ctx, s, b"data").unwrap(); + let s = "1".repeat(150); + let blob = BlobObject::create(&t.ctx, &s, b"data").unwrap(); let blobname = blob.as_name().split('/').last().unwrap(); - assert!(s.len() > blobname.len()); + assert!(blobname.len() < 128); } #[test] @@ -603,4 +604,15 @@ mod tests { let data = fs::read(blob.to_abs_path()).unwrap(); assert_eq!(data, b"boo"); } + #[test] + fn test_create_from_name_long() { + let t = dummy_context(); + let src_ext = t.dir.path().join("autocrypt-setup-message-4137848473.html"); + fs::write(&src_ext, b"boo").unwrap(); + let blob = BlobObject::create_from_path(&t.ctx, &src_ext).unwrap(); + assert_eq!( + blob.as_name(), + "$BLOBDIR/autocrypt-setup-message-4137848473.html" + ); + } }