Skip to content

Commit

Permalink
Restricted schema for interface names #24
Browse files Browse the repository at this point in the history
Closes #24
  • Loading branch information
nemesifier committed Nov 2, 2015
1 parent cd4b217 commit 4261940
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
4 changes: 3 additions & 1 deletion netjsonconfig/schema.py
Expand Up @@ -19,7 +19,9 @@
],
"properties": {
"name": {
"type": "string"
"type": "string",
"maxLength": 15,
"pattern": "^[^\s]*$"
},
"mac": {
"type": "string"
Expand Down
28 changes: 25 additions & 3 deletions tests/openwrt/test_network.py
Expand Up @@ -606,13 +606,35 @@ def test_bridge_members_schema(self):
with self.assertRaises(ValidationError):
o.validate()
# ensure fix works
o.config['interfaces'][0]['bridge_members'] = ['eth0', 'wlan0']
o.validate()

def test_ifname_length(self):
o = OpenWrt({
"interfaces": [
{
"name": "lan",
"type": "bridge",
"bridge_members": ["eth0", "wlan0"]
"name": "ifname0123456789",
"type": "ethernet"
}
]
})
with self.assertRaises(ValidationError):
o.validate()
# ensure fix works
o.config['interfaces'][0]['name'] = 'ifname0'
o.validate()

def test_ifname_pattern(self):
o = OpenWrt({
"interfaces": [
{
"name": "eth 0",
"type": "ethernet"
}
]
})
with self.assertRaises(ValidationError):
o.validate()
# ensure fix works
o.config['interfaces'][0]['name'] = 'e-t_h@=0.1'
o.validate()

0 comments on commit 4261940

Please sign in to comment.