コード例 #1
0
    def test_unpack_devicelist_request_result_for_own_devices(self, mockdb):
        mockdb.return_value = get_test_db_connection()
        test_stanza = (
            '<iq id="0x011" to="[email protected]/profanity" type="result">'
            '<pubsub xmlns="http://jabber.org/protocol/pubsub">'
            '<items node="{0}">'
            '<item id="1">'
            '<list xmlns="{1}">'
            '<device id="1426586702"/>'
            '</list>'
            '</item>'
            '</items>'
            '</pubsub>'
            '</iq>').format(NS_DEVICE_LIST, NS_OMEMO)

        current_user = '******'
        ProfOmemoUser.set_user(current_user, current_user + '/profanity')

        msg_dict = xmpp.unpack_devicelist_info(test_stanza)
        expected_msg_dict = {'from': current_user, 'devices': [1426586702]}

        assert msg_dict == expected_msg_dict
コード例 #2
0
    def test_unpack_devicelist_update(self, mockdb):
        mockdb.return_value = get_test_db_connection()
        test_stanza = (
            '<message from="*****@*****.**" to="*****@*****.**" type="headline" id="update_01">'
                '<event xmlns="http://jabber.org/protocol/pubsub#event">'
                '<items node="{0}">'
                    '<item>'
                        '<list xmlns="{1}">'
                            '<device id="12345" />'
                            '<device id="4223" />'
                        '</list>'
                    '</item>'
                '</items>'
                '</event>'
            '</message>'
        ).format(NS_DEVICE_LIST, NS_OMEMO)

        msg_dict = xmpp.unpack_devicelist_info(test_stanza)
        expected_msg_dict = {'from': '*****@*****.**',
                             'devices': [12345, 4223]}

        assert msg_dict == expected_msg_dict
コード例 #3
0
    def test_unpack_devicelist_update(self, mockdb):
        mockdb.return_value = get_test_db_connection()
        test_stanza = (
            '<message from="*****@*****.**" to="*****@*****.**" type="headline" id="update_01">'
            '<event xmlns="http://jabber.org/protocol/pubsub#event">'
            '<items node="{0}">'
            '<item>'
            '<list xmlns="{1}">'
            '<device id="12345" />'
            '<device id="4223" />'
            '</list>'
            '</item>'
            '</items>'
            '</event>'
            '</message>').format(NS_DEVICE_LIST, NS_OMEMO)

        msg_dict = xmpp.unpack_devicelist_info(test_stanza)
        expected_msg_dict = {
            'from': '*****@*****.**',
            'devices': [12345, 4223]
        }

        assert msg_dict == expected_msg_dict
コード例 #4
0
def _handle_devicelist_update(stanza):
    omemo_state = ProfOmemoState()
    own_jid = omemo_state.own_jid
    msg_dict = xmpp.unpack_devicelist_info(stanza)
    sender_jid = msg_dict['from']
    log.info('Received devicelist update from {0}'.format(sender_jid))

    known_devices = omemo_state.device_list_for(sender_jid)
    new_devices = msg_dict['devices']

    added_devices = set(new_devices) - known_devices

    if added_devices:
        device_str = ', '.join([str(d) for d in added_devices])
        msg = '{0} added devices with IDs {1}'.format(sender_jid, device_str)
        show_chat_warning(sender_jid, msg)
        xmpp.update_devicelist(own_jid, sender_jid, new_devices)

    if not omemo_state.own_device_id_published():
        _announce_own_devicelist()

    if sender_jid != own_jid:
        add_recipient_to_completer(sender_jid)
コード例 #5
0
def _handle_devicelist_update(stanza):
    omemo_state = ProfOmemoState()
    own_jid = omemo_state.own_jid
    msg_dict = xmpp.unpack_devicelist_info(stanza)
    sender_jid = msg_dict['from']
    log.info('Received devicelist update from {0}'.format(sender_jid))

    known_devices = omemo_state.device_list_for(sender_jid)
    new_devices = msg_dict['devices']

    added_devices = set(new_devices) - known_devices

    if added_devices:
        device_str = ', '.join([str(d) for d in added_devices])
        msg = '{0} added devices with IDs {1}'.format(sender_jid, device_str)
        show_chat_warning(sender_jid, msg)
        xmpp.update_devicelist(own_jid, sender_jid, new_devices)

    if not omemo_state.own_device_id_published():
        _announce_own_devicelist()

    if sender_jid != own_jid:
        add_recipient_to_completer(sender_jid)
コード例 #6
0
    def test_unpack_devicelist_request_result_for_own_devices(self, mockdb):
        mockdb.return_value = get_test_db_connection()
        test_stanza = ('<iq id="0x011" to="[email protected]/profanity" type="result">'
                           '<pubsub xmlns="http://jabber.org/protocol/pubsub">'
                               '<items node="{0}">'
                                '<item id="1">'
                                    '<list xmlns="{1}">'
                                        '<device id="1426586702"/>'
                                    '</list>'
                                '</item>'
                               '</items>'
                           '</pubsub>'
                       '</iq>'
        ).format(NS_DEVICE_LIST, NS_OMEMO)

        current_user = '******'
        ProfOmemoUser.set_user(current_user, current_user + '/profanity')

        msg_dict = xmpp.unpack_devicelist_info(test_stanza)
        expected_msg_dict = {'from': current_user,
                             'devices': [1426586702]}

        assert msg_dict == expected_msg_dict