def test_send_and_receive_will_encrypt_decrypt(self, acfactory, lp):
        lp.sec("starting accounts, waiting for configuration")
        ac1 = acfactory.get_online_configuring_account()
        ac2 = acfactory.get_online_configuring_account()
        c2 = ac1.create_contact(email=ac2.get_config("addr"))
        chat = ac1.create_chat_by_contact(c2)
        assert chat.id >= const.DC_CHAT_ID_LAST_SPECIAL

        wait_configuration_progress(ac1, 1000)
        wait_configuration_progress(ac2, 1000)

        lp.sec("sending text message from ac1 to ac2")
        msg_out = chat.send_text("message1")

        lp.sec("wait for ac2 to receive message")
        ev = ac2._evlogger.get_matching("DC_EVENT_MSGS_CHANGED")
        assert ev[2] == msg_out.id
        msg_in = ac2.get_message_by_id(msg_out.id)
        assert msg_in.text == "message1"

        lp.sec(
            "create new chat with contact and send back (encrypted) message")
        chat2b = ac2.create_chat_by_message(msg_in)
        chat2b.send_text("message-back")

        lp.sec("wait for ac1 to receive message")
        ev = ac1._evlogger.get_matching("DC_EVENT_INCOMING_MSG")
        assert ev[1] == chat.id
        assert ev[2] > msg_out.id
        msg_back = ac1.get_message_by_id(ev[2])
        assert msg_back.text == "message-back"
Exemple #2
0
 def test_ac_setup_message(self, acfactory, lp):
     # note that the receiving account needs to be configured and running
     # before ther setup message is send. DC does not read old messages
     # as of Jul2019
     ac1 = acfactory.get_online_configuring_account()
     ac2 = acfactory.clone_online_account(ac1)
     wait_configuration_progress(ac2, 1000)
     wait_configuration_progress(ac1, 1000)
     lp.sec("trigger ac setup message and return setupcode")
     assert ac1.get_info()["fingerprint"] != ac2.get_info()["fingerprint"]
     setup_code = ac1.initiate_key_transfer()
     ac2._evlogger.set_timeout(30)
     ev = ac2._evlogger.get_matching(
         "DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED")
     msg = ac2.get_message_by_id(ev[2])
     assert msg.is_setup_message()
     assert msg.get_setupcodebegin() == setup_code[:2]
     lp.sec("try a bad setup code")
     with pytest.raises(ValueError):
         msg.continue_key_transfer(str(reversed(setup_code)))
     lp.sec("try a good setup code")
     print("*************** Incoming ASM File at: ", msg.filename)
     print("*************** Setup Code: ", setup_code)
     msg.continue_key_transfer(setup_code)
     assert ac1.get_info()["fingerprint"] == ac2.get_info()["fingerprint"]
    def test_forward_increation(self, acfactory, data, lp):
        ac1 = acfactory.get_online_configuring_account()
        ac2 = acfactory.get_online_configuring_account()
        wait_configuration_progress(ac1, 1000)
        wait_configuration_progress(ac2, 1000)

        blobdir = ac1.get_blobdir()

        c2 = ac1.create_contact(email=ac2.get_config("addr"))
        chat = ac1.create_chat_by_contact(c2)
        assert chat.id >= const.DC_CHAT_ID_LAST_SPECIAL
        wait_msgs_changed(ac1, 0, 0)  # why no chat id?

        lp.sec("create a message with a file in creation")
        path = os.path.join(blobdir, "d.png")
        open(path, 'a').close()
        prepared_original = chat.prepare_file(path)
        assert prepared_original.get_state().is_out_preparing()
        wait_msgs_changed(ac1, chat.id, prepared_original.id)

        lp.sec("forward the message while still in creation")
        chat2 = ac1.create_group_chat("newgroup")
        chat2.add_contact(c2)
        wait_msgs_changed(ac1, 0, 0)  # why not chat id?
        ac1.forward_messages([prepared_original], chat2)
        forwarded_id = wait_msgs_changed(ac1, chat2.id)
        forwarded_msg = ac1.get_message_by_id(forwarded_id)
        assert forwarded_msg.get_state().is_out_preparing()

        lp.sec("finish creating the file and send it")
        shutil.copy(data.get_path("d.png"), path)
        sent_original = chat.send_prepared(prepared_original)
        assert sent_original.id == prepared_original.id
        state = sent_original.get_state()
        assert state.is_out_pending() or state.is_out_delivered()
        wait_msgs_changed(ac1, chat.id, sent_original.id)

        lp.sec("expect the forwarded message to be sent now too")
        wait_msgs_changed(ac1, chat2.id, forwarded_id)
        state = ac1.get_message_by_id(forwarded_id).get_state()
        assert state.is_out_pending() or state.is_out_delivered()

        lp.sec("wait for the messages to be delivered to SMTP")
        ev = ac1._evlogger.get_matching("DC_EVENT_MSG_DELIVERED")
        assert ev[1] == chat.id
        assert ev[2] == sent_original.id
        ev = ac1._evlogger.get_matching("DC_EVENT_MSG_DELIVERED")
        assert ev[1] == chat2.id
        assert ev[2] == forwarded_id

        lp.sec("wait for both messages to arrive")
        ev1 = ac2._evlogger.get_matching("DC_EVENT_MSGS_CHANGED")
        assert ev1[1] >= const.DC_CHAT_ID_LAST_SPECIAL
        received_original = ac2.get_message_by_id(ev1[2])
        assert cmp(received_original.filename, path, False)
        ev2 = ac2._evlogger.get_matching("DC_EVENT_MSGS_CHANGED")
        assert ev2[1] >= const.DC_CHAT_ID_LAST_SPECIAL
        assert ev2[1] != ev1[1]
        received_copy = ac2.get_message_by_id(ev2[2])
        assert cmp(received_copy.filename, path, False)
