9578053 Jan 22 2022 distfiles.gentoo.org/distfiles/gajim-1.3.3-2.tar.gz
This commit is contained in:
parent
a5b3822651
commit
4c1b226bff
1045 changed files with 753037 additions and 18 deletions
220
test/broken/integration/test_gui_event_integration.py
Normal file
220
test/broken/integration/test_gui_event_integration.py
Normal file
|
@ -0,0 +1,220 @@
|
|||
'''
|
||||
Tests for the miscellaneous functions scattered throughout gajim/gajim.py
|
||||
'''
|
||||
import unittest
|
||||
|
||||
import lib
|
||||
lib.setup_env()
|
||||
|
||||
import nbxmpp
|
||||
|
||||
from gajim.common import gajim
|
||||
from gajim.common import contacts as contacts_module
|
||||
from gajim.common import caps_cache
|
||||
from gajim.gajim import Interface
|
||||
|
||||
from gajim_mocks import *
|
||||
gajim.logger = MockLogger()
|
||||
|
||||
Interface()
|
||||
|
||||
import time
|
||||
from data import *
|
||||
|
||||
from gajim import roster_window
|
||||
from gajim import plugins
|
||||
|
||||
class TestStatusChange(unittest.TestCase):
|
||||
'''tests gajim.py's incredibly complex presence handling'''
|
||||
|
||||
def setUp(self):
|
||||
|
||||
gajim.connections = {}
|
||||
gajim.contacts = contacts_module.LegacyContactsAPI()
|
||||
gajim.interface.roster = roster_window.RosterWindow()
|
||||
gajim.plugin_manager = plugins.PluginManager()
|
||||
gajim.logger = MockLogger()
|
||||
caps_cache.initialize(gajim.logger)
|
||||
|
||||
for acc in contacts:
|
||||
gajim.connections[acc] = MockConnection(acc)
|
||||
|
||||
gajim.interface.roster.fill_contacts_and_groups_dicts(contacts[acc],
|
||||
acc)
|
||||
gajim.interface.roster.add_account(acc)
|
||||
gajim.interface.roster.add_account_contacts(acc)
|
||||
|
||||
self.assertEqual(0, len(notify.notifications))
|
||||
|
||||
def tearDown(self):
|
||||
notify.notifications = []
|
||||
for acc in contacts:
|
||||
gajim.connections[acc].cleanup()
|
||||
|
||||
def contact_comes_online(self, account, jid, resource, prio,
|
||||
should_popup=True):
|
||||
'''a remote contact comes online'''
|
||||
xml = """<presence from='%s/%s' id='123'><priority>%s</priority>
|
||||
<c node='http://gajim.org' ver='pRCD6cgQ4SDqNMCjdhRV6TECx5o='
|
||||
hash='sha-1' xmlns='http://jabber.org/protocol/caps'/>
|
||||
<status>I'm back!</status>
|
||||
</presence>
|
||||
""" % (jid, resource, prio)
|
||||
msg = nbxmpp.protocol.Presence(node=nbxmpp.simplexml.XML2Node(xml))
|
||||
gajim.connections[account]._presenceCB(None, msg)
|
||||
|
||||
contact = None
|
||||
for c in gajim.contacts.get_contacts(account, jid):
|
||||
if c.resource == resource:
|
||||
contact = c
|
||||
break
|
||||
|
||||
self.assertEqual('online', contact.show)
|
||||
self.assertEqual("I'm back!", contact.status)
|
||||
self.assertEqual(prio, contact.priority)
|
||||
|
||||
# the most recent notification is that the contact connected
|
||||
if should_popup:
|
||||
self.assertEqual('Contact Signed In',
|
||||
notify.notifications[-1].popup_event_type)
|
||||
else:
|
||||
self.assertEqual('', notify.notifications[-1].popup_event_type)
|
||||
|
||||
def contact_goes_offline(self, account, jid, resource, prio,
|
||||
still_exists = True):
|
||||
'''a remote contact goes offline.'''
|
||||
xml = """<presence type='unavailable' from='%s/%s' id='123'>
|
||||
<priority>%s</priority>
|
||||
<c node='http://gajim.org' ver='pRCD6cgQ4SDqNMCjdhRV6TECx5o='
|
||||
hash='sha-1' xmlns='http://jabber.org/protocol/caps'/>
|
||||
<status>Goodbye!</status>
|
||||
</presence>
|
||||
""" % (jid, resource, prio)
|
||||
msg = nbxmpp.protocol.Presence(node=nbxmpp.simplexml.XML2Node(xml))
|
||||
gajim.connections[account]._presenceCB(None, msg)
|
||||
|
||||
contact = None
|
||||
for c in gajim.contacts.get_contacts(account, jid):
|
||||
if c.resource == resource:
|
||||
contact = c
|
||||
break
|
||||
|
||||
if not still_exists:
|
||||
self.assertTrue(contact is None)
|
||||
return
|
||||
|
||||
self.assertEqual('offline', contact.show)
|
||||
self.assertEqual('Goodbye!', contact.status)
|
||||
self.assertEqual(prio, contact.priority)
|
||||
|
||||
self.assertEqual('Contact Signed Out',
|
||||
notify.notifications[-1].popup_event_type)
|
||||
|
||||
def user_starts_chatting(self, jid, account, resource=None):
|
||||
'''the user opens a chat window and starts talking'''
|
||||
ctrl = MockChatControl(jid, account)
|
||||
win = MockWindow()
|
||||
win.new_tab(ctrl)
|
||||
gajim.interface.msg_win_mgr._windows['test'] = win
|
||||
|
||||
if resource:
|
||||
jid = jid + '/' + resource
|
||||
|
||||
# a basic session is started
|
||||
session = gajim.connections[account1].make_new_session(jid,
|
||||
'01234567890abcdef', cls=MockSession)
|
||||
ctrl.set_session(session)
|
||||
|
||||
return ctrl
|
||||
|
||||
def user_starts_esession(self, jid, resource, account):
|
||||
'''the user opens a chat window and starts an encrypted session'''
|
||||
ctrl = self.user_starts_chatting(jid, account, resource)
|
||||
ctrl.session.status = 'active'
|
||||
ctrl.session.enable_encryption = True
|
||||
|
||||
return ctrl
|
||||
|
||||
def test_contact_comes_online(self):
|
||||
jid = 'default1@gajim.org'
|
||||
|
||||
# contact is offline initially
|
||||
contacts = gajim.contacts.get_contacts(account1, jid)
|
||||
self.assertEqual(1, len(contacts))
|
||||
self.assertEqual('offline', contacts[0].show)
|
||||
self.assertEqual('', contacts[0].status)
|
||||
|
||||
self.contact_comes_online(account1, jid, 'lowprio', 1)
|
||||
|
||||
def test_contact_goes_offline(self):
|
||||
jid = 'default1@gajim.org'
|
||||
|
||||
self.contact_comes_online(account1, jid, 'lowprio', 1)
|
||||
|
||||
ctrl = self.user_starts_chatting(jid, account1)
|
||||
orig_sess = ctrl.session
|
||||
|
||||
self.contact_goes_offline(account1, jid, 'lowprio', 1)
|
||||
|
||||
# session hasn't changed since we were talking to the bare jid
|
||||
self.assertEqual(orig_sess, ctrl.session)
|
||||
|
||||
def test_two_resources_higher_comes_online(self):
|
||||
jid = 'default1@gajim.org'
|
||||
|
||||
self.contact_comes_online(account1, jid, 'lowprio', 1)
|
||||
|
||||
ctrl = self.user_starts_chatting(jid, account1)
|
||||
|
||||
self.contact_comes_online(account1, jid, 'highprio', 50,
|
||||
should_popup=False)
|
||||
|
||||
# old session was dropped
|
||||
self.assertEqual(None, ctrl.session)
|
||||
|
||||
def test_two_resources_higher_goes_offline(self):
|
||||
jid = 'default1@gajim.org'
|
||||
|
||||
self.contact_comes_online(account1, jid, 'lowprio', 1)
|
||||
self.contact_comes_online(account1, jid, 'highprio', 50,
|
||||
should_popup=False)
|
||||
|
||||
ctrl = self.user_starts_chatting(jid, account1)
|
||||
|
||||
self.contact_goes_offline(account1, jid, 'highprio', 50,
|
||||
still_exists=False)
|
||||
|
||||
# old session was dropped
|
||||
self.assertEqual(None, ctrl.session)
|
||||
|
||||
def test_two_resources_higher_comes_online_with_esession(self):
|
||||
jid = 'default1@gajim.org'
|
||||
|
||||
self.contact_comes_online(account1, jid, 'lowprio', 1)
|
||||
|
||||
ctrl = self.user_starts_esession(jid, 'lowprio', account1)
|
||||
|
||||
self.contact_comes_online(account1, jid, 'highprio', 50,
|
||||
should_popup=False)
|
||||
|
||||
# session was associated with the low priority full jid, so it should
|
||||
# have been removed from the control
|
||||
self.assertEqual(None, ctrl.session)
|
||||
|
||||
def test_two_resources_higher_goes_offline_with_esession(self):
|
||||
jid = 'default1@gajim.org'
|
||||
|
||||
self.contact_comes_online(account1, jid, 'lowprio', 1)
|
||||
self.contact_comes_online(account1, jid, 'highprio', 50)
|
||||
|
||||
ctrl = self.user_starts_esession(jid, 'highprio', account1)
|
||||
|
||||
self.contact_goes_offline(account1, jid, 'highprio', 50,
|
||||
still_exists=False)
|
||||
|
||||
# session was associated with the high priority full jid, so it should
|
||||
# have been removed from the control
|
||||
self.assertEqual(None, ctrl.session)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
211
test/broken/integration/test_roster.py
Normal file
211
test/broken/integration/test_roster.py
Normal file
|
@ -0,0 +1,211 @@
|
|||
import unittest
|
||||
|
||||
import lib
|
||||
lib.setup_env()
|
||||
|
||||
from data import *
|
||||
|
||||
from gajim_mocks import *
|
||||
|
||||
from gajim.common import app
|
||||
from gajim.common import contacts as contacts_module
|
||||
from gajim import roster_window
|
||||
|
||||
app.get_jid_from_account = lambda acc: 'myjid@' + acc
|
||||
|
||||
|
||||
class TestRosterWindow(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
app.interface = MockInterface()
|
||||
|
||||
self.C_NAME = roster_window.Column.NAME
|
||||
self.C_TYPE = roster_window.Column.TYPE
|
||||
self.C_JID = roster_window.Column.JID
|
||||
self.C_ACCOUNT = roster_window.Column.ACCOUNT
|
||||
|
||||
# Add after creating RosterWindow
|
||||
# We want to test the filling explicitly
|
||||
app.contacts = contacts_module.LegacyContactsAPI()
|
||||
app.connections = {}
|
||||
self.roster = roster_window.RosterWindow(app.app)
|
||||
|
||||
for acc in contacts:
|
||||
app.connections[acc] = MockConnection(acc)
|
||||
app.contacts.add_account(acc)
|
||||
|
||||
def tearDown(self):
|
||||
self.roster.window.destroy()
|
||||
# Clean main loop
|
||||
from gi.repository import GLib
|
||||
mc = GLib.main_context_default()
|
||||
while mc.pending():
|
||||
mc.iteration()
|
||||
|
||||
### Custom assertions
|
||||
def assert_all_contacts_are_in_roster(self, acc):
|
||||
for jid in contacts[acc]:
|
||||
self.assert_contact_is_in_roster(jid, acc)
|
||||
|
||||
def assert_contact_is_in_roster(self, jid, account):
|
||||
contacts = app.contacts.get_contacts(account, jid)
|
||||
# check for all resources
|
||||
for contact in contacts:
|
||||
iters = self.roster._get_contact_iter(jid, account,
|
||||
model=self.roster.model)
|
||||
|
||||
if jid != app.get_jid_from_account(account):
|
||||
# We don't care for groups of SelfContact
|
||||
self.assertTrue(len(iters) == len(contact.get_shown_groups()),
|
||||
msg='Contact is not in all his groups')
|
||||
|
||||
# Are we big brother?
|
||||
bb_jid = None
|
||||
bb_account = None
|
||||
family = app.contacts.get_metacontacts_family(account, jid)
|
||||
if family:
|
||||
nearby_family, bb_jid, bb_account = \
|
||||
self.roster._get_nearby_family_and_big_brother(family, account)
|
||||
|
||||
is_in_nearby_family = (jid, account) in (
|
||||
(data['jid'], data['account']) for data in nearby_family)
|
||||
self.assertTrue(is_in_nearby_family,
|
||||
msg='Contact not in his own nearby family')
|
||||
|
||||
is_big_brother = (bb_jid, bb_account) == (jid, account)
|
||||
|
||||
# check for each group tag
|
||||
for titerC in iters:
|
||||
self.assertTrue(self.roster.model.iter_is_valid(titerC),
|
||||
msg='Contact iter invalid')
|
||||
|
||||
c_model = self.roster.model[titerC]
|
||||
# name can be stricked if contact or group is blocked
|
||||
# self.assertEqual(contact.get_shown_name(), c_model[self.C_NAME],
|
||||
# msg='Contact name missmatch')
|
||||
self.assertEqual(contact.jid, c_model[self.C_JID],
|
||||
msg='Jid missmatch')
|
||||
|
||||
if not self.roster.regroup:
|
||||
self.assertEqual(account, c_model[self.C_ACCOUNT],
|
||||
msg='Account missmatch')
|
||||
|
||||
# Check for correct nesting
|
||||
parent_iter = self.roster.model.iter_parent(titerC)
|
||||
p_model = self.roster.model[parent_iter]
|
||||
if family:
|
||||
if is_big_brother:
|
||||
self.assertTrue(p_model[self.C_TYPE] == 'group',
|
||||
msg='Big Brother is not on top')
|
||||
else:
|
||||
self.assertTrue(p_model[self.C_TYPE] == 'contact',
|
||||
msg='Little Brother brother has no BigB')
|
||||
else:
|
||||
if jid == app.get_jid_from_account(account):
|
||||
self.assertTrue(p_model[self.C_TYPE] == 'account',
|
||||
msg='SelfContact is not on top')
|
||||
else:
|
||||
self.assertTrue(p_model[self.C_TYPE] == 'group',
|
||||
msg='Contact not found in a group')
|
||||
|
||||
def assert_group_is_in_roster(self, group, account):
|
||||
#TODO
|
||||
pass
|
||||
|
||||
def assert_account_is_in_roster(self, acc):
|
||||
titerA = self.roster._get_account_iter(acc, model=self.roster.model)
|
||||
self.assertTrue(self.roster.model.iter_is_valid(titerA),
|
||||
msg='Account iter is invalid')
|
||||
|
||||
acc_model = self.roster.model[titerA]
|
||||
self.assertEqual(acc_model[self.C_TYPE], 'account',
|
||||
msg='No account found')
|
||||
|
||||
if not self.roster.regroup:
|
||||
self.assertEqual(acc_model[self.C_ACCOUNT], acc,
|
||||
msg='Account not found')
|
||||
|
||||
self_jid = app.get_jid_from_account(acc)
|
||||
self.assertEqual(acc_model[self.C_JID], self_jid,
|
||||
msg='Account JID not found in account row')
|
||||
|
||||
def assert_model_is_in_sync(self):
|
||||
#TODO: check that iter_n_children returns the correct numbers
|
||||
pass
|
||||
|
||||
# tests
|
||||
def test_fill_contacts_and_groups_dicts(self):
|
||||
for acc in contacts:
|
||||
self.roster.fill_contacts_and_groups_dicts(contacts[acc], acc)
|
||||
|
||||
for jid in contacts[acc]:
|
||||
instances = app.contacts.get_contacts(acc, jid)
|
||||
|
||||
# Created a contact for each single jid?
|
||||
self.assertTrue(len(instances) == 1)
|
||||
|
||||
# Contacts kept their info
|
||||
contact = instances[0]
|
||||
self.assertEqual(sorted(contact.groups), sorted(contacts[acc][jid]['groups']),
|
||||
msg='Group Missmatch')
|
||||
|
||||
groups = contacts[acc][jid]['groups'] or ['General',]
|
||||
|
||||
def test_fill_roster_model(self):
|
||||
for acc in contacts:
|
||||
self.roster.fill_contacts_and_groups_dicts(contacts[acc], acc)
|
||||
|
||||
self.roster.add_account(acc)
|
||||
self.assert_account_is_in_roster(acc)
|
||||
|
||||
self.roster.add_account_contacts(acc)
|
||||
self.assert_all_contacts_are_in_roster(acc)
|
||||
|
||||
self.assert_model_is_in_sync()
|
||||
|
||||
|
||||
class TestRosterWindowRegrouped(TestRosterWindow):
|
||||
|
||||
def setUp(self):
|
||||
app.settings.set('mergeaccounts', True)
|
||||
TestRosterWindow.setUp(self)
|
||||
|
||||
def test_toggle_regroup(self):
|
||||
self.roster.regroup = not self.roster.regroup
|
||||
self.roster.setup_and_draw_roster()
|
||||
self.roster.regroup = not self.roster.regroup
|
||||
self.roster.setup_and_draw_roster()
|
||||
|
||||
|
||||
class TestRosterWindowMetaContacts(TestRosterWindowRegrouped):
|
||||
|
||||
def test_receive_metacontact_data(self):
|
||||
for complete_data in metacontact_data:
|
||||
t_acc = complete_data[0]['account']
|
||||
t_jid = complete_data[0]['jid']
|
||||
data = complete_data[1:]
|
||||
for brother in data:
|
||||
acc = brother['account']
|
||||
jid = brother['jid']
|
||||
app.contacts.add_metacontact(t_acc, t_jid, acc, jid)
|
||||
self.roster.setup_and_draw_roster()
|
||||
|
||||
def test_connect_new_metacontact(self):
|
||||
self.test_fill_roster_model()
|
||||
|
||||
jid = 'coolstuff@gajim.org'
|
||||
contact = app.contacts.create_contact(jid, account1)
|
||||
app.contacts.add_contact(account1, contact)
|
||||
self.roster.add_contact(jid, account1)
|
||||
self.roster.chg_contact_status(contact, 'offline', '', account1)
|
||||
|
||||
app.contacts.add_metacontact(account1, 'samejid@gajim.org',
|
||||
account1, jid)
|
||||
self.roster.chg_contact_status(contact, 'online', '', account1)
|
||||
|
||||
self.assert_model_is_in_sync()
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
89
test/broken/test_pluginmanager.py
Normal file
89
test/broken/test_pluginmanager.py
Normal file
|
@ -0,0 +1,89 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
## This file is part of Gajim.
|
||||
##
|
||||
## Gajim is free software; you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published
|
||||
## by the Free Software Foundation; version 3 only.
|
||||
##
|
||||
## Gajim is distributed in the hope that it will be useful,
|
||||
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
## GNU General Public License for more details.
|
||||
##
|
||||
## You should have received a copy of the GNU General Public License
|
||||
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
||||
##
|
||||
|
||||
'''
|
||||
Testing PluginManager class.
|
||||
|
||||
:author: Mateusz Biliński <mateusz@bilinski.it>
|
||||
:since: 05/30/2008
|
||||
:copyright: Copyright (2008) Mateusz Biliński <mateusz@bilinski.it>
|
||||
:license: GPL
|
||||
'''
|
||||
|
||||
import sys
|
||||
import os
|
||||
import unittest
|
||||
|
||||
gajim_root = os.path.join(os.path.abspath(os.path.dirname(__file__)), '..')
|
||||
sys.path.append(gajim_root + '/gajim')
|
||||
|
||||
# a temporary version of ~/.gajim for testing
|
||||
configdir = gajim_root + '/test/tmp'
|
||||
|
||||
import time
|
||||
|
||||
# define _ for i18n
|
||||
import builtins
|
||||
builtins._ = lambda x: x
|
||||
|
||||
# wipe config directory
|
||||
import os
|
||||
if os.path.isdir(configdir):
|
||||
import shutil
|
||||
shutil.rmtree(configdir)
|
||||
|
||||
os.mkdir(configdir)
|
||||
|
||||
from gajim.common import configpaths
|
||||
configpaths.set_config_root(configdir)
|
||||
configpaths.init()
|
||||
|
||||
# for some reason common.app needs to be imported before xmpppy?
|
||||
|
||||
configpaths.override_path('DATA', gajim_root + '/gajim/data')
|
||||
|
||||
# name to use for the test account
|
||||
account_name = 'test'
|
||||
|
||||
from plugins import PluginManager
|
||||
|
||||
class PluginManagerTestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.pluginmanager = PluginManager()
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def test_01_Singleton(self):
|
||||
""" 1. Checking whether PluginManger class is singleton. """
|
||||
self.pluginmanager.test_arg = 1
|
||||
secondPluginManager = PluginManager()
|
||||
|
||||
self.assertEqual(id(secondPluginManager), id(self.pluginmanager),
|
||||
'Different IDs in references to PluginManager objects (not a singleton)')
|
||||
self.assertEqual(secondPluginManager.test_arg, 1,
|
||||
'References point to different PluginManager objects (not a singleton')
|
||||
|
||||
def suite():
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(PluginManagerTestCase)
|
||||
return suite
|
||||
|
||||
if __name__=='__main__':
|
||||
runner = unittest.TextTestRunner()
|
||||
test_suite = suite()
|
||||
runner.run(test_suite)
|
156
test/broken/unit/test_jingle.py
Normal file
156
test/broken/unit/test_jingle.py
Normal file
|
@ -0,0 +1,156 @@
|
|||
'''
|
||||
Tests for dispatcher.py
|
||||
'''
|
||||
import unittest
|
||||
|
||||
import lib
|
||||
lib.setup_env()
|
||||
|
||||
from mock import Mock
|
||||
|
||||
|
||||
from nbxmpp import dispatcher
|
||||
from nbxmpp.namespaces import Namespace
|
||||
|
||||
from gajim.common.protocol.bytestream import ConnectionIBBytestream
|
||||
from gajim.common.protocol.bytestream import ConnectionSocks5Bytestream
|
||||
from gajim.common.jingle import ConnectionJingle
|
||||
from gajim.common import app
|
||||
from gajim.common.socks5 import SocksQueue
|
||||
|
||||
|
||||
session_init = '''
|
||||
<iq xmlns="jabber:client" to="jingleft@thiessen.im/Gajim" type="set" id="43">
|
||||
<jingle xmlns="urn:xmpp:jingle:1" action="session-initiate" initiator="jtest@thiessen.im/Gajim" sid="38">
|
||||
<content name="fileWL1Y2JIPTM5RAD68" creator="initiator">
|
||||
<security xmlns="urn:xmpp:jingle:security:xtls:0">
|
||||
<method name="x509" />
|
||||
</security>
|
||||
<description xmlns="urn:xmpp:jingle:apps:file-transfer:1">
|
||||
<offer>
|
||||
<file xmlns="http://jabber.org/protocol/si/profile/file-transfer" name="to" size="2273">
|
||||
<desc />
|
||||
</file>
|
||||
</offer>
|
||||
</description>
|
||||
<transport xmlns="urn:xmpp:jingle:transports:s5b:1" sid="39">
|
||||
<candidate jid="jtest@thiessen.im/Gajim" cid="40" priority="8257536" host="192.168.2.100" type="direct" port="28011" />
|
||||
<candidate jid="proxy.thiessen.im" cid="41" priority="655360" host="192.168.2.100" type="proxy" port="5000" />
|
||||
<candidate jid="proxy.jabbim.cz" cid="42" priority="655360" host="192.168.2.100" type="proxy" port="7777" />
|
||||
</transport>
|
||||
</content>
|
||||
</jingle>
|
||||
</iq>
|
||||
'''
|
||||
|
||||
|
||||
transport_info = '''
|
||||
<iq from='jtest@thiessen.im/Gajim'
|
||||
id='hjdi8'
|
||||
to='jingleft@thiessen.im/Gajim'
|
||||
type='set'>
|
||||
<jingle xmlns='urn:xmpp:jingle:1'
|
||||
action='transport-info'
|
||||
initiator='jtest@thiessen.im/Gajim'
|
||||
sid='38'>
|
||||
<content creator='initiator' name='fileWL1Y2JIPTM5RAD68'>
|
||||
<transport xmlns='urn:xmpp:jingle:transports:s5b:1'
|
||||
sid='vj3hs98y'>
|
||||
<candidate-used cid='hr65dqyd'/>
|
||||
</transport>
|
||||
</content>
|
||||
</jingle>
|
||||
</iq>
|
||||
|
||||
'''
|
||||
|
||||
class Connection(Mock, ConnectionJingle, ConnectionSocks5Bytestream,
|
||||
ConnectionIBBytestream):
|
||||
|
||||
def __init__(self):
|
||||
Mock.__init__(self)
|
||||
ConnectionJingle.__init__(self)
|
||||
ConnectionSocks5Bytestream.__init__(self)
|
||||
ConnectionIBBytestream.__init__(self)
|
||||
self.connected = 2 # This tells gajim we are connected
|
||||
|
||||
def send(self, stanza=None, when=None):
|
||||
# Called when gajim wants to send something
|
||||
print(str(stanza))
|
||||
|
||||
|
||||
class TestJingle(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.dispatcher = dispatcher.XMPPDispatcher()
|
||||
app.nec = Mock()
|
||||
app.socks5queue = SocksQueue(Mock())
|
||||
# Setup mock client
|
||||
self.client = Connection()
|
||||
self.client.__str__ = lambda: 'Mock' # FIXME: why do I need this one?
|
||||
self.client._caller = Connection()
|
||||
self.client.defaultNamespace = Namespace.CLIENT
|
||||
self.client.Connection = Connection() # mock transport
|
||||
self.con = self.client.Connection
|
||||
self.con.server_resource = None
|
||||
self.con.connection = Connection()
|
||||
|
||||
'''
|
||||
Fake file_props when we receive a file. Gajim creates a file_props
|
||||
out of a FileRequestReceive event and from then on it changes in
|
||||
a lot of places. It is easier to just copy it in here.
|
||||
If the session_initiate stanza changes, this also must change.
|
||||
'''
|
||||
self.receive_file = {'stream-methods':
|
||||
'http://jabber.org/protocol/bytestreams',
|
||||
'sender': 'jtest@thiessen.im/Gajim',
|
||||
'file-name': 'test_received_file',
|
||||
'request-id': '43', 'sid': '39',
|
||||
'session-sid': '38', 'session-type': 'jingle',
|
||||
'transfered_size': [], 'receiver':
|
||||
'jingleft@thiessen.im/Gajim', 'desc': '',
|
||||
'size': '2273', 'type': 'r',
|
||||
'streamhosts': [{'initiator':
|
||||
'jtest@thiessen.im/Gajim',
|
||||
'target': 'jingleft@thiessen.im/Gajim',
|
||||
'cid': '41', 'state': 0, 'host': '192.168.2.100',
|
||||
'type': 'direct', 'port': '28011'},
|
||||
{'initiator': 'jtest@thiessen.im/Gajim',
|
||||
'target': 'jingleft@thiessen.im/Gajim',
|
||||
'cid': '42', 'state': 0, 'host': '192.168.2.100',
|
||||
'type': 'proxy', 'port': '5000'}],
|
||||
'name': 'to'}
|
||||
|
||||
def tearDown(self):
|
||||
# Unplug if needed
|
||||
if hasattr(self.dispatcher, '_owner'):
|
||||
self.dispatcher.PlugOut()
|
||||
|
||||
def _simulate_connect(self):
|
||||
self.dispatcher.PlugIn(self.client) # client is owner
|
||||
# Simulate that we have established a connection
|
||||
self.dispatcher.StreamInit()
|
||||
self.dispatcher.ProcessNonBlocking("<stream:stream xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client'>")
|
||||
|
||||
def _simulate_jingle_session(self):
|
||||
|
||||
self.dispatcher.RegisterHandler('iq', self.con._JingleCB, 'set',
|
||||
Namespace.JINGLE)
|
||||
self.dispatcher.ProcessNonBlocking(session_init)
|
||||
session = list(self.con._sessions.values())[0] # The only session we have
|
||||
jft = list(session.contents.values())[0] # jingleFT object
|
||||
jft.file_props = self.receive_file # We plug file_props manually
|
||||
# The user accepts to receive the file
|
||||
# we have to manually simulate this behavior
|
||||
session.approve_session()
|
||||
self.con.send_file_approval(self.receive_file)
|
||||
|
||||
self.dispatcher.ProcessNonBlocking(transport_info)
|
||||
|
||||
def test_jingle_session(self):
|
||||
self._simulate_connect()
|
||||
self._simulate_jingle_session()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
167
test/broken/unit/test_sessions.py
Normal file
167
test/broken/unit/test_sessions.py
Normal file
|
@ -0,0 +1,167 @@
|
|||
import unittest
|
||||
|
||||
import lib
|
||||
lib.setup_env()
|
||||
|
||||
import notify
|
||||
import nbxmpp
|
||||
|
||||
from gajim.common import app
|
||||
from gajim.common import nec
|
||||
from gajim.common import ged
|
||||
from gajim.common.nec import NetworkEvent
|
||||
|
||||
from gajim.session import ChatControlSession
|
||||
from gajim.roster_window import RosterWindow
|
||||
|
||||
from gajim_mocks import *
|
||||
from data import account1
|
||||
|
||||
app.interface = MockInterface()
|
||||
|
||||
|
||||
# name to use for the test account
|
||||
account_name = account1
|
||||
|
||||
|
||||
class TestChatControlSession(unittest.TestCase):
|
||||
''' Testclass for session.py '''
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
app.nec = nec.NetworkEventsController()
|
||||
cls.conn = MockConnection(account_name, {'send_stanza': None})
|
||||
app.logger = MockLogger()
|
||||
app.default_session_type = ChatControlSession
|
||||
|
||||
def setUp(self):
|
||||
app.notification = notify.Notification()
|
||||
|
||||
# no notifications have been sent
|
||||
self.assertEqual(0, len(notify.notifications))
|
||||
|
||||
def tearDown(self):
|
||||
app.notification.clean()
|
||||
|
||||
def receive_chat_msg(self, jid, msgtxt):
|
||||
'''simulate receiving a chat message from jid'''
|
||||
msg = nbxmpp.Message()
|
||||
msg.setBody(msgtxt)
|
||||
msg.setType('chat')
|
||||
|
||||
xml = """<message from='%s' id='1' type='chat'><body>%s</body>
|
||||
<thread>123</thread></message>""" % (jid, msgtxt)
|
||||
stanza = nbxmpp.protocol.Message(node=nbxmpp.simplexml.XML2Node(xml))
|
||||
self.conn._messageCB(None, stanza)
|
||||
|
||||
# ----- custom assertions -----
|
||||
def assert_new_message_notification(self):
|
||||
'''a new_message notification has been sent'''
|
||||
self.assertEqual(1, len(notify.notifications))
|
||||
notif = notify.notifications[-1]
|
||||
self.assertEqual('New Message', notif.popup_event_type)
|
||||
|
||||
def assert_first_message_notification(self):
|
||||
'''this message was treated as a first message'''
|
||||
self.assert_new_message_notification()
|
||||
notif = notify.notifications[-1]
|
||||
first = notif.first_unread
|
||||
self.assertTrue(first,
|
||||
'message should have been treated as a first message')
|
||||
|
||||
def assert_not_first_message_notification(self):
|
||||
'''this message was not treated as a first message'''
|
||||
self.assert_new_message_notification()
|
||||
notif = notify.notifications[-1]
|
||||
first = notif.first_unread
|
||||
self.assertTrue(not first,
|
||||
'message was unexpectedly treated as a first message')
|
||||
|
||||
# ----- tests -----
|
||||
def test_receive_1nocontrol(self):
|
||||
'''test receiving a message in a blank state'''
|
||||
jid = 'bct@necronomicorp.com'
|
||||
fjid = 'bct@necronomicorp.com/Gajim'
|
||||
msgtxt = 'testing one'
|
||||
|
||||
self.receive_chat_msg(fjid, msgtxt)
|
||||
|
||||
# session is created
|
||||
self.assertTrue((jid in self.conn.sessions) and (
|
||||
'123' in self.conn.sessions[jid]), 'session is not created')
|
||||
sess = self.conn.sessions[jid]['123']
|
||||
|
||||
# message was logged
|
||||
calls = app.storage.archive.mockGetNamedCalls('insert_into_logs')
|
||||
self.assertEqual(1, len(calls))
|
||||
|
||||
# no ChatControl was open and autopopup was off
|
||||
# so the message goes into the event queue
|
||||
self.assertEqual(1, len(app.events.get_events(account_name)))
|
||||
|
||||
self.assert_first_message_notification()
|
||||
|
||||
# no control is attached to the session
|
||||
self.assertEqual(None, sess.control)
|
||||
|
||||
def test_receive_2already_has_control(self):
|
||||
'''test receiving a message with a session already attached to a
|
||||
control'''
|
||||
jid = 'bct@necronomicorp.com'
|
||||
fjid = 'bct@necronomicorp.com/Gajim'
|
||||
msgtxt = 'testing two'
|
||||
app.interface.roster = RosterWindow(app.app)
|
||||
|
||||
sess = self.conn.sessions[jid]['123']
|
||||
sess.control = MockChatControl(fjid, account_name)
|
||||
|
||||
self.receive_chat_msg(fjid, msgtxt)
|
||||
|
||||
# message was logged
|
||||
calls = app.storage.archive.mockGetNamedCalls('insert_into_logs')
|
||||
self.assertEqual(2, len(calls))
|
||||
|
||||
# the message does not go into the event queue
|
||||
self.assertEqual(1, len(app.events.get_events(account_name)))
|
||||
|
||||
self.assert_not_first_message_notification()
|
||||
|
||||
# message was printed to the control
|
||||
calls = sess.control.mockGetNamedCalls('print_conversation')
|
||||
self.assertEqual(1, len(calls))
|
||||
app.interface.roster.window.destroy()
|
||||
|
||||
#def test_received_3orphaned_control(self):
|
||||
#'''test receiving a message when a control that doesn't have a session
|
||||
#attached exists'''
|
||||
|
||||
#jid = 'bct@necronomicorp.com'
|
||||
#fjid = jid + '/Gajim'
|
||||
#msgtxt = 'testing three'
|
||||
|
||||
#ctrl = MockChatControl(jid, account_name)
|
||||
#gajim.interface.msg_win_mgr = Mock({'get_control': ctrl})
|
||||
#gajim.interface.msg_win_mgr.mockSetExpectation('get_control',
|
||||
#expectParams(jid, account_name))
|
||||
|
||||
#self.receive_chat_msg(fjid, msgtxt)
|
||||
|
||||
## message was logged
|
||||
#calls = gajim.logger.mockGetNamedCalls('insert_into_logs')
|
||||
#self.assertEqual(1, len(calls))
|
||||
|
||||
## the message does not go into the event queue
|
||||
#self.assertEqual(0, len(gajim.events.get_events(account_name)))
|
||||
|
||||
#self.assert_not_first_message_notification()
|
||||
|
||||
## this session is now attached to that control
|
||||
#self.assertEqual(self.sess, ctrl.session)
|
||||
#self.assertEqual(ctrl, self.sess.control, 'foo')
|
||||
|
||||
## message was printed to the control
|
||||
#calls = ctrl.mockGetNamedCalls('print_conversation')
|
||||
#self.assertEqual(1, len(calls))
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
172
test/broken/unit/test_socks5.py
Normal file
172
test/broken/unit/test_socks5.py
Normal file
|
@ -0,0 +1,172 @@
|
|||
'''
|
||||
Tests for dispatcher.py
|
||||
'''
|
||||
import unittest
|
||||
|
||||
import lib
|
||||
lib.setup_env()
|
||||
|
||||
from mock import Mock
|
||||
import sys
|
||||
import socket
|
||||
|
||||
from gajim.common.socks5 import *
|
||||
from gajim.common import jingle_xtls
|
||||
|
||||
class fake_sock(Mock):
|
||||
def __init__(self, sockobj):
|
||||
Mock.__init__(self)
|
||||
|
||||
self.sockobj = sockobj
|
||||
|
||||
|
||||
def setup_stream(self):
|
||||
sha1 = self.sockobj._get_sha1_auth()
|
||||
|
||||
self.incoming = []
|
||||
self.incoming.append(self.sockobj._get_auth_response())
|
||||
self.incoming.append(self.sockobj._get_request_buff(sha1, 0x00))
|
||||
self.outgoing = []
|
||||
self.outgoing.append(self.sockobj._get_auth_buff())
|
||||
self.outgoing.append(self.sockobj._get_request_buff(sha1))
|
||||
|
||||
def switch_stream(self):
|
||||
# Roles are reversed, client will be expecting server stream
|
||||
# and server will be expecting client stream
|
||||
|
||||
temp = self.incoming
|
||||
self.incoming = self.outgoing
|
||||
self.outgoing = temp
|
||||
|
||||
def _recv(self, foo):
|
||||
return self.incoming.pop(0)
|
||||
|
||||
def _send(self, data):
|
||||
# This method is surrounded by a try block,
|
||||
# we can't use assert here
|
||||
|
||||
if data != self.outgoing[0]:
|
||||
print('FAILED SENDING TEST')
|
||||
self.outgoing.pop(0)
|
||||
|
||||
class fake_idlequeue(Mock):
|
||||
|
||||
def __init__(self):
|
||||
Mock.__init__(self)
|
||||
|
||||
def plug_idle(self, obj, writable=True, readable=True):
|
||||
|
||||
if readable:
|
||||
obj.pollin()
|
||||
if writable:
|
||||
obj.pollout()
|
||||
|
||||
class TestSocks5(unittest.TestCase):
|
||||
'''
|
||||
Test class for Socks5
|
||||
'''
|
||||
def setUp(self):
|
||||
streamhost = { 'host': None,
|
||||
'port': 1,
|
||||
'initiator' : None,
|
||||
'target' : None}
|
||||
queue = Mock()
|
||||
queue.file_props = {}
|
||||
#self.sockobj = Socks5Receiver(fake_idlequeue(), streamhost, None)
|
||||
self.sockobj = Socks5Sender(fake_idlequeue(), None, 'server', Mock() ,
|
||||
None, None, True, file_props={})
|
||||
sock = fake_sock(self.sockobj)
|
||||
self.sockobj._sock = sock
|
||||
self.sockobj._recv = sock._recv
|
||||
self.sockobj._send = sock._send
|
||||
self.sockobj.state = 1
|
||||
self.sockobj.connected = True
|
||||
self.sockobj.pollend = self._pollend
|
||||
|
||||
# Something that the receiver needs
|
||||
#self.sockobj.file_props['type'] = 'r'
|
||||
|
||||
# Something that the sender needs
|
||||
self.sockobj.file_props = {}
|
||||
self.sockobj.file_props['type'] = 'r'
|
||||
self.sockobj.file_props['paused'] = ''
|
||||
self.sockobj.queue = Mock()
|
||||
self.sockobj.queue.process_result = self._pollend
|
||||
|
||||
def _pollend(self, foo = None, duu = None):
|
||||
# This is a disconnect function
|
||||
sys.exit("end of the road")
|
||||
|
||||
def _check_inout(self):
|
||||
# Check if there isn't anything else to receive or send
|
||||
sock = self.sockobj._sock
|
||||
assert(sock.incoming == [])
|
||||
assert(sock.outgoing == [])
|
||||
|
||||
def test_connection_server(self):
|
||||
return
|
||||
mocksock = self.sockobj._sock
|
||||
mocksock.setup_stream()
|
||||
#self.sockobj._sock.switch_stream()
|
||||
s = socket.socket(2, 1, 6)
|
||||
server = ('127.0.0.1', 28000)
|
||||
|
||||
s.connect(server)
|
||||
|
||||
s.send(mocksock.outgoing.pop(0))
|
||||
self.assertEqual(s.recv(64), mocksock.incoming.pop(0))
|
||||
|
||||
s.send(mocksock.outgoing.pop(0))
|
||||
self.assertEqual(s.recv(64), mocksock.incoming.pop(0))
|
||||
|
||||
def test_connection_client(self):
|
||||
|
||||
|
||||
mocksock = self.sockobj._sock
|
||||
mocksock.setup_stream()
|
||||
mocksock.switch_stream()
|
||||
s = socket.socket(10, 1, 6)
|
||||
|
||||
|
||||
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
s.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
|
||||
s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
|
||||
|
||||
netadd = ('::', 28000, 0, 0)
|
||||
s.bind(netadd)
|
||||
s.listen(socket.SOMAXCONN)
|
||||
(s, address) = s.accept()
|
||||
|
||||
|
||||
self.assertEqual(s.recv(64), mocksock.incoming.pop(0))
|
||||
s.send(mocksock.outgoing.pop(0))
|
||||
|
||||
buff = s.recv(64)
|
||||
inco = mocksock.incoming.pop(0)
|
||||
#self.assertEqual(s.recv(64), mocksock.incoming.pop(0))
|
||||
s.send(mocksock.outgoing.pop(0))
|
||||
|
||||
def test_client_negoc(self):
|
||||
return
|
||||
self.sockobj._sock.setup_stream()
|
||||
try:
|
||||
self.sockobj.pollout()
|
||||
except SystemExit:
|
||||
pass
|
||||
|
||||
self._check_inout()
|
||||
|
||||
def test_server_negoc(self):
|
||||
return
|
||||
self.sockobj._sock.setup_stream()
|
||||
self.sockobj._sock.switch_stream()
|
||||
try:
|
||||
self.sockobj.idlequeue.plug_idle(self.sockobj, False, True)
|
||||
except SystemExit:
|
||||
pass
|
||||
self._check_inout()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
unittest.main()
|
Loading…
Add table
Add a link
Reference in a new issue