Skip to content

Commit a09fd45

Browse files
authored
fix: add explicit limit for adding relays (5 at the moment) (#7611)
closes #7608
1 parent 525a353 commit a09fd45

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

deltachat-rpc-client/tests/test_multitransport.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,25 @@ def test_recognize_self_address(acfactory) -> None:
221221
bob_chat.send_text("Hello!")
222222
msg = alice.wait_for_incoming_msg().get_snapshot()
223223
assert msg.chat == alice.create_chat(bob)
224+
225+
226+
def test_transport_limit(acfactory) -> None:
227+
"""Test transports limit."""
228+
account = acfactory.get_online_account()
229+
qr = acfactory.get_account_qr()
230+
231+
limit = 5
232+
233+
for _ in range(1, limit):
234+
account.add_transport_from_qr(qr)
235+
236+
assert len(account.list_transports()) == limit
237+
238+
with pytest.raises(JsonRpcError):
239+
account.add_transport_from_qr(qr)
240+
241+
second_addr = account.list_transports()[1]["addr"]
242+
account.delete_transport(second_addr)
243+
244+
# test that adding a transport after deleting one works again
245+
account.add_transport_from_qr(qr)

src/configure.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ use crate::transport::{
4545
use crate::{EventType, stock_str};
4646
use crate::{chat, provider};
4747

48+
/// Maximum number of relays
49+
/// see <https://github.com/chatmail/core/issues/7608>
50+
pub(crate) const MAX_TRANSPORT_RELAYS: usize = 5;
51+
4852
macro_rules! progress {
4953
($context:tt, $progress:expr, $comment:expr) => {
5054
assert!(
@@ -283,6 +287,18 @@ impl Context {
283287
"To use additional relays, set the legacy option \"Settings / Advanced / Show Classic Emails\" to \"All\"."
284288
);
285289
}
290+
291+
if self
292+
.sql
293+
.count("SELECT COUNT(*) FROM transports", ())
294+
.await?
295+
>= MAX_TRANSPORT_RELAYS
296+
{
297+
bail!(
298+
"You have reached the maximum number of relays ({}).",
299+
MAX_TRANSPORT_RELAYS
300+
)
301+
}
286302
}
287303

288304
let provider = match configure(self, param).await {

0 commit comments

Comments
 (0)