Skip to content
Permalink
Browse files

[OpenWrt] Validate ntp server hostname format #42

  • Loading branch information
nemesisdesign committed Apr 3, 2016
1 parent 2f23cfd commit 612959e0089b456b17ffd90c17afcb928706e491
Showing with 38 additions and 1 deletion.
  1. +2 −1 netjsonconfig/backends/openwrt/schema.py
  2. +36 −0 tests/openwrt/test_formats.py
@@ -290,7 +290,8 @@
"propertyOrder": 3,
"items": {
"title": "NTP server",
"type": "string"
"type": "string",
"format": "hostname"
},
"default": [
"0.openwrt.pool.ntp.org",
@@ -37,3 +37,39 @@ def test_interface_ipv4(self):
o.config['interfaces'][0]['addresses'][0]['address'] = '127_0_0_1'
with self.assertRaises(ValidationError):
o.validate()

def test_interface_ipv6(self):
o = OpenWrt({
"interfaces": [
{
"name": "eth0",
"type": "ethernet",
"addresses": [
{
"family": "ipv6",
"proto": "static",
"address": "fe80::ba27:ebff:fe1c:5477",
"mask": 64
}
]
}
]
})
o.validate()
# invalid ipv6
o.config['interfaces'][0]['addresses'][0]['address'] = 'fe80::ba27.ebff_fe1c:5477'
with self.assertRaises(ValidationError):
o.validate()

def test_ntp_servers_hostname(self):
o = OpenWrt({
"ntp": {
"enabled": True,
"server": ["0.openwrt.pool.ntp.org"]
}
})
o.validate()
# invalid hostname
o.config['ntp']['server'][0] = 'totally/wrong'
with self.assertRaises(ValidationError):
o.validate()

0 comments on commit 612959e

Please sign in to comment.
You can’t perform that action at this time.