Exemple #4
0
    def test_one_account_send_bcc_setting(self, acfactory, lp):
        ac1 = acfactory.get_online_configuring_account()
        c2 = ac1.create_contact(email="*****@*****.**")
        chat = ac1.create_chat_by_contact(c2)
        assert chat.id > const.DC_CHAT_ID_LAST_SPECIAL
        wait_successful_IMAP_SMTP_connection(ac1)
        wait_configuration_progress(ac1, 1000)

        lp.sec("send out message with bcc to ourselves")
        msg_out = chat.send_text("message2")
        ev = ac1._evlogger.get_matching("DC_EVENT_MSGS_CHANGED")
        assert ev[2] == msg_out.id
        # wait for send out (BCC)
        assert ac1.get_config("bcc_self") == "1"
        self_addr = ac1.get_config("addr")
        ev = ac1._evlogger.get_matching("DC_EVENT_SMTP_MESSAGE_SENT")
        assert self_addr in ev[2]
        ev = ac1._evlogger.get_matching("DC_EVENT_DELETED_BLOB_FILE")

        ac1._evlogger.consume_events()
        lp.sec("send out message without bcc")
        ac1.set_config("bcc_self", "0")
        msg_out = chat.send_text("message3")
        ev = ac1._evlogger.get_matching("DC_EVENT_MSGS_CHANGED")
        assert ev[2] == msg_out.id
        ev = ac1._evlogger.get_matching("DC_EVENT_SMTP_MESSAGE_SENT")
        assert self_addr not in ev[2]
        ev = ac1._evlogger.get_matching("DC_EVENT_DELETED_BLOB_FILE")
    def test_forward_messages(self, acfactory):
        ac1 = acfactory.get_online_configuring_account()
        ac2 = acfactory.get_online_configuring_account()
        c2 = ac1.create_contact(email=ac2.get_config("addr"))
        chat = ac1.create_chat_by_contact(c2)
        assert chat.id >= const.DC_CHAT_ID_LAST_SPECIAL
        wait_successful_IMAP_SMTP_connection(ac1)
        wait_configuration_progress(ac1, 1000)
        wait_successful_IMAP_SMTP_connection(ac2)
        wait_configuration_progress(ac2, 1000)

        msg_out = chat.send_text("message2")

        # wait for other account to receive
        ev = ac2._evlogger.get_matching("DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED")
        assert ev[2] == msg_out.id
        msg_in = ac2.get_message_by_id(msg_out.id)
        assert msg_in.text == "message2"

        # check the message arrived in contact-requests/deaddrop
        chat2 = msg_in.chat
        assert msg_in in chat2.get_messages()
        assert chat2.is_deaddrop()
        assert chat2 == ac2.get_deaddrop_chat()
        chat3 = ac2.create_group_chat("newgroup")
        assert not chat3.is_promoted()
        ac2.forward_messages([msg_in], chat3)
        assert chat3.is_promoted()
        messages = chat3.get_messages()
        ac2.delete_messages(messages)
        assert not chat3.get_messages()
    def test_send_and_receive_image(self, acfactory, lp, data):
        lp.sec("starting accounts, waiting for configuration")
        ac1 = acfactory.get_online_configuring_account()
        ac2 = acfactory.get_online_configuring_account()
        c2 = ac1.create_contact(email=ac2.get_config("addr"))
        chat = ac1.create_chat_by_contact(c2)

        wait_configuration_progress(ac1, 1000)
        wait_configuration_progress(ac2, 1000)

        lp.sec("sending image message from ac1 to ac2")
        path = data.get_path("d.png")
        msg_out = chat.send_image(path)
        ev = ac1._evlogger.get_matching("DC_EVENT_MSG_DELIVERED")
        evt_name, data1, data2 = ev
        assert data1 == chat.id
        assert data2 == msg_out.id
        assert msg_out.get_state().is_out_delivered()

        lp.sec("wait for ac2 to receive message")
        ev = ac2._evlogger.get_matching("DC_EVENT_MSGS_CHANGED")
        assert ev[2] == msg_out.id
        msg_in = ac2.get_message_by_id(msg_out.id)
        assert msg_in.view_type.is_image()
        assert os.path.exists(msg_in.filename)
        assert os.stat(msg_in.filename).st_size == os.stat(path).st_size
