|
| 1 | +import pytest |
| 2 | + |
| 3 | +from deltachat_rpc_client.rpc import JsonRpcError |
| 4 | + |
| 5 | + |
| 6 | +def test_add_second_address(acfactory) -> None: |
| 7 | + account = acfactory.new_configured_account() |
| 8 | + assert len(account.list_transports()) == 1 |
| 9 | + |
| 10 | + # When the first transport is created, |
| 11 | + # mvbox_move and only_fetch_mvbox should be disabled. |
| 12 | + assert account.get_config("mvbox_move") == "0" |
| 13 | + assert account.get_config("only_fetch_mvbox") == "0" |
| 14 | + assert account.get_config("show_emails") == "2" |
| 15 | + |
| 16 | + qr = acfactory.get_account_qr() |
| 17 | + account.add_transport_from_qr(qr) |
| 18 | + assert len(account.list_transports()) == 2 |
| 19 | + |
| 20 | + account.add_transport_from_qr(qr) |
| 21 | + assert len(account.list_transports()) == 3 |
| 22 | + |
| 23 | + first_addr = account.list_transports()[0]["addr"] |
| 24 | + second_addr = account.list_transports()[1]["addr"] |
| 25 | + |
| 26 | + # Cannot delete the first address. |
| 27 | + with pytest.raises(JsonRpcError): |
| 28 | + account.delete_transport(first_addr) |
| 29 | + |
| 30 | + account.delete_transport(second_addr) |
| 31 | + assert len(account.list_transports()) == 2 |
| 32 | + |
| 33 | + # Enabling mvbox_move or only_fetch_mvbox |
| 34 | + # is not allowed when multi-transport is enabled. |
| 35 | + for option in ["mvbox_move", "only_fetch_mvbox"]: |
| 36 | + with pytest.raises(JsonRpcError): |
| 37 | + account.set_config(option, "1") |
| 38 | + |
| 39 | + with pytest.raises(JsonRpcError): |
| 40 | + account.set_config("show_emails", "0") |
| 41 | + |
| 42 | + |
| 43 | +@pytest.mark.parametrize("key", ["mvbox_move", "only_fetch_mvbox"]) |
| 44 | +def test_no_second_transport_with_mvbox(acfactory, key) -> None: |
| 45 | + """Test that second transport cannot be configured if mvbox is used.""" |
| 46 | + account = acfactory.new_configured_account() |
| 47 | + assert len(account.list_transports()) == 1 |
| 48 | + |
| 49 | + assert account.get_config("mvbox_move") == "0" |
| 50 | + assert account.get_config("only_fetch_mvbox") == "0" |
| 51 | + |
| 52 | + qr = acfactory.get_account_qr() |
| 53 | + account.set_config(key, "1") |
| 54 | + |
| 55 | + with pytest.raises(JsonRpcError): |
| 56 | + account.add_transport_from_qr(qr) |
| 57 | + |
| 58 | + |
| 59 | +def test_no_second_transport_without_classic_emails(acfactory) -> None: |
| 60 | + """Test that second transport cannot be configured if classic emails are not fetched.""" |
| 61 | + account = acfactory.new_configured_account() |
| 62 | + assert len(account.list_transports()) == 1 |
| 63 | + |
| 64 | + assert account.get_config("show_emails") == "2" |
| 65 | + |
| 66 | + qr = acfactory.get_account_qr() |
| 67 | + account.set_config("show_emails", "0") |
| 68 | + |
| 69 | + with pytest.raises(JsonRpcError): |
| 70 | + account.add_transport_from_qr(qr) |
| 71 | + |
| 72 | + |
| 73 | +def test_change_address(acfactory) -> None: |
| 74 | + """Test Alice configuring a second transport and setting it as a primary one.""" |
| 75 | + alice, bob = acfactory.get_online_accounts(2) |
| 76 | + |
| 77 | + bob_addr = bob.get_config("configured_addr") |
| 78 | + bob.create_chat(alice) |
| 79 | + |
| 80 | + alice_chat_bob = alice.create_chat(bob) |
| 81 | + alice_chat_bob.send_text("Hello!") |
| 82 | + |
| 83 | + msg1 = bob.wait_for_incoming_msg().get_snapshot() |
| 84 | + sender_addr1 = msg1.sender.get_snapshot().address |
| 85 | + |
| 86 | + alice.stop_io() |
| 87 | + old_alice_addr = alice.get_config("configured_addr") |
| 88 | + alice_vcard = alice.self_contact.make_vcard() |
| 89 | + assert old_alice_addr in alice_vcard |
| 90 | + qr = acfactory.get_account_qr() |
| 91 | + alice.add_transport_from_qr(qr) |
| 92 | + new_alice_addr = alice.list_transports()[1]["addr"] |
| 93 | + with pytest.raises(JsonRpcError): |
| 94 | + # Cannot use the address that is not |
| 95 | + # configured for any transport. |
| 96 | + alice.set_config("configured_addr", bob_addr) |
| 97 | + |
| 98 | + # Load old address so it is cached. |
| 99 | + assert alice.get_config("configured_addr") == old_alice_addr |
| 100 | + alice.set_config("configured_addr", new_alice_addr) |
| 101 | + # Make sure that setting `configured_addr` invalidated the cache. |
| 102 | + assert alice.get_config("configured_addr") == new_alice_addr |
| 103 | + |
| 104 | + alice_vcard = alice.self_contact.make_vcard() |
| 105 | + assert old_alice_addr not in alice_vcard |
| 106 | + assert new_alice_addr in alice_vcard |
| 107 | + with pytest.raises(JsonRpcError): |
| 108 | + alice.delete_transport(new_alice_addr) |
| 109 | + alice.start_io() |
| 110 | + |
| 111 | + alice_chat_bob.send_text("Hello again!") |
| 112 | + |
| 113 | + msg2 = bob.wait_for_incoming_msg().get_snapshot() |
| 114 | + sender_addr2 = msg2.sender.get_snapshot().address |
| 115 | + |
| 116 | + assert msg1.sender == msg2.sender |
| 117 | + assert sender_addr1 != sender_addr2 |
| 118 | + assert sender_addr1 == old_alice_addr |
| 119 | + assert sender_addr2 == new_alice_addr |
| 120 | + |
| 121 | + |
| 122 | +@pytest.mark.parametrize("is_chatmail", ["0", "1"]) |
| 123 | +def test_mvbox_move_first_transport(acfactory, is_chatmail) -> None: |
| 124 | + """Test that mvbox_move is disabled by default even for non-chatmail accounts. |
| 125 | + Disabling mvbox_move is required to be able to setup a second transport. |
| 126 | + """ |
| 127 | + account = acfactory.get_unconfigured_account() |
| 128 | + |
| 129 | + account.set_config("fix_is_chatmail", "1") |
| 130 | + account.set_config("is_chatmail", is_chatmail) |
| 131 | + |
| 132 | + # The default value when the setting is unset is "1". |
| 133 | + # This is not changed for compatibility with old databases |
| 134 | + # imported from backups. |
| 135 | + assert account.get_config("mvbox_move") == "1" |
| 136 | + |
| 137 | + qr = acfactory.get_account_qr() |
| 138 | + account.add_transport_from_qr(qr) |
| 139 | + |
| 140 | + # Once the first transport is set up, |
| 141 | + # mvbox_move is disabled. |
| 142 | + assert account.get_config("mvbox_move") == "0" |
| 143 | + assert account.get_config("is_chatmail") == is_chatmail |
| 144 | + |
| 145 | + |
| 146 | +def test_reconfigure_transport(acfactory) -> None: |
| 147 | + """Test that reconfiguring the transport works |
| 148 | + even if settings not supported for multi-transport |
| 149 | + like mvbox_move are enabled.""" |
| 150 | + account = acfactory.get_online_account() |
| 151 | + account.set_config("mvbox_move", "1") |
| 152 | + |
| 153 | + [transport] = account.list_transports() |
| 154 | + account.add_or_update_transport(transport) |
| 155 | + |
| 156 | + # Reconfiguring the transport should not reset |
| 157 | + # the settings as if when configuring the first transport. |
| 158 | + assert account.get_config("mvbox_move") == "1" |
0 commit comments