Skip to content

Commit 1d69b7f

Browse files
committed
feat: Use random filename suffixes for blobstorage (#4309)
Thanks to the added Param::Filename these random suffixes aren't sent over the network.
1 parent e8bd795 commit 1d69b7f

File tree

8 files changed

+119
-97
lines changed

8 files changed

+119
-97
lines changed

python/src/deltachat/message.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ def set_html(self, html_text):
107107
lib.dc_msg_set_html(self._dc_msg, as_dc_charpointer(html_text))
108108

109109
@props.with_doc
110-
def filename(self):
111-
"""filename if there was an attachment, otherwise empty string."""
110+
def file_path(self):
111+
"""file path if there was an attachment, otherwise empty string."""
112112
return from_dc_charpointer(lib.dc_msg_get_file(self._dc_msg))
113113

114114
def set_file(self, path, mime_type=None):
@@ -119,9 +119,8 @@ def set_file(self, path, mime_type=None):
119119
lib.dc_msg_set_file(self._dc_msg, as_dc_charpointer(path), mtype)
120120

121121
@props.with_doc
122-
def basename(self) -> str:
123-
"""basename of the attachment if it exists, otherwise empty string."""
124-
# FIXME, it does not return basename
122+
def filename(self) -> str:
123+
"""filename of the attachment if any, otherwise empty string."""
125124
return from_dc_charpointer(lib.dc_msg_get_filename(self._dc_msg))
126125

127126
@props.with_doc

python/tests/test_1_online.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,16 @@ def send_and_receive_message():
181181

182182
msg = send_and_receive_message()
183183
assert msg.text == "withfile"
184-
assert open(msg.filename).read() == "some data"
185-
msg.filename.index(basename)
186-
assert msg.filename.endswith(ext)
184+
assert open(msg.file_path).read() == "some data"
185+
msg.file_path.index(basename)
186+
assert msg.file_path.endswith(ext)
187187

188188
msg2 = send_and_receive_message()
189189
assert msg2.text == "withfile"
190-
assert open(msg2.filename).read() == "some data"
191-
msg2.filename.index(basename)
192-
assert msg2.filename.endswith(ext)
193-
assert msg.filename != msg2.filename
190+
assert open(msg2.file_path).read() == "some data"
191+
msg2.file_path.index(basename)
192+
assert msg2.file_path.endswith(ext)
193+
assert msg.file_path != msg2.file_path
194194

195195

196196
def test_send_file_html_attachment(tmp_path, acfactory, lp):
@@ -214,9 +214,9 @@ def test_send_file_html_attachment(tmp_path, acfactory, lp):
214214
assert ev.data2 > dc.const.DC_CHAT_ID_LAST_SPECIAL
215215
msg = ac2.get_message_by_id(ev.data2)
216216

217-
assert open(msg.filename).read() == content
218-
msg.filename.index(basename)
219-
assert msg.filename.endswith(ext)
217+
assert open(msg.file_path).read() == content
218+
msg.file_path.index(basename)
219+
assert msg.file_path.endswith(ext)
220220

221221

222222
def test_html_message(acfactory, lp):
@@ -310,7 +310,7 @@ def test_webxdc_message(acfactory, data, lp):
310310
msg1.set_file(data.get_path("webxdc/minimal.xdc"))
311311
msg1 = chat.send_msg(msg1)
312312
assert msg1.is_webxdc()
313-
assert msg1.filename
313+
assert msg1.file_path
314314

315315
assert msg1.send_status_update({"payload": "test1"}, "some test data")
316316
assert msg1.send_status_update({"payload": "test2"}, "more test data")
@@ -323,7 +323,7 @@ def test_webxdc_message(acfactory, data, lp):
323323
msg2 = ac2._evtracker.wait_next_incoming_message()
324324
assert msg2.text == "message1"
325325
assert msg2.is_webxdc()
326-
assert msg2.filename
326+
assert msg2.file_path
327327
ac2._evtracker.get_info_contains("Marked messages [0-9]+ in folder INBOX as seen.")
328328
ac2.direct_imap.select_folder("Inbox")
329329
assert len(list(ac2.direct_imap.conn.fetch(AND(seen=True)))) == 1
@@ -338,7 +338,7 @@ def test_webxdc_huge_update(acfactory, data, lp):
338338
msg1.set_file(data.get_path("webxdc/minimal.xdc"))
339339
msg1 = chat.send_msg(msg1)
340340
assert msg1.is_webxdc()
341-
assert msg1.filename
341+
assert msg1.file_path
342342

343343
msg2 = ac2._evtracker.wait_next_incoming_message()
344344
assert msg2.is_webxdc()
@@ -360,7 +360,7 @@ def test_webxdc_download_on_demand(acfactory, data, lp):
360360
msg1.set_file(data.get_path("webxdc/minimal.xdc"))
361361
msg1 = chat.send_msg(msg1)
362362
assert msg1.is_webxdc()
363-
assert msg1.filename
363+
assert msg1.file_path
364364

365365
msg2 = ac2._evtracker.wait_next_incoming_message()
366366
assert msg2.is_webxdc()
@@ -1325,7 +1325,7 @@ def test_quote_attachment(tmp_path, acfactory, lp):
13251325
received_reply = ac1._evtracker.wait_next_incoming_message()
13261326
assert received_reply.text == "message reply"
13271327
assert received_reply.quoted_text == received_message.text
1328-
assert open(received_reply.filename).read() == "data to send"
1328+
assert open(received_reply.file_path).read() == "data to send"
13291329

13301330

13311331
def test_saved_mime_on_received_message(acfactory, lp):
@@ -1418,8 +1418,8 @@ def ac_outgoing_message(self, message):
14181418
assert ev.data2 == msg_out.id
14191419
msg_in = ac2.get_message_by_id(msg_out.id)
14201420
assert msg_in.is_image()
1421-
assert os.path.exists(msg_in.filename)
1422-
assert os.stat(msg_in.filename).st_size == os.stat(path).st_size
1421+
assert os.path.exists(msg_in.file_path)
1422+
assert os.stat(msg_in.file_path).st_size == os.stat(path).st_size
14231423
m = message_queue.get()
14241424
assert m == msg_in
14251425

@@ -1547,7 +1547,7 @@ def assert_account_is_proper(ac):
15471547
assert len(messages) == 3
15481548
assert messages[0].text == "msg1"
15491549
assert messages[1].filemime == "image/png"
1550-
assert os.stat(messages[1].filename).st_size == os.stat(original_image_path).st_size
1550+
assert os.stat(messages[1].file_path).st_size == os.stat(original_image_path).st_size
15511551
ac.set_config("displayname", "new displayname")
15521552
assert ac.get_config("displayname") == "new displayname"
15531553

@@ -1620,7 +1620,7 @@ def test_ac_setup_message(acfactory, lp):
16201620
with pytest.raises(ValueError):
16211621
msg.continue_key_transfer(str(reversed(setup_code)))
16221622
lp.sec("try a good setup code")
1623-
print("*************** Incoming ASM File at: ", msg.filename)
1623+
print("*************** Incoming ASM File at: ", msg.file_path)
16241624
print("*************** Setup Code: ", setup_code)
16251625
msg.continue_key_transfer(setup_code)
16261626
assert ac1.get_info()["fingerprint"] == ac2.get_info()["fingerprint"]

python/tests/test_2_increation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ def test_no_increation_copies_to_blobdir(self, tmp_path, acfactory, lp):
5050
src = tmp_path / "file.txt"
5151
src.write_text("hello there\n")
5252
msg = chat.send_file(str(src))
53-
assert msg.filename.startswith(os.path.join(ac1.get_blobdir(), "file"))
54-
assert msg.filename.endswith(".txt")
53+
assert msg.file_path.startswith(os.path.join(ac1.get_blobdir(), "file"))
54+
assert msg.file_path.endswith(".txt")
5555

5656
def test_forward_increation(self, acfactory, data, lp):
5757
ac1, ac2 = acfactory.get_online_accounts(2)
@@ -96,9 +96,9 @@ def test_forward_increation(self, acfactory, data, lp):
9696

9797
lp.sec("wait1 for original or forwarded messages to arrive")
9898
received_original = ac2._evtracker.wait_next_incoming_message()
99-
assert cmp(received_original.filename, orig, shallow=False)
99+
assert cmp(received_original.file_path, orig, shallow=False)
100100

101101
lp.sec("wait2 for original or forwarded messages to arrive")
102102
received_copy = ac2._evtracker.wait_next_incoming_message()
103103
assert received_copy.id != received_original.id
104-
assert cmp(received_copy.filename, orig, shallow=False)
104+
assert cmp(received_copy.file_path, orig, shallow=False)

python/tests/test_3_offline.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -443,31 +443,34 @@ def test_message_image(self, chat1, data, lp):
443443
assert msg.is_image()
444444
assert msg
445445
assert msg.id > 0
446-
assert os.path.exists(msg.filename)
446+
assert os.path.exists(msg.file_path)
447447
assert msg.filemime == "image/png"
448448

449449
@pytest.mark.parametrize(
450-
("fn", "typein", "typeout"),
450+
("stem", "ext", "typein", "typeout"),
451451
[
452-
("r", None, "application/octet-stream"),
453-
("r.txt", None, "text/plain"),
454-
("r.txt", "text/plain", "text/plain"),
455-
("r.txt", "image/png", "image/png"),
452+
("r", "", None, "application/octet-stream"),
453+
("r", ".txt", None, "text/plain"),
454+
("r", ".txt", "text/plain", "text/plain"),
455+
("r", ".txt", "image/png", "image/png"),
456456
],
457457
)
458-
def test_message_file(self, chat1, data, lp, fn, typein, typeout):
458+
def test_message_file(self, chat1, data, lp, stem, ext, typein, typeout):
459459
lp.sec("sending file")
460+
fn = stem + ext
460461
fp = data.get_path(fn)
461462
msg = chat1.send_file(fp, typein)
462463
assert msg
463464
assert msg.id > 0
464465
assert msg.is_file()
465-
assert os.path.exists(msg.filename)
466-
assert msg.filename.endswith(msg.basename)
466+
assert os.path.exists(msg.file_path)
467+
assert msg.file_path.endswith(ext)
468+
assert msg.filename == fn
467469
assert msg.filemime == typeout
468470
msg2 = chat1.send_file(fp, typein)
469471
assert msg2 != msg
470-
assert msg2.filename != msg.filename
472+
assert msg2.file_path != msg.file_path
473+
assert msg2.filename == fn
471474

472475
def test_create_contact(self, acfactory):
473476
ac1 = acfactory.get_pseudo_configured_account()
@@ -535,7 +538,7 @@ def test_import_export_on_unencrypted_acct(self, acfactory, tmp_path):
535538
messages = chat2.get_messages()
536539
assert len(messages) == 2
537540
assert messages[0].text == "msg1"
538-
assert os.path.exists(messages[1].filename)
541+
assert os.path.exists(messages[1].file_path)
539542

540543
def test_import_export_on_encrypted_acct(self, acfactory, tmp_path):
541544
passphrase1 = "passphrase1"
@@ -573,7 +576,7 @@ def test_import_export_on_encrypted_acct(self, acfactory, tmp_path):
573576
messages = chat2.get_messages()
574577
assert len(messages) == 2
575578
assert messages[0].text == "msg1"
576-
assert os.path.exists(messages[1].filename)
579+
assert os.path.exists(messages[1].file_path)
577580

578581
ac2.shutdown()
579582

@@ -590,7 +593,7 @@ def test_import_export_on_encrypted_acct(self, acfactory, tmp_path):
590593
messages = chat2.get_messages()
591594
assert len(messages) == 2
592595
assert messages[0].text == "msg1"
593-
assert os.path.exists(messages[1].filename)
596+
assert os.path.exists(messages[1].file_path)
594597

595598
def test_import_export_with_passphrase(self, acfactory, tmp_path):
596599
passphrase = "test_passphrase"
@@ -629,7 +632,7 @@ def test_import_export_with_passphrase(self, acfactory, tmp_path):
629632
messages = chat2.get_messages()
630633
assert len(messages) == 2
631634
assert messages[0].text == "msg1"
632-
assert os.path.exists(messages[1].filename)
635+
assert os.path.exists(messages[1].file_path)
633636

634637
def test_import_encrypted_bak_into_encrypted_acct(self, acfactory, tmp_path):
635638
"""
@@ -674,7 +677,7 @@ def test_import_encrypted_bak_into_encrypted_acct(self, acfactory, tmp_path):
674677
messages = chat2.get_messages()
675678
assert len(messages) == 2
676679
assert messages[0].text == "msg1"
677-
assert os.path.exists(messages[1].filename)
680+
assert os.path.exists(messages[1].file_path)
678681

679682
ac2.shutdown()
680683

@@ -691,7 +694,7 @@ def test_import_encrypted_bak_into_encrypted_acct(self, acfactory, tmp_path):
691694
messages = chat2.get_messages()
692695
assert len(messages) == 2
693696
assert messages[0].text == "msg1"
694-
assert os.path.exists(messages[1].filename)
697+
assert os.path.exists(messages[1].file_path)
695698

696699
def test_set_get_draft(self, chat1):
697700
msg = Message.new_empty(chat1.account, "text")

0 commit comments

Comments
 (0)