Skip to content

Commit 81a6afd

Browse files
authored
Fix(jsonrpc): Do not error on missign webxdc info (#6866)
When an invalid webxdc is set as draft, json-rpc's `get_draft` fails, because `get_webxdc_info` which it calls, fails because the zip reader can not read a non-zip file. With this change, any error occurring in `get_webxdc_info` is ignored and the None-variant is returned instead. I also added a test, that setting invalid xdcs is draft is fine core-wise and checked that the input field stays responsive when a fake.xdc produced like in #6826 is added to draft close #6826
1 parent adcc8a9 commit 81a6afd

File tree

5 files changed

+51
-2
lines changed

5 files changed

+51
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,4 @@ result
5353
# direnv
5454
.envrc
5555
.direnv
56+
.aider*

deltachat-jsonrpc/src/api/types/message.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use deltachat::chat::ChatVisibility;
88
use deltachat::contact::Contact;
99
use deltachat::context::Context;
1010
use deltachat::download;
11+
use deltachat::log::LogExt as _;
1112
use deltachat::message::Message;
1213
use deltachat::message::MsgId;
1314
use deltachat::message::Viewtype;
@@ -143,7 +144,10 @@ impl MessageObject {
143144
let override_sender_name = message.get_override_sender_name();
144145

145146
let webxdc_info = if message.get_viewtype() == Viewtype::Webxdc {
146-
Some(WebxdcMessageInfo::get_for_message(context, msg_id).await?)
147+
WebxdcMessageInfo::get_for_message(context, msg_id)
148+
.await
149+
.log_err(context)
150+
.ok()
147151
} else {
148152
None
149153
};

deltachat-jsonrpc/typescript/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"dependencies": {
44
"@deltachat/tiny-emitter": "3.0.0",
55
"isomorphic-ws": "^4.0.1",
6+
"tmp": "^0.2.3",
67
"yerpc": "^0.6.2"
78
},
89
"devDependencies": {

deltachat-jsonrpc/typescript/test/basic.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { strictEqual } from "assert";
21
import chai, { assert, expect } from "chai";
32
import chaiAsPromised from "chai-as-promised";
3+
import { fileSync } from "tmp";
44
chai.use(chaiAsPromised);
55
import { StdioDeltaChat as DeltaChat } from "../deltachat.js";
66

@@ -100,6 +100,32 @@ describe("basic tests", () => {
100100
});
101101
});
102102

103+
describe("webxdc", function () {
104+
let invalidXdcPath: string;
105+
let accountId: number;
106+
107+
before(async () => {
108+
const tmpFile = fileSync({ postfix: ".xdc" });
109+
invalidXdcPath = tmpFile.name;
110+
accountId = await dc.rpc.addAccount();
111+
});
112+
113+
it("should be able to draft set an invalid xdc", async function () {
114+
const chat = await dc.rpc.createGroupChat(accountId, "xdc", false);
115+
await expect(
116+
dc.rpc.miscSetDraft(
117+
accountId,
118+
chat,
119+
"",
120+
invalidXdcPath,
121+
"invalid.xdc",
122+
null,
123+
null
124+
)
125+
).to.be.eventually.rejectedWith("Invalid xdc");
126+
});
127+
});
128+
103129
describe("configuration", function () {
104130
let accountId: number;
105131
before(async () => {

src/webxdc/webxdc_tests.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,23 @@ async fn test_send_invalid_webxdc() -> Result<()> {
124124
Ok(())
125125
}
126126

127+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
128+
async fn test_set_draft_invalid_webxdc() -> Result<()> {
129+
let t = TestContext::new_alice().await;
130+
let chat_id = create_group_chat(&t, ProtectionStatus::Unprotected, "foo").await?;
131+
132+
let mut instance = create_webxdc_instance(
133+
&t,
134+
"invalid-no-zip-but-7z.xdc",
135+
include_bytes!("../../test-data/webxdc/invalid-no-zip-but-7z.xdc"),
136+
)?;
137+
138+
// draft should not fail
139+
chat_id.set_draft(&t, Some(&mut instance)).await?;
140+
chat_id.get_draft(&t).await.unwrap();
141+
Ok(())
142+
}
143+
127144
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
128145
async fn test_send_special_webxdc_format() -> Result<()> {
129146
let t = TestContext::new_alice().await;

0 commit comments

Comments
 (0)