Commit dfe42d58 authored by Łukasz Nowak's avatar Łukasz Nowak

- fix raises hooks, they were raising something else

 - check login with clearing cache, as ERP5 remote user manager caches a
   lot
 - add checks for more raises


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@39164 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent b2bfde09
...@@ -73,15 +73,21 @@ ERP5Site.ERP5Site_getExpressInstanceUid =\ ...@@ -73,15 +73,21 @@ ERP5Site.ERP5Site_getExpressInstanceUid =\
ERP5Site.security.declarePublic('ERP5Site_getExpressInstanceUid') ERP5Site.security.declarePublic('ERP5Site_getExpressInstanceUid')
# portal_wizard patches # portal_wizard patches
def raises_socket_error(self, **kw): def raises_socket_error(self, *args, **kw):
raise socket.error raise socket.error
def raises_socket_sslerror(self, **kw): def raises_socket_sslerror(self, *args, **kw):
raise socket.sslerror raise socket.sslerror
def raises_valueerror(self, **kw): def raises_valueerror(self, *args, **kw):
raise ValueError raise ValueError
def raises_socket_timeout(self, *args, **kw):
raise socket.timeout
def raises_socket_gaierror(self, *args, **kw):
raise socket.gaierror
class TestERP5RemoteUserManager(ERP5TypeTestCase): class TestERP5RemoteUserManager(ERP5TypeTestCase):
"""Low level tests of remote logging""" """Low level tests of remote logging"""
def getBusinessTemplateList(self): def getBusinessTemplateList(self):
...@@ -168,6 +174,12 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase): ...@@ -168,6 +174,12 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase):
portal_type=self.person_portal_type, portal_type=self.person_portal_type,
reference=reference, title=password) reference=reference, title=password)
def checkLogin(self, expected, sent):
"""Helper to check login, clear cache later and commit transaction"""
self.assertEqual(expected,
self.erp5_remote_manager.authenticateCredentials(sent))
self.portal.portal_caches.clearAllCache()
############################################################################ ############################################################################
# TESTS # TESTS
############################################################################ ############################################################################
...@@ -178,8 +190,7 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase): ...@@ -178,8 +190,7 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase):
transaction.commit() transaction.commit()
self.tic() self.tic()
kw = {'login':login, 'password': password} kw = {'login':login, 'password': password}
self.assertEqual(('someone', 'someone'), self.checkLogin(('someone', 'someone'), kw)
self.erp5_remote_manager.authenticateCredentials(kw))
def test_incorrect_login(self): def test_incorrect_login(self):
login = 'someone' login = 'someone'
...@@ -188,8 +199,7 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase): ...@@ -188,8 +199,7 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase):
transaction.commit() transaction.commit()
self.tic() self.tic()
kw = {'login':login, 'password': 'another_password'} kw = {'login':login, 'password': 'another_password'}
self.assertEqual(None, self.checkLogin(None, kw)
self.erp5_remote_manager.authenticateCredentials(kw))
def test_incorrect_login_in_case_of_no_connection(self): def test_incorrect_login_in_case_of_no_connection(self):
login = 'someone' login = 'someone'
...@@ -201,8 +211,7 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase): ...@@ -201,8 +211,7 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase):
self.removeAuthenticationServerPreferences() self.removeAuthenticationServerPreferences()
transaction.commit() transaction.commit()
self.tic() self.tic()
self.assertEqual(None, self.checkLogin(None, kw)
self.erp5_remote_manager.authenticateCredentials(kw))
def test_loggable_in_case_of_server_socket_error(self): def test_loggable_in_case_of_server_socket_error(self):
login = 'someone' login = 'someone'
...@@ -211,10 +220,7 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase): ...@@ -211,10 +220,7 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase):
transaction.commit() transaction.commit()
self.tic() self.tic()
kw = {'login':login, 'password': password} kw = {'login':login, 'password': password}
self.assertEqual(('someone', 'someone'), self.checkLogin(('someone', 'someone'), kw)
self.erp5_remote_manager.authenticateCredentials(kw))
transaction.commit()
self.tic()
# patch Wizard Tool to raise in callRemoteProxyMethod # patch Wizard Tool to raise in callRemoteProxyMethod
from Products.ERP5Wizard.Tool.WizardTool import WizardTool from Products.ERP5Wizard.Tool.WizardTool import WizardTool
original_callRemoteProxyMethod=WizardTool.callRemoteProxyMethod original_callRemoteProxyMethod=WizardTool.callRemoteProxyMethod
...@@ -222,8 +228,7 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase): ...@@ -222,8 +228,7 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase):
WizardTool.callRemoteProxyMethod = raises_socket_error WizardTool.callRemoteProxyMethod = raises_socket_error
self.assertRaises(socket.error, self.assertRaises(socket.error,
self.portal.portal_wizard.callRemoteProxyMethod) self.portal.portal_wizard.callRemoteProxyMethod)
self.assertEqual(('someone', 'someone'), self.checkLogin(('someone', 'someone'), kw)
self.erp5_remote_manager.authenticateCredentials(kw))
finally: finally:
WizardTool.callRemoteProxyMethod = original_callRemoteProxyMethod WizardTool.callRemoteProxyMethod = original_callRemoteProxyMethod
...@@ -234,10 +239,7 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase): ...@@ -234,10 +239,7 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase):
transaction.commit() transaction.commit()
self.tic() self.tic()
kw = {'login':login, 'password': password} kw = {'login':login, 'password': password}
self.assertEqual(('someone', 'someone'), self.checkLogin(('someone', 'someone'), kw)
self.erp5_remote_manager.authenticateCredentials(kw))
transaction.commit()
self.tic()
# patch Wizard Tool to raise in callRemoteProxyMethod # patch Wizard Tool to raise in callRemoteProxyMethod
from Products.ERP5Wizard.Tool.WizardTool import WizardTool from Products.ERP5Wizard.Tool.WizardTool import WizardTool
original_callRemoteProxyMethod=WizardTool.callRemoteProxyMethod original_callRemoteProxyMethod=WizardTool.callRemoteProxyMethod
...@@ -245,8 +247,7 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase): ...@@ -245,8 +247,7 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase):
WizardTool.callRemoteProxyMethod = raises_socket_sslerror WizardTool.callRemoteProxyMethod = raises_socket_sslerror
self.assertRaises(socket.sslerror, self.assertRaises(socket.sslerror,
self.portal.portal_wizard.callRemoteProxyMethod) self.portal.portal_wizard.callRemoteProxyMethod)
self.assertEqual(('someone', 'someone'), self.checkLogin(('someone', 'someone'), kw)
self.erp5_remote_manager.authenticateCredentials(kw))
finally: finally:
WizardTool.callRemoteProxyMethod = original_callRemoteProxyMethod WizardTool.callRemoteProxyMethod = original_callRemoteProxyMethod
...@@ -257,10 +258,7 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase): ...@@ -257,10 +258,7 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase):
transaction.commit() transaction.commit()
self.tic() self.tic()
kw = {'login':login, 'password': password} kw = {'login':login, 'password': password}
self.assertEqual(('someone', 'someone'), self.checkLogin(('someone', 'someone'), kw)
self.erp5_remote_manager.authenticateCredentials(kw))
transaction.commit()
self.tic()
# patch Wizard Tool to raise in callRemoteProxyMethod # patch Wizard Tool to raise in callRemoteProxyMethod
from Products.ERP5Wizard.Tool.WizardTool import WizardTool from Products.ERP5Wizard.Tool.WizardTool import WizardTool
original_callRemoteProxyMethod=WizardTool.callRemoteProxyMethod original_callRemoteProxyMethod=WizardTool.callRemoteProxyMethod
...@@ -268,8 +266,7 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase): ...@@ -268,8 +266,7 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase):
WizardTool.callRemoteProxyMethod = raises_valueerror WizardTool.callRemoteProxyMethod = raises_valueerror
self.assertRaises(ValueError, self.assertRaises(ValueError,
self.portal.portal_wizard.callRemoteProxyMethod) self.portal.portal_wizard.callRemoteProxyMethod)
self.assertEqual(('someone', 'someone'), self.checkLogin(None, kw)
self.erp5_remote_manager.authenticateCredentials(kw))
finally: finally:
WizardTool.callRemoteProxyMethod = original_callRemoteProxyMethod WizardTool.callRemoteProxyMethod = original_callRemoteProxyMethod
...@@ -281,10 +278,7 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase): ...@@ -281,10 +278,7 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase):
transaction.commit() transaction.commit()
self.tic() self.tic()
kw = {'login':login, 'password': password} kw = {'login':login, 'password': password}
self.assertEqual(('someone', 'someone'), self.checkLogin(('someone', 'someone'), kw)
self.erp5_remote_manager.authenticateCredentials(kw))
transaction.commit()
self.tic()
# patch Wizard Tool to raise in callRemoteProxyMethod # patch Wizard Tool to raise in callRemoteProxyMethod
from Products.ERP5Wizard.Tool.WizardTool import WizardTool from Products.ERP5Wizard.Tool.WizardTool import WizardTool
original_callRemoteProxyMethod=WizardTool.callRemoteProxyMethod original_callRemoteProxyMethod=WizardTool.callRemoteProxyMethod
...@@ -292,13 +286,47 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase): ...@@ -292,13 +286,47 @@ class TestERP5RemoteUserManager(ERP5TypeTestCase):
WizardTool.callRemoteProxyMethod = raises_socket_error WizardTool.callRemoteProxyMethod = raises_socket_error
self.assertRaises(socket.error, self.assertRaises(socket.error,
self.portal.portal_wizard.callRemoteProxyMethod) self.portal.portal_wizard.callRemoteProxyMethod)
self.assertEqual(('someone', 'someone'), self.checkLogin(('someone', 'someone'), kw)
self.erp5_remote_manager.authenticateCredentials(kw)) self.checkLogin(None, {'login':kw['login'], 'password':'wrong_password'})
self.assertEqual(None, self.checkLogin(('someone', 'someone'), kw)
self.erp5_remote_manager.authenticateCredentials( finally:
{'login':kw['login'], 'password':'wrong_password'})) WizardTool.callRemoteProxyMethod = original_callRemoteProxyMethod
self.assertEqual(('someone', 'someone'),
self.erp5_remote_manager.authenticateCredentials(kw)) def test_loggable_in_case_of_server_socket_timeout(self):
login = 'someone'
password = 'somepass'
self.createPerson(login, password)
transaction.commit()
self.tic()
kw = {'login':login, 'password': password}
self.checkLogin(('someone', 'someone'), kw)
# patch Wizard Tool to raise in callRemoteProxyMethod
from Products.ERP5Wizard.Tool.WizardTool import WizardTool
original_callRemoteProxyMethod=WizardTool.callRemoteProxyMethod
try:
WizardTool.callRemoteProxyMethod = raises_socket_timeout
self.assertRaises(socket.timeout,
self.portal.portal_wizard.callRemoteProxyMethod)
self.checkLogin(('someone', 'someone'), kw)
finally:
WizardTool.callRemoteProxyMethod = original_callRemoteProxyMethod
def test_loggable_in_case_of_server_gaierror(self):
login = 'someone'
password = 'somepass'
self.createPerson(login, password)
transaction.commit()
self.tic()
kw = {'login':login, 'password': password}
self.checkLogin(('someone', 'someone'), kw)
# patch Wizard Tool to raise in callRemoteProxyMethod
from Products.ERP5Wizard.Tool.WizardTool import WizardTool
original_callRemoteProxyMethod=WizardTool.callRemoteProxyMethod
try:
WizardTool.callRemoteProxyMethod = raises_socket_gaierror
self.assertRaises(socket.gaierror,
self.portal.portal_wizard.callRemoteProxyMethod)
self.checkLogin(('someone', 'someone'), kw)
finally: finally:
WizardTool.callRemoteProxyMethod = original_callRemoteProxyMethod WizardTool.callRemoteProxyMethod = original_callRemoteProxyMethod
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment