Skip to content

Commit

Permalink
Merge 254de1a into 2bae0da
Browse files Browse the repository at this point in the history
  • Loading branch information
Aryamanz29 committed Aug 3, 2023
2 parents 2bae0da + 254de1a commit 45c1064
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
4 changes: 2 additions & 2 deletions netjsonconfig/backends/openwrt/converters/zerotier.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def __intermediate_vpn(self, vpn):

def __netjson_vpn(self, vpn):
vpn['id'] = vpn.pop('join')
vpn['name'] = vpn.pop('.name').replace('_', '-')
# 'disabled' defaults to False in OpenWRT
vpn['name'] = vpn.pop('.name')
# 'enabled' defaults to False in OpenWRT
vpn['disabled'] = vpn.pop('enabled', '0') == '0'
del vpn['.type']
return super().__netjson_vpn(vpn)
3 changes: 2 additions & 1 deletion netjsonconfig/backends/zerotier/zerotier.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ class ZeroTier(BaseVpnBackend):
config_suffix = config_suffix

@classmethod
def auto_client(cls, name='', nwid=None, disabled=False):
def auto_client(cls, name='', nwid=None, identity_secret=None, disabled=False):
nwid = nwid or ['']
return {
'id': nwid,
'name': name,
'secret': identity_secret,
'disabled': disabled,
}
12 changes: 9 additions & 3 deletions tests/openwrt/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,22 +548,28 @@ def test_vxlan_wireguard_auto_client(self):

def test_zerotier_auto_client(self):
with self.subTest('No arguments provided'):
expected = {'zerotier': [{'id': [''], 'name': '', 'disabled': False}]}
expected = {
'zerotier': [
{'name': '', 'id': [''], 'secret': None, 'disabled': False}
]
}
self.assertDictEqual(OpenWrt.zerotier_auto_client(), expected)
with self.subTest('Required arguments provided'):
expected = {
'zerotier': [
{
'name': 'ow_zt',
'id': ['9536600adf654321'],
'name': 'zerotier-openwisp-network',
'secret': 'test_secret',
'disabled': False,
}
]
}
self.assertDictEqual(
OpenWrt.zerotier_auto_client(
name='ow_zt',
nwid=['9536600adf654321'],
name='zerotier-openwisp-network',
identity_secret='test_secret',
),
expected,
)
8 changes: 4 additions & 4 deletions tests/openwrt/test_zerotier.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class TestZeroTier(unittest.TestCase, _TabsMixin):
"zerotier": [
{
"id": ["9536600adf654321", "9536600adf654322"],
"name": "zerotier-openwisp-network",
"name": "ow_zt",
},
]
}
Expand All @@ -20,7 +20,7 @@ def test_render_zerotier(self):
expected = self._tabs(
"""package zerotier
config zerotier 'zerotier_openwisp_network'
config zerotier 'ow_zt'
option enabled '1'
list join '9536600adf654321'
list join '9536600adf654322'
Expand All @@ -32,7 +32,7 @@ def test_parse_zerotier(self):
native = self._tabs(
"""package zerotier
config zerotier 'zerotier_openwisp_network'
config zerotier 'ow_zt'
option enabled '0'
list join '9536600adf654321'
list join '9536600adf654322'
Expand All @@ -42,7 +42,7 @@ def test_parse_zerotier(self):
"zerotier": [
{
"id": ["9536600adf654321", "9536600adf654322"],
"name": "zerotier-openwisp-network",
"name": "ow_zt",
"disabled": True,
},
]
Expand Down
6 changes: 4 additions & 2 deletions tests/zerotier/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,15 +385,17 @@ def test_generate(self):

def test_auto_client(self):
expected = {
"name": "ow_zt",
"id": ["9536600adf654321"],
"name": "zerotier-openwisp-network",
"secret": "test_secret",
"disabled": False,
}
test_config = self._TEST_CONFIG["zerotier"][0]
self.assertEqual(
ZeroTier.auto_client(
name="ow_zt",
nwid=[test_config['id']],
name=test_config['name'],
identity_secret="test_secret",
),
expected,
)

0 comments on commit 45c1064

Please sign in to comment.