Skip to content

Fix(jsonrpc): Do not error on missign webxdc info #6866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ result
# direnv
.envrc
.direnv
.aider*
6 changes: 5 additions & 1 deletion deltachat-jsonrpc/src/api/types/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
};
Expand Down
1 change: 1 addition & 0 deletions deltachat-jsonrpc/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
28 changes: 27 additions & 1 deletion deltachat-jsonrpc/typescript/test/basic.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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 () => {
Expand Down
17 changes: 17 additions & 0 deletions src/webxdc/webxdc_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test is not actually failing when I revert the fix, seems not to reproduce the bug

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bug is deltachat-json-rpc specific. I tried to replicate the issue in core first and left the test as an artifact.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it realistic to reproduce the bug with a python test?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather a jsonrpc test, but I think it's unnecessary for such a small thing

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't matter whether it's a Typescript JsonRPC or a Python JsonRPC test (in deltachat-rpc-client/tests/test_something.py), both are testing mostly the same API.

BTW, to prevent confusion about which Python bindings are meant, at some point we should rename the deprecated CFFI Python bindings, which are currently in python/, to python-deprecated, and then rename deltachat-rpc-client to python-rpc-client (or similar).

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;
Expand Down
Loading