summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/leap/eip/config.py26
-rw-r--r--src/leap/eip/test_config.py61
2 files changed, 79 insertions, 8 deletions
diff --git a/src/leap/eip/config.py b/src/leap/eip/config.py
index 11788ff..8c67a25 100644
--- a/src/leap/eip/config.py
+++ b/src/leap/eip/config.py
@@ -184,6 +184,15 @@ 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
@@ -201,9 +210,8 @@ def build_ovpn_options(daemon=False):
# get user/group name
# also from config.
- user = os.getlogin()
- gid = os.getgroups()[-1]
- group = grp.getgrgid(gid).gr_name
+ user = get_username()
+ group = get_groupname()
opts = []
@@ -241,6 +249,8 @@ def build_ovpn_options(daemon=False):
opts.append('--config')
default_provider_path = get_default_provider_path()
+
+ # XXX get rid of config_file at all
ovpncnf = get_config_file(
'openvpn.conf',
folder=default_provider_path)
@@ -255,7 +265,7 @@ def build_ovpn_options(daemon=False):
return opts
-def build_ovpn_command(config, debug=False):
+def build_ovpn_command(config, debug=False, do_pkexec_check=True):
"""
build a string with the
complete openvpn invocation
@@ -273,7 +283,7 @@ def build_ovpn_command(config, debug=False):
if config.has_option('openvpn', 'use_pkexec'):
use_pkexec = config.get('openvpn', 'use_pkexec')
- if platform.system() == "Linux" and use_pkexec:
+ if platform.system() == "Linux" and use_pkexec and do_pkexec_check:
# XXX check for both pkexec (done)
# AND a suitable authentication
@@ -304,7 +314,11 @@ def build_ovpn_command(config, debug=False):
'openvpn_binary')
if ovpn:
- command.append(ovpn)
+ vpn_command = ovpn
+ else:
+ vpn_command = "openvpn"
+
+ command.append(vpn_command)
daemon_mode = not debug
diff --git a/src/leap/eip/test_config.py b/src/leap/eip/test_config.py
index d92ace9..12679ec 100644
--- a/src/leap/eip/test_config.py
+++ b/src/leap/eip/test_config.py
@@ -1,3 +1,4 @@
+import ConfigParser
import os
import platform
import shutil
@@ -43,9 +44,11 @@ class EIPConfigTest(unittest.TestCase):
#
def get_username(self):
- return os.getlogin()
+ return config.get_username()
+
+ def get_groupname(self):
+ return config.get_groupname()
- #@unittest.skip
def _missing_test_for_plat(self, do_raise=False):
if do_raise:
raise NotImplementedError(
@@ -60,6 +63,38 @@ class EIPConfigTest(unittest.TestCase):
'openvpn')
open(tfile, 'bw').close()
+ def get_empty_config(self):
+ _config = ConfigParser.ConfigParser()
+ return _config
+
+ def get_minimal_config(self):
+ _config = ConfigParser.ConfigParser()
+ return _config
+
+ def get_expected_openvpn_args(self):
+ args = []
+ username = self.get_username()
+ groupname = self.get_groupname()
+
+ args.append('--user')
+ args.append(username)
+ args.append('--group')
+ args.append(groupname)
+ args.append('--management-client-user')
+ args.append(username)
+ args.append('--management-signal')
+ args.append('--management')
+
+ #XXX hey!
+ #get platform switches here!
+ args.append('/tmp/.eip.sock')
+ args.append('unix')
+ args.append('--config')
+ #XXX bad assumption. FIXME: expand $HOME
+ args.append('/home/%s/.config/leap/providers/default/openvpn.conf' %
+ username)
+ return args
+
#
# tests
#
@@ -148,6 +183,28 @@ class EIPConfigTest(unittest.TestCase):
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
+ # params in the function call, to disable
+ # some checks.
+ # XXX breaking!
+
+ def test_build_ovpn_command_empty_config(self):
+ _config = self.get_empty_config()
+ command, args = config.build_ovpn_command(
+ _config,
+ do_pkexec_check=False)
+ self.assertEqual(command, 'openvpn')
+ self.assertEqual(args, self.get_expected_openvpn_args())
+
if __name__ == "__main__":
unittest.main()