diff --git a/.gitignore b/.gitignore index df6d6fb20..0be33f761 100644 --- a/.gitignore +++ b/.gitignore @@ -53,3 +53,4 @@ result # direnv .envrc .direnv +.aider* diff --git a/deltachat-jsonrpc/src/api/types/message.rs b/deltachat-jsonrpc/src/api/types/message.rs index a5c25184a..9cb8fc04c 100644 --- a/deltachat-jsonrpc/src/api/types/message.rs +++ b/deltachat-jsonrpc/src/api/types/message.rs @@ -8,6 +8,7 @@ use deltachat::chat::ChatVisibility; use deltachat::contact::Contact; use deltachat::context::Context; use deltachat::download; +use deltachat::log::LogExt as _; use deltachat::message::Message; use deltachat::message::MsgId; use deltachat::message::Viewtype; @@ -143,7 +144,10 @@ impl MessageObject { let override_sender_name = message.get_override_sender_name(); let webxdc_info = if message.get_viewtype() == Viewtype::Webxdc { - Some(WebxdcMessageInfo::get_for_message(context, msg_id).await?) + WebxdcMessageInfo::get_for_message(context, msg_id) + .await + .log_err(context) + .ok() } else { None }; diff --git a/deltachat-jsonrpc/typescript/package.json b/deltachat-jsonrpc/typescript/package.json index 85a286676..c0801a739 100644 --- a/deltachat-jsonrpc/typescript/package.json +++ b/deltachat-jsonrpc/typescript/package.json @@ -3,6 +3,7 @@ "dependencies": { "@deltachat/tiny-emitter": "3.0.0", "isomorphic-ws": "^4.0.1", + "tmp": "^0.2.3", "yerpc": "^0.6.2" }, "devDependencies": { diff --git a/deltachat-jsonrpc/typescript/test/basic.ts b/deltachat-jsonrpc/typescript/test/basic.ts index d5ce57aec..9e29119a2 100644 --- a/deltachat-jsonrpc/typescript/test/basic.ts +++ b/deltachat-jsonrpc/typescript/test/basic.ts @@ -1,6 +1,6 @@ -import { strictEqual } from "assert"; import chai, { assert, expect } from "chai"; import chaiAsPromised from "chai-as-promised"; +import { fileSync } from "tmp"; chai.use(chaiAsPromised); import { StdioDeltaChat as DeltaChat } from "../deltachat.js"; @@ -100,6 +100,32 @@ describe("basic tests", () => { }); }); + describe("webxdc", function () { + let invalidXdcPath: string; + let accountId: number; + + before(async () => { + const tmpFile = fileSync({ postfix: ".xdc" }); + invalidXdcPath = tmpFile.name; + accountId = await dc.rpc.addAccount(); + }); + + it("should be able to draft set an invalid xdc", async function () { + const chat = await dc.rpc.createGroupChat(accountId, "xdc", false); + await expect( + dc.rpc.miscSetDraft( + accountId, + chat, + "", + invalidXdcPath, + "invalid.xdc", + null, + null + ) + ).to.be.eventually.rejectedWith("Invalid xdc"); + }); + }); + describe("configuration", function () { let accountId: number; before(async () => { diff --git a/src/webxdc/webxdc_tests.rs b/src/webxdc/webxdc_tests.rs index 5b7b6309d..464e22f99 100644 --- a/src/webxdc/webxdc_tests.rs +++ b/src/webxdc/webxdc_tests.rs @@ -124,6 +124,23 @@ async fn test_send_invalid_webxdc() -> Result<()> { Ok(()) } +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] +async fn test_set_draft_invalid_webxdc() -> Result<()> { + let t = TestContext::new_alice().await; + let chat_id = create_group_chat(&t, ProtectionStatus::Unprotected, "foo").await?; + + let mut instance = create_webxdc_instance( + &t, + "invalid-no-zip-but-7z.xdc", + include_bytes!("../../test-data/webxdc/invalid-no-zip-but-7z.xdc"), + )?; + + // draft should not fail + chat_id.set_draft(&t, Some(&mut instance)).await?; + chat_id.get_draft(&t).await.unwrap(); + Ok(()) +} + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn test_send_special_webxdc_format() -> Result<()> { let t = TestContext::new_alice().await;