Skip to content
This repository was archived by the owner on Apr 3, 2025. It is now read-only.

Commit 7eb5835

Browse files
committed
fix #89
1 parent 33a10a9 commit 7eb5835

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

eduvpn/openvpn.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def ovpn_to_nm(config, uuid, display_name, username=None):
8585
'ipv6': {'method': 'auto'},
8686
'vpn': {'data': {'auth': config.get('auth', 'SHA256'),
8787
'cipher': config.get('cipher', 'AES-256-CBC'),
88-
'comp-lzo': config.get('auth', 'adaptive'),
88+
'comp-lzo': config.get('comp-lzo', 'adaptive'),
8989
'connection-type': config.get('connection-type', 'tls'),
9090
'dev': 'tun',
9191
'remote': ",".join(":".join(r) for r in config['remote']),
@@ -97,10 +97,13 @@ def ovpn_to_nm(config, uuid, display_name, username=None):
9797

9898
# 2 factor auth enabled
9999
if 'auth-user-pass' in config:
100+
assert username
100101
logger.info("looks like 2 factor authentication is enabled, enabling this in NM config")
101102
settings['vpn']['data']['cert-pass-flags'] = '0'
102103
settings['vpn']['data']['connection-type'] = 'password-tls'
103104
settings['vpn']['data']['password-flags'] = '2'
104105
settings['vpn']['data']['username'] = username
106+
else:
107+
assert not username
105108

106109
return settings

tests/test_openvpn.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
# Copyright: 2017, The Commons Conservancy eduVPN Programme
44
# SPDX-License-Identifier: GPL-3.0+
55

6-
from os import path
76
import unittest
8-
from eduvpn.openvpn import format_like_ovpn, parse_ovpn
7+
from eduvpn.openvpn import format_like_ovpn, parse_ovpn, ovpn_to_nm
98

109
from tests.mock_config import mock_config
1110

@@ -15,4 +14,15 @@ def test_format_like_ovpn(self):
1514
format_like_ovpn('test', 'test', 'test')
1615

1716
def test_parse_ovpn(self):
18-
parse_ovpn(mock_config)
17+
_ = parse_ovpn(mock_config)
18+
19+
def test_ovpn_to_nm(self):
20+
config = parse_ovpn(mock_config)
21+
_ = ovpn_to_nm(config=config, uuid='test_uuid', display_name='test name')
22+
23+
def test_ovpn_to_nm_2fa(self):
24+
config = parse_ovpn(mock_config)
25+
config['auth-user-pass'] = True
26+
username = 'test_user'
27+
nm_dict = ovpn_to_nm(config=config, uuid='test_uuid', display_name='test name', username=username)
28+
self.assertEqual(username, nm_dict['vpn']['data']['username'], username)

0 commit comments

Comments
 (0)