35
35
from ubuntu_sso import DBUS_CREDENTIALS_IFACE
36
36
from ubuntu_sso.keyring import U1_APP_NAME
37
from ubuntu_sso.main import (U1_PING_URL, blocking, except_to_errdict,
37
from ubuntu_sso.main import (U1_PING_URL, TIMEOUT_INTERVAL,
38
blocking, except_to_errdict,
38
39
CredentialsManagement, SSOCredentials, SSOLogin)
39
40
from ubuntu_sso.main import (HELP_TEXT_KEY, PING_URL_KEY,
40
41
TC_URL_KEY, UI_CLASS_KEY, UI_MODULE_KEY, WINDOW_ID_KEY,
41
42
SUCCESS_CB_KEY, ERROR_CB_KEY, DENIAL_CB_KEY)
42
43
from ubuntu_sso.tests import (APP_NAME, TC_URL, HELP_TEXT, CAPTCHA_ID,
43
44
CAPTCHA_SOLUTION, EMAIL, EMAIL_TOKEN, PASSWORD, PING_URL, TOKEN,
44
TOKEN_NAME, WINDOW_ID)
45
TOKEN_NAME, WINDOW_ID, TestCase)
47
48
# Access to a protected member 'yyy' of a client class
740
749
self.assertIsInstance(self.client, ubuntu_sso.main.dbus.service.Object)
752
class CredentialsManagementRefCountingTestCase(CredentialsManagementTestCase):
753
"""Tests for the CredentialsManagement ref counting."""
755
def test_ref_counting(self):
756
"""Ref counting is in place."""
757
self.assertEqual(self.client.ref_count, 0)
759
def test_find_credentials(self):
760
"""Keep proper track of on going requests."""
761
self.client.find_credentials(APP_NAME, self.args)
763
self.assertEqual(self.client.ref_count, 1)
765
def test_clear_credentials(self):
766
"""Keep proper track of on going requests."""
767
self.client.clear_credentials(APP_NAME, self.args)
769
self.assertEqual(self.client.ref_count, 1)
771
def test_store_credentials(self):
772
"""Keep proper track of on going requests."""
773
self.client.store_credentials(APP_NAME, self.args)
775
self.assertEqual(self.client.ref_count, 1)
777
def test_register(self):
778
"""Keep proper track of on going requests."""
779
self.client.register(APP_NAME, self.args)
781
self.assertEqual(self.client.ref_count, 1)
783
def test_login(self):
784
"""Keep proper track of on going requests."""
785
self.client.login(APP_NAME, self.args)
787
self.assertEqual(self.client.ref_count, 1)
789
def test_several_requests(self):
790
"""Requests can be nested."""
791
self.client.login(APP_NAME, self.args)
792
self.client.clear_credentials(APP_NAME, self.args)
793
self.client.find_credentials(APP_NAME, self.args)
794
self.client.register(APP_NAME, self.args)
795
self.client.store_credentials(APP_NAME, self.args)
797
self.assertEqual(self.client.ref_count, 5)
799
def test_credentials_found(self):
800
"""Ref counter is decreased when a signal is sent."""
801
self.client.ref_count = 3
802
self.client.CredentialsFound(APP_NAME, TOKEN)
804
self.assertEqual(self.client.ref_count, 2)
806
def test_credentials_not_found(self):
807
"""Ref counter is decreased when a signal is sent."""
808
self.client.ref_count = 3
809
self.client.CredentialsNotFound(APP_NAME)
811
self.assertEqual(self.client.ref_count, 2)
813
def test_credentials_cleared(self):
814
"""Ref counter is decreased when a signal is sent."""
815
self.client.ref_count = 3
816
self.client.CredentialsCleared(APP_NAME)
818
self.assertEqual(self.client.ref_count, 2)
820
def test_credentials_stored(self):
821
"""Ref counter is decreased when a signal is sent."""
822
self.client.ref_count = 3
823
self.client.CredentialsStored(APP_NAME)
825
self.assertEqual(self.client.ref_count, 2)
827
def test_credentials_error(self):
828
"""Ref counter is decreased when a signal is sent."""
829
self.client.ref_count = 3
830
self.client.CredentialsError(APP_NAME, {'error_type': 'test'})
832
self.assertEqual(self.client.ref_count, 2)
834
def test_authorization_denied(self):
835
"""Ref counter is decreased when a signal is sent."""
836
self.client.ref_count = 3
837
self.client.AuthorizationDenied(APP_NAME)
839
self.assertEqual(self.client.ref_count, 2)
841
def test_credentials_found_when_ref_count_is_not_positive(self):
842
"""Ref counter is decreased when a signal is sent."""
843
self.client._ref_count = -3
844
self.client.CredentialsFound(APP_NAME, TOKEN)
846
self.assertEqual(self.client.ref_count, 0)
847
msg = 'Attempting to decrease ref_count to a negative value (-4).'
848
self.assertTrue(self.memento.check_warning(msg))
850
def test_credentials_not_found_when_ref_count_is_not_positive(self):
851
"""Ref counter is decreased when a signal is sent."""
852
self.client._ref_count = -3
853
self.client.CredentialsNotFound(APP_NAME)
855
self.assertEqual(self.client.ref_count, 0)
856
msg = 'Attempting to decrease ref_count to a negative value (-4).'
857
self.assertTrue(self.memento.check_warning(msg))
859
def test_credentials_cleared_when_ref_count_is_not_positive(self):
860
"""Ref counter is decreased when a signal is sent."""
861
self.client._ref_count = -3
862
self.client.CredentialsCleared(APP_NAME)
864
self.assertEqual(self.client.ref_count, 0)
865
msg = 'Attempting to decrease ref_count to a negative value (-4).'
866
self.assertTrue(self.memento.check_warning(msg))
868
def test_credentials_stored_when_ref_count_is_not_positive(self):
869
"""Ref counter is decreased when a signal is sent."""
870
self.client._ref_count = -3
871
self.client.CredentialsStored(APP_NAME)
873
self.assertEqual(self.client.ref_count, 0)
874
msg = 'Attempting to decrease ref_count to a negative value (-4).'
875
self.assertTrue(self.memento.check_warning(msg))
877
def test_credentials_error_when_ref_count_is_not_positive(self):
878
"""Ref counter is decreased when a signal is sent."""
879
self.client._ref_count = -3
880
self.client.CredentialsError(APP_NAME, {'error_type': 'test'})
882
self.assertEqual(self.client.ref_count, 0)
883
msg = 'Attempting to decrease ref_count to a negative value (-4).'
884
self.assertTrue(self.memento.check_warning(msg))
886
def test_autorization_denied_when_ref_count_is_not_positive(self):
887
"""Ref counter is decreased when a signal is sent."""
888
self.client._ref_count = -3
889
self.client.AuthorizationDenied(APP_NAME)
891
self.assertEqual(self.client.ref_count, 0)
892
msg = 'Attempting to decrease ref_count to a negative value (-4).'
893
self.assertTrue(self.memento.check_warning(msg))
895
def test_on_zero_ref_count_shutdown(self):
896
"""When ref count reaches 0, queue shutdown op."""
897
self.client.timeout_func = self._set_called
898
self.client.find_credentials(APP_NAME, self.args)
899
self.client.CredentialsFound(APP_NAME, TOKEN)
901
self.assertEqual(self._called,
902
((TIMEOUT_INTERVAL, self.client.shutdown_func), {}))
904
def test_on_non_zero_ref_count_do_not_shutdown(self):
905
"""If ref count is not 0, do not queue shutdown op."""
906
self.client.timeout_func = self._set_called
907
self.client.find_credentials(APP_NAME, self.args)
909
self.assertEqual(self._called, False)
743
912
class CredentialsManagementFindTestCase(CredentialsManagementTestCase):
744
913
"""Tests for the CredentialsManagement find method."""