Exemple #7
0
 def test_invalid_password(self, acfactory):
     ac1, configdict = acfactory.get_online_config()
     ac1.configure(addr=configdict["addr"], mail_pw="123")
     ac1.start_threads()
     wait_configuration_progress(ac1, 500)
     ev1 = ac1._evlogger.get_matching("DC_EVENT_ERROR_NETWORK")
     assert "authentication failed" in ev1[2].lower()
     wait_configuration_progress(ac1, 0, 0)
Exemple #8
0
 def test_invalid_domain(self, acfactory):
     ac1, configdict = acfactory.get_online_config()
     ac1.configure(addr=configdict["addr"] + "x",
                   mail_pw=configdict["mail_pw"])
     ac1.start_threads()
     wait_configuration_progress(ac1, 500)
     ev1 = ac1._evlogger.get_matching("DC_EVENT_ERROR_NETWORK")
     assert "could not connect" in ev1[2].lower()
     wait_configuration_progress(ac1, 0, 0)
    def test_set_get_profile_image(self, acfactory, data, lp):
        ac1 = acfactory.get_online_configuring_account()
        ac2 = acfactory.get_online_configuring_account()
        wait_configuration_progress(ac2, 1000)
        wait_configuration_progress(ac1, 1000)

        lp.sec("create unpromoted group chat")
        chat = ac1.create_group_chat("hello")
        p = data.get_path("d.png")

        lp.sec("ac1: set profile image on unpromoted chat")
        chat.set_profile_image(p)
        ac1._evlogger.get_matching("DC_EVENT_CHAT_MODIFIED")
        assert not chat.is_promoted()

        lp.sec("ac1: send text to promote chat (XXX without contact added)")
        # XXX first promote the chat before adding contact
        # because DC does not send out profile images for unpromoted chats
        # otherwise
        chat.send_text("ac1: initial message to promote chat (workaround)")
        assert chat.is_promoted()

        lp.sec(
            "ac2: add ac1 to a chat so the message does not land in DEADDROP")
        c1 = ac2.create_contact(email=ac1.get_config("addr"))
        ac2.create_chat_by_contact(c1)
        ev = ac2._evlogger.get_matching("DC_EVENT_MSGS_CHANGED")

        lp.sec("ac1: add ac2 to promoted group chat")
        c2 = ac1.create_contact(email=ac2.get_config("addr"))
        chat.add_contact(c2)

        lp.sec("ac1: send a first message to ac2")
        chat.send_text("hi")
        assert chat.is_promoted()

        lp.sec("ac2: wait for receiving message from ac1")
        ev = ac2._evlogger.get_matching("DC_EVENT_INCOMING_MSG")
        msg_in = ac2.get_message_by_id(ev[2])
        assert not msg_in.chat.is_deaddrop()

        lp.sec("ac2: create chat and read profile image")
        chat2 = ac2.create_chat_by_message(msg_in)
        p2 = chat2.get_profile_image()
        assert p2 is not None
        assert open(p2, "rb").read() == open(p, "rb").read()

        ac2._evlogger.consume_events()
        ac1._evlogger.consume_events()
        lp.sec("ac2: delete profile image from chat")
        chat2.remove_profile_image()
        ev = ac1._evlogger.get_matching("DC_EVENT_INCOMING_MSG")
        assert ev[1] == chat.id
        chat1b = ac1.create_chat_by_message(ev[2])
        assert chat1b.get_profile_image() is None
        assert chat.get_profile_image() is None
Exemple #10
0
 def test_mvbox_sentbox_threads(self, acfactory):
     ac1 = acfactory.get_online_configuring_account(mvbox=True,
                                                    sentbox=True)
     ac2 = acfactory.get_online_configuring_account()
     wait_configuration_progress(ac2, 1000)
     wait_configuration_progress(ac1, 1000)
     chat = self.get_chat(ac1, ac2)
     chat.send_text("message1")
     ev = ac2._evlogger.get_matching(
         "DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED")
     assert ev[2] > const.DC_CHAT_ID_LAST_SPECIAL
 def test_qr_setup_contact(self, acfactory, lp):
     ac1 = acfactory.get_online_configuring_account()
     ac2 = acfactory.get_online_configuring_account()
     wait_configuration_progress(ac2, 1000)
     wait_configuration_progress(ac1, 1000)
     lp.sec(
         "ac1: create QR code and let ac2 scan it, starting the securejoin")
     qr = ac1.get_setup_contact_qr()
     lp.sec("ac2: start QR-code based setup contact protocol")
     ch = ac2.qr_setup_contact(qr)
     assert ch.id >= 10
     wait_securejoin_inviter_progress(ac1, 1000)
Exemple #12
0
    def test_one_account_send(self, acfactory):
        ac1 = acfactory.get_online_configuring_account()
        c2 = ac1.create_contact(email=ac1.get_config("addr"))
        chat = ac1.create_chat_by_contact(c2)
        assert chat.id >= const.DC_CHAT_ID_LAST_SPECIAL
        wait_successful_IMAP_SMTP_connection(ac1)
        wait_configuration_progress(ac1, 1000)

        msg_out = chat.send_text("message2")
        # wait for own account to receive
        ev = ac1._evlogger.get_matching("DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED")
        assert ev[1] == msg_out.id
    def test_increation_not_blobdir(self, tmpdir, acfactory, lp):
        ac1 = acfactory.get_online_configuring_account()
        ac2 = acfactory.get_online_configuring_account()
        wait_configuration_progress(ac1, 1000)
        wait_configuration_progress(ac2, 1000)

        c2 = ac1.create_contact(email=ac2.get_config("addr"))
        chat = ac1.create_chat_by_contact(c2)

        lp.sec("Creating in-creation file outside of blobdir")
        assert tmpdir.strpath != ac1.get_blobdir()
        src = tmpdir.join('file.txt').ensure(file=1)
        with pytest.raises(Exception):
            chat.prepare_message_file(src.strpath)
    def test_send_and_receive_message(self, acfactory, lp):
        lp.sec("starting accounts, waiting for configuration")
        ac1 = acfactory.get_online_configuring_account()
        ac2 = acfactory.get_online_configuring_account()
        c2 = ac1.create_contact(email=ac2.get_config("addr"))
        chat = ac1.create_chat_by_contact(c2)
        assert chat.id >= const.DC_CHAT_ID_LAST_SPECIAL

        wait_configuration_progress(ac1, 1000)
        wait_configuration_progress(ac2, 1000)

        lp.sec("sending text message from ac1 to ac2")
        msg_out = chat.send_text("message1")
        ev = ac1._evlogger.get_matching("DC_EVENT_MSG_DELIVERED")
        evt_name, data1, data2 = ev
        assert data1 == chat.id
        assert data2 == msg_out.id
        assert msg_out.is_out_delivered()

        lp.sec("wait for ac2 to receive message")
        ev = ac2._evlogger.get_matching("DC_EVENT_MSGS_CHANGED")
        assert ev[2] == msg_out.id
        msg_in = ac2.get_message_by_id(msg_out.id)
        assert msg_in.text == "message1"

        lp.sec("check the message arrived in contact-requets/deaddrop")
        chat2 = msg_in.chat
        assert msg_in in chat2.get_messages()
        assert chat2.is_deaddrop()
        assert chat2.count_fresh_messages() == 0
        assert msg_in.time_received > msg_in.time_sent

        lp.sec("create new chat with contact and verify it's proper")
        chat2b = ac2.create_chat_by_message(msg_in)
        assert not chat2b.is_deaddrop()
        assert chat2b.count_fresh_messages() == 1

        lp.sec("mark chat as noticed")
        chat2b.mark_noticed()
        assert chat2b.count_fresh_messages() == 0

        lp.sec("mark message as seen on ac2, wait for changes on ac1")
        ac2.mark_seen_messages([msg_in])
        lp.step("1")
        ev = ac1._evlogger.get_matching("DC_EVENT_MSG_READ")
        assert ev[1] >= const.DC_CHAT_ID_LAST_SPECIAL
        assert ev[2] >= const.DC_MSG_ID_LAST_SPECIAL
        lp.step("2")
        assert msg_out.is_out_mdn_received()
    def test_no_increation_copies_to_blobdir(self, tmpdir, acfactory, lp):
        ac1 = acfactory.get_online_configuring_account()
        ac2 = acfactory.get_online_configuring_account()
        wait_configuration_progress(ac1, 1000)
        wait_configuration_progress(ac2, 1000)

        c2 = ac1.create_contact(email=ac2.get_config("addr"))
        chat = ac1.create_chat_by_contact(c2)

        lp.sec("Creating file outside of blobdir")
        assert tmpdir.strpath != ac1.get_blobdir()
        src = tmpdir.join('file.txt')
        src.write("hello there\n")
        chat.send_file(src.strpath)

        blob_src = os.path.join(ac1.get_blobdir(), 'file.txt')
        assert os.path.exists(blob_src), "file.txt not copied to blobdir"
    def test_import_export_online_all(self, acfactory, tmpdir, lp):
        ac1 = acfactory.get_online_configuring_account()
        wait_configuration_progress(ac1, 1000)

        lp.sec("create some chat content")
        contact1 = ac1.create_contact("*****@*****.**", name="some1")
        chat = ac1.create_chat_by_contact(contact1)
        chat.send_text("msg1")
        backupdir = tmpdir.mkdir("backup")

        lp.sec("export all to {}".format(backupdir))
        path = ac1.export_all(backupdir.strpath)
        assert os.path.exists(path)
        t = time.time()

        lp.sec("get fresh empty account")
        ac2 = acfactory.get_unconfigured_account()

        lp.sec("get latest backup file")
        path2 = ac2.get_latest_backupfile(backupdir.strpath)
        assert path2 == path

        lp.sec("import backup and check it's proper")
        ac2.import_all(path)
        contacts = ac2.get_contacts(query="some1")
        assert len(contacts) == 1
        contact2 = contacts[0]
        assert contact2.addr == "*****@*****.**"
        chat2 = ac2.create_chat_by_contact(contact2)
        messages = chat2.get_messages()
        assert len(messages) == 1
        assert messages[0].text == "msg1"

        pytest.xfail(
            "cannot export twice yet, probably due to interrupt_idle failing")
        # wait until a second passed since last backup
        # because get_latest_backupfile() shall return the latest backup
        # from a UI it's unlikely anyone manages to export two
        # backups in one second.
        time.sleep(max(0, 1 - (time.time() - t)))
        lp.sec("Second-time export all to {}".format(backupdir))
        path2 = ac1.export_all(backupdir.strpath)
        assert os.path.exists(path2)
        assert path2 != path
        assert ac2.get_latest_backupfile(backupdir.strpath) == path2
