diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/leap/eip/checks.py | 34 | ||||
-rw-r--r-- | src/leap/eip/eipconnection.py | 11 | ||||
-rw-r--r-- | src/leap/eip/tests/test_checks.py | 14 | ||||
-rw-r--r-- | src/leap/eip/tests/test_eipconnection.py | 30 |
4 files changed, 55 insertions, 34 deletions
diff --git a/src/leap/eip/checks.py b/src/leap/eip/checks.py index 794e69e1..27320b1f 100644 --- a/src/leap/eip/checks.py +++ b/src/leap/eip/checks.py @@ -15,21 +15,40 @@ from leap.eip import constants as eipconstants from leap.eip import exceptions as eipexceptions from leap.util.fileutil import mkdir_p +""" +EIPConfigChecker +---------- +this is the first of 3 consecutive checks that we're implementing. -class EIPChecker(object): +It is used from the eip conductor (a instance of EIPConnection that is +managed from the QtApp), running run_all method before trying to call +`connect` or any other of the state switching methods. + +It checks that the needed files are provided or can be discovered over the +net. Much of these tests are not specific to EIP module, and can be splitted +into base.tests to be invoked by the base leap init routines. +However, I'm testing them alltogether for the sake of having the whole unit +reachable and testable as a whole. + +Other related checkers - not implemented yet -: +* LeapNetworkChecker +* ProviderCertChecker +""" + + +class EIPConfigChecker(object): """ Several tests needed to ensure a EIPConnection - can be sucessful + can be sucessfully established. use run_all to run all checks. """ def __init__(self, fetcher=requests): - """ - we do not want to accept too many - argument on init. we want tests - to be explicitely run. - """ + # we do not want to accept too many + # argument on init. + # we want tests + # to be explicitely run. self.config = None self.fetcher = fetcher @@ -100,7 +119,6 @@ class EIPChecker(object): def fetch_definition(self, skip_download=False, config=None, uri=None): - # check_and_get_definition_file """ fetches a definition file from server """ diff --git a/src/leap/eip/eipconnection.py b/src/leap/eip/eipconnection.py index aea560c9..386b71be 100644 --- a/src/leap/eip/eipconnection.py +++ b/src/leap/eip/eipconnection.py @@ -8,7 +8,7 @@ logging.basicConfig() logger = logging.getLogger(name=__name__) logger.setLevel(logging.DEBUG) -from leap.eip.checks import EIPChecker +from leap.eip.checks import EIPConfigChecker from leap.eip import exceptions as eip_exceptions from leap.eip.openvpnconnection import OpenVPNConnection @@ -18,18 +18,19 @@ class EIPConnection(OpenVPNConnection): Manages the execution of the OpenVPN process, auto starts, monitors the network connection, handles configuration, fixes leaky hosts, handles errors, etc. - Preferences will be stored via the Storage API. (TBD) Status updates (connected, bandwidth, etc) are signaled to the GUI. """ - def __init__(self, checker=EIPChecker, *args, **kwargs): + def __init__(self, config_checker=EIPConfigChecker, *args, **kwargs): self.settingsfile = kwargs.get('settingsfile', None) self.logfile = kwargs.get('logfile', None) + + # not used atm. but should. self.error_queue = [] status_signals = kwargs.pop('status_signals', None) self.status = EIPConnectionStatus(callbacks=status_signals) - self.checker = checker() + self.config_checker = config_checker() super(EIPConnection, self).__init__(*args, **kwargs) @@ -37,7 +38,7 @@ class EIPConnection(OpenVPNConnection): """ run all eip checks previous to attempting a connection """ - self.checker.run_all(skip_download=skip_download) + self.config_checker.run_all(skip_download=skip_download) def connect(self): """ diff --git a/src/leap/eip/tests/test_checks.py b/src/leap/eip/tests/test_checks.py index 83561833..1c79ce0c 100644 --- a/src/leap/eip/tests/test_checks.py +++ b/src/leap/eip/tests/test_checks.py @@ -32,7 +32,7 @@ class EIPCheckTest(BaseLeapTest): # test methods are there, and can be called from run_all def test_checker_should_implement_check_methods(self): - checker = eipchecks.EIPChecker() + checker = eipchecks.EIPConfigChecker() self.assertTrue(hasattr(checker, "check_default_eipconfig"), "missing meth") @@ -45,7 +45,7 @@ class EIPCheckTest(BaseLeapTest): self.assertTrue(hasattr(checker, "ping_gateway"), "missing meth") def test_checker_should_actually_call_all_tests(self): - checker = eipchecks.EIPChecker() + checker = eipchecks.EIPConfigChecker() mc = Mock() checker.run_all(checker=mc) @@ -64,7 +64,7 @@ class EIPCheckTest(BaseLeapTest): # test individual check methods def test_check_default_eipconfig(self): - checker = eipchecks.EIPChecker() + checker = eipchecks.EIPConfigChecker() # no eip config (empty home) eipconfig = baseconfig.get_config_file(eipconstants.EIP_CONFIG) self.assertFalse(os.path.isfile(eipconfig)) @@ -79,7 +79,7 @@ class EIPCheckTest(BaseLeapTest): # run validation methods. def test_check_is_there_default_provider(self): - checker = eipchecks.EIPChecker() + checker = eipchecks.EIPConfigChecker() # we do dump a sample eip config, but lacking a # default provider entry. # This error will be possible catched in a different @@ -104,7 +104,7 @@ class EIPCheckTest(BaseLeapTest): with patch.object(requests, "get") as mocked_get: mocked_get.return_value.status_code = 200 mocked_get.return_value.json = DEFAULT_PROVIDER_DEFINITION - checker = eipchecks.EIPChecker(fetcher=requests) + checker = eipchecks.EIPConfigChecker(fetcher=requests) sampleconfig = eipconstants.EIP_SAMPLE_JSON checker.fetch_definition(config=sampleconfig) @@ -122,12 +122,12 @@ class EIPCheckTest(BaseLeapTest): with patch.object(requests, "get") as mocked_get: mocked_get.return_value.status_code = 200 mocked_get.return_value.json = eipconstants.EIP_SAMPLE_SERVICE - checker = eipchecks.EIPChecker(fetcher=requests) + checker = eipchecks.EIPConfigChecker(fetcher=requests) sampleconfig = eipconstants.EIP_SAMPLE_JSON checker.fetch_definition(config=sampleconfig) def test_check_complete_eip_config(self): - checker = eipchecks.EIPChecker() + checker = eipchecks.EIPConfigChecker() with self.assertRaises(eipexceptions.EIPConfigurationError): sampleconfig = copy.copy(eipconstants.EIP_SAMPLE_JSON) sampleconfig['provider'] = None diff --git a/src/leap/eip/tests/test_eipconnection.py b/src/leap/eip/tests/test_eipconnection.py index 7d8acad6..26f6529e 100644 --- a/src/leap/eip/tests/test_eipconnection.py +++ b/src/leap/eip/tests/test_eipconnection.py @@ -50,8 +50,12 @@ class EIPConductorTest(BaseLeapTest): # for instance: # We have to TOUCH a keys file because # we're triggerig the key checks FROM - # the constructo. me not like that, + # the constructor. me not like that, # key checker should better be called explicitelly. + + # XXX change to keys_checker invocation + # (see config_checker) + filepath = os.path.expanduser( '~/.config/leap/providers/%s/openvpn.keys' % constants.DEFAULT_TEST_PROVIDER) @@ -60,12 +64,8 @@ class EIPConductorTest(BaseLeapTest): # we init the manager with only # some methods mocked - - self.manager = Mock( - name="openvpnmanager_mock") - + self.manager = Mock(name="openvpnmanager_mock") self.con = MockedEIPConnection() - #manager=self.manager) def tearDown(self): del self.con @@ -74,14 +74,6 @@ class EIPConductorTest(BaseLeapTest): # tests # - @unittest.skip - #ain't manager anymore! - def test_manager_was_initialized(self): - """ - manager init ok during conductor init? - """ - self.manager.assert_called_once_with() - def test_vpnconnection_defaults(self): """ default attrs as expected @@ -109,6 +101,16 @@ class EIPConductorTest(BaseLeapTest): self.assertEqual(self.con.args, [1, 2, 3]) + # config checks + + def test_config_checked_called(self): + del(self.con) + config_checker = Mock() + self.con = MockedEIPConnection(config_checker=config_checker) + self.assertTrue(config_checker.called) + self.con.run_checks() + self.con.config_checker.run_all.assert_called_with(skip_download=False) + # connect/disconnect calls def test_disconnect(self): |