Skip to content

Commit

Permalink
[OpenWrt] Validate ntp server hostname format #42
Browse files Browse the repository at this point in the history
  • Loading branch information
nemesifier committed Apr 3, 2016
1 parent 2f23cfd commit 612959e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
3 changes: 2 additions & 1 deletion netjsonconfig/backends/openwrt/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@
"propertyOrder": 3,
"items": {
"title": "NTP server",
"type": "string"
"type": "string",
"format": "hostname"
},
"default": [
"0.openwrt.pool.ntp.org",
Expand Down
36 changes: 36 additions & 0 deletions tests/openwrt/test_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.