From e9a817ceadab842ec5382e074e4d7861dbd2b898 Mon Sep 17 00:00:00 2001 From: antialias Date: Tue, 21 Aug 2012 15:27:29 -0700 Subject: pep --- src/leap/eip/exceptions.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/leap/eip') diff --git a/src/leap/eip/exceptions.py b/src/leap/eip/exceptions.py index ac61f42b..3719c605 100644 --- a/src/leap/eip/exceptions.py +++ b/src/leap/eip/exceptions.py @@ -61,5 +61,3 @@ class EIPInitNoKeyFileError(Exception): class EIPInitBadKeyFilePermError(Exception): pass - - -- cgit v1.2.3 From 9891fc2f6869db7fc56503087ce124d74f5fc3b7 Mon Sep 17 00:00:00 2001 From: antialias Date: Wed, 22 Aug 2012 14:01:22 -0700 Subject: moved help functions from eip/config.py to base/configuration.py. --- src/leap/eip/config.py | 86 +++----------------------------------------------- 1 file changed, 4 insertions(+), 82 deletions(-) (limited to 'src/leap/eip') diff --git a/src/leap/eip/config.py b/src/leap/eip/config.py index f38268e2..b461422a 100644 --- a/src/leap/eip/config.py +++ b/src/leap/eip/config.py @@ -8,6 +8,10 @@ import socket from leap.util.fileutil import (which, mkdir_p, check_and_fix_urw_only) +from leap.base.configuration import (get_default_provider_path, + get_config_file, + get_username, + get_groupname) from leap.baseapp.permcheck import (is_pkexec_in_system, is_auth_agent_running) from leap.eip import exceptions as eip_exceptions @@ -32,55 +36,6 @@ ca {LEAP_EIP_KEYS} """ -def get_config_dir(): - """ - get the base dir for all leap config - @rparam: config path - @rtype: string - """ - # TODO - # check for $XDG_CONFIG_HOME var? - # get a more sensible path for win/mac - # kclair: opinion? ^^ - return os.path.expanduser( - os.path.join('~', - '.config', - 'leap')) - - -def get_config_file(filename, folder=None): - """ - concatenates the given filename - with leap config dir. - @param filename: name of the file - @type filename: string - @rparam: full path to config file - """ - path = [] - path.append(get_config_dir()) - if folder is not None: - path.append(folder) - path.append(filename) - return os.path.join(*path) - - -def get_default_provider_path(): - default_subpath = os.path.join("providers", - "default") - default_provider_path = get_config_file( - '', - folder=default_subpath) - return default_provider_path - - -def validate_ip(ip_str): - """ - raises exception if the ip_str is - not a valid representation of an ip - """ - socket.inet_aton(ip_str) - - def check_or_create_default_vpnconf(config): """ checks that a vpn config file @@ -158,15 +113,6 @@ def check_or_create_default_vpnconf(config): f.write(ovpn_config) -def get_username(): - return os.getlogin() - - -def get_groupname(): - gid = os.getgroups()[-1] - return grp.getgrgid(gid).gr_name - - def build_ovpn_options(daemon=False): """ build a list of options @@ -412,27 +358,3 @@ def check_vpn_keys(config): check_and_fix_urw_only(keyfile) except OSError: raise eip_exceptions.EIPInitBadKeyFilePermError - - -def get_config_json(config_file=None): - """ - will replace get_config function be developing them - in parralel for branch purposes. - @param: configuration file - @type: file - @rparam: configuration turples - @rtype: dictionary - """ - if not config_file: - fpath = get_config_file('eip.json') - if not os.path.isfile(fpath): - dpath, cfile = os.path.split(fpath) - if not os.path.isdir(dpath): - mkdir_p(dpath) - with open(fpath, 'wb') as configfile: - configfile.flush() - config_file = open(fpath) - - config = json.load(config_file) - - return config -- cgit v1.2.3 From dc10833bedcdecf081a7c79678614c5521445164 Mon Sep 17 00:00:00 2001 From: antialias Date: Wed, 22 Aug 2012 19:47:41 -0700 Subject: grabs a definition.json file if one isn't present. includes some basic error handling and tests. uses the requests library for network interactions and mocks for simulating network states. --- src/leap/eip/tests/test_config.py | 104 -------------------------------------- 1 file changed, 104 deletions(-) (limited to 'src/leap/eip') diff --git a/src/leap/eip/tests/test_config.py b/src/leap/eip/tests/test_config.py index b4ad66e5..0e1a3a01 100644 --- a/src/leap/eip/tests/test_config.py +++ b/src/leap/eip/tests/test_config.py @@ -82,101 +82,6 @@ class EIPConfigTest(BaseLeapTest): username) return args - # - # tests - # - - # XXX fixme! /home/user should - # be replaced for proper home lookup. - - @unittest.skipUnless(_system == "Linux", "linux only") - def test_lin_get_config_file(self): - """ - config file path where expected? (linux) - """ - self.assertEqual( - config.get_config_file( - 'test', folder="foo/bar"), - '/home/%s/.config/leap/foo/bar/test' % - self.get_username()) - - @unittest.skipUnless(_system == "Darwin", "mac only") - def test_mac_get_config_file(self): - """ - config file path where expected? (mac) - """ - self._missing_test_for_plat(do_raise=True) - - @unittest.skipUnless(_system == "Windows", "win only") - def test_win_get_config_file(self): - """ - config file path where expected? - """ - self._missing_test_for_plat(do_raise=True) - - # - # XXX hey, I'm raising exceptions here - # on purpose. just wanted to make sure - # that the skip stuff is doing it right. - # If you're working on win/macos tests, - # feel free to remove tests that you see - # are too redundant. - - @unittest.skipUnless(_system == "Linux", "linux only") - def test_lin_get_config_dir(self): - """ - nice config dir? (linux) - """ - self.assertEqual( - config.get_config_dir(), - '/home/%s/.config/leap' % - self.get_username()) - - @unittest.skipUnless(_system == "Darwin", "mac only") - def test_mac_get_config_dir(self): - """ - nice config dir? (mac) - """ - self._missing_test_for_plat(do_raise=True) - - @unittest.skipUnless(_system == "Windows", "win only") - def test_win_get_config_dir(self): - """ - nice config dir? (win) - """ - self._missing_test_for_plat(do_raise=True) - - # provider paths - - @unittest.skipUnless(_system == "Linux", "linux only") - def test_get_default_provider_path(self): - """ - is default provider path ok? - """ - self.assertEqual( - config.get_default_provider_path(), - '/home/%s/.config/leap/providers/default/' % - self.get_username()) - - # validate ip - - def test_validate_ip(self): - """ - check our ip validation - """ - config.validate_ip('3.3.3.3') - with self.assertRaises(socket.error): - config.validate_ip('255.255.255.256') - with self.assertRaises(socket.error): - config.validate_ip('foobar') - - @unittest.skip - def test_validate_domain(self): - """ - code to be written yet - """ - pass - # build command string # these tests are going to have to check # many combinations. we should inject some @@ -191,15 +96,6 @@ class EIPConfigTest(BaseLeapTest): self.assertEqual(command, 'openvpn') self.assertEqual(args, self.get_expected_openvpn_args()) - # json config - - def test_get_config_json(self): - config_js = config.get_config_json() - self.assertTrue(isinstance(config_js, dict)) - self.assertTrue('transport' in config_js) - self.assertTrue('provider' in config_js) - self.assertEqual(config_js['provider'], "testprovider.org") - if __name__ == "__main__": unittest.main() -- cgit v1.2.3