Exemple #17
0
 def test_ac_setup_message(self, acfactory):
     # note that the receiving account needs to be configured and running
     # before ther setup message is send. DC does not read old messages
     # as of Jul2019
     ac1 = acfactory.get_online_configuring_account()
     ac2 = acfactory.clone_online_account(ac1)
     wait_configuration_progress(ac2, 1000)
     wait_configuration_progress(ac1, 1000)
     assert ac1.get_info()["fingerprint"] != ac2.get_info()["fingerprint"]
     setup_code = ac1.initiate_key_transfer()
     ac2._evlogger.set_timeout(30)
     ev = ac2._evlogger.get_matching("DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED")
     msg = ac2.get_message_by_id(ev[2])
     assert msg.is_setup_message()
     print("*************** Incoming ASM File at: ", msg.filename)
     print("*************** Setup Code: ", setup_code)
     msg.continue_key_transfer(setup_code)
     assert ac1.get_info()["fingerprint"] == ac2.get_info()["fingerprint"]
Exemple #18
0
    def test_two_acocunts_send_receive(self, acfactory):
        ac1 = acfactory.get_online_configuring_account()
        ac2 = acfactory.get_online_configuring_account()
        c2 = ac1.create_contact(email=ac2.get_config("addr"))
        chat = ac1.create_chat_by_contact(c2)
        assert chat.id >= const.DC_CHAT_ID_LAST_SPECIAL
        wait_successful_IMAP_SMTP_connection(ac1)
        wait_configuration_progress(ac1, 1000)
        wait_successful_IMAP_SMTP_connection(ac2)
        wait_configuration_progress(ac2, 1000)

        msg_out = chat.send_text("message1")

        # wait for other account to receive
        ev = ac2._evlogger.get_matching(
            "DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED")
        assert ev[2] == msg_out.id
        msg_in = ac2.get_message_by_id(msg_out.id)
        assert msg_in.text == "message1"
Exemple #19
0
    def test_saved_mime_on_received_message(self, acfactory, lp):
        lp.sec("starting accounts, waiting for configuration")
        ac1 = acfactory.get_online_configuring_account()
        ac2 = acfactory.get_online_configuring_account()
        ac2.set_config("save_mime_headers", "1")
        c2 = ac1.create_contact(email=ac2.get_config("addr"))
        chat = ac1.create_chat_by_contact(c2)
        wait_configuration_progress(ac1, 1000)
        wait_configuration_progress(ac2, 1000)
        lp.sec("sending text message from ac1 to ac2")
        msg_out = chat.send_text("message1")
        ac1._evlogger.get_matching("DC_EVENT_MSG_DELIVERED")
        assert msg_out.get_mime_headers() is None

        lp.sec("wait for ac2 to receive message")
        ev = ac2._evlogger.get_matching("DC_EVENT_MSGS_CHANGED")
        in_id = ev[2]
        mime = ac2.get_message_by_id(in_id).get_mime_headers()
        assert mime.get_all("From")
        assert mime.get_all("Received")
    def test_import_export_online(self, acfactory, tmpdir):
        backupdir = tmpdir.mkdir("backup")
        ac1 = acfactory.get_online_configuring_account()
        wait_configuration_progress(ac1, 1000)

        contact1 = ac1.create_contact("*****@*****.**", name="some1")
        chat = ac1.create_chat_by_contact(contact1)
        chat.send_text("msg1")
        path = ac1.export_to_dir(backupdir.strpath)
        assert os.path.exists(path)

        ac2 = acfactory.get_unconfigured_account()
        ac2.import_from_file(path)
        contacts = ac2.get_contacts(query="some1")
        assert len(contacts) == 1
        contact2 = contacts[0]
        assert contact2.addr == "*****@*****.**"
        chat2 = ac2.create_chat_by_contact(contact2)
        messages = chat2.get_messages()
        assert len(messages) == 1
        assert messages[0].text == "msg1"
    def test_ac_setup_message_twice(self, acfactory, lp):
        ac1 = acfactory.get_online_configuring_account()
        ac2 = acfactory.clone_online_account(ac1)
        ac2._evlogger.set_timeout(30)
        wait_configuration_progress(ac2, 1000)
        wait_configuration_progress(ac1, 1000)
        lp.sec("trigger ac setup message but ignore")
        assert ac1.get_info()["fingerprint"] != ac2.get_info()["fingerprint"]
        ac1.initiate_key_transfer()
        ac2._evlogger.get_matching(
            "DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED")

        lp.sec("trigger second ac setup message, wait for receive ")
        setup_code2 = ac1.initiate_key_transfer()
        ev = ac2._evlogger.get_matching(
            "DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED")
        msg = ac2.get_message_by_id(ev[2])
        assert msg.is_setup_message()
        assert msg.get_setupcodebegin() == setup_code2[:2]
        lp.sec("process second setup message")
        msg.continue_key_transfer(setup_code2)
        assert ac1.get_info()["fingerprint"] == ac2.get_info()["fingerprint"]
Exemple #22
0
 def test_configure_canceled(self, acfactory):
     ac1 = acfactory.get_online_configuring_account()
     wait_configuration_progress(ac1, 200)
     ac1.stop_ongoing()
     wait_configuration_progress(ac1, 0, 0)
    def test_forward_increation(self, acfactory, data, lp):
        ac1 = acfactory.get_online_configuring_account()
        ac2 = acfactory.get_online_configuring_account()
        wait_configuration_progress(ac1, 1000)
        wait_configuration_progress(ac2, 1000)

        c2 = ac1.create_contact(email=ac2.get_config("addr"))
        chat = ac1.create_chat_by_contact(c2)
        assert chat.id >= const.DC_CHAT_ID_LAST_SPECIAL
        wait_msgs_changed(ac1, 0, 0)  # why no chat id?

        lp.sec("create a message with a file in creation")
        path = data.get_path("d.png")
        prepared_original = chat.prepare_message_file(path)
        assert prepared_original.is_out_preparing()
        wait_msgs_changed(ac1, chat.id, prepared_original.id)

        lp.sec("forward the message while still in creation")
        chat2 = ac1.create_group_chat("newgroup")
        chat2.add_contact(c2)
        wait_msgs_changed(ac1, 0, 0)  # why not chat id?
        ac1.forward_messages([prepared_original], chat2)
        # XXX there might be two EVENT_MSGS_CHANGED and only one of them
        # is the one caused by forwarding
        forwarded_id = wait_msgs_changed(ac1, chat2.id)
        if forwarded_id == 0:
            forwarded_id = wait_msgs_changed(ac1, chat2.id)
            assert forwarded_id
        forwarded_msg = ac1.get_message_by_id(forwarded_id)
        assert forwarded_msg.is_out_preparing()

        lp.sec("finish creating the file and send it")
        assert prepared_original.is_out_preparing()
        chat.send_prepared(prepared_original)
        assert prepared_original.is_out_pending(
        ) or prepared_original.is_out_delivered()
        wait_msgs_changed(ac1, chat.id, prepared_original.id)

        lp.sec("expect the forwarded message to be sent now too")
        wait_msgs_changed(ac1, chat2.id, forwarded_id)
        fwd_msg = ac1.get_message_by_id(forwarded_id)
        assert fwd_msg.is_out_pending() or fwd_msg.is_out_delivered()

        lp.sec("wait for the messages to be delivered to SMTP")
        ev = ac1._evlogger.get_matching("DC_EVENT_MSG_DELIVERED")
        assert ev[1] == chat.id
        assert ev[2] == prepared_original.id
        ev = ac1._evlogger.get_matching("DC_EVENT_MSG_DELIVERED")
        assert ev[1] == chat2.id
        assert ev[2] == forwarded_id

        lp.sec("wait1 for original or forwarded messages to arrive")
        ev1 = ac2._evlogger.get_matching("DC_EVENT_MSGS_CHANGED")
        assert ev1[1] >= const.DC_CHAT_ID_LAST_SPECIAL
        received_original = ac2.get_message_by_id(ev1[2])
        assert cmp(received_original.filename, path, False)

        lp.sec("wait2 for original or forwarded messages to arrive")
        ev2 = ac2._evlogger.get_matching("DC_EVENT_MSGS_CHANGED")
        assert ev2[1] >= const.DC_CHAT_ID_LAST_SPECIAL
        assert ev2[1] != ev1[1]
        received_copy = ac2.get_message_by_id(ev2[2])
        assert cmp(received_copy.filename, path, False)
 def test_one_account_init(self, acfactory):
     ac1 = acfactory.get_online_configuring_account()
     wait_successful_IMAP_SMTP_connection(ac1)
     wait_configuration_progress(ac1, 1000)