Skip to content

Commit

Permalink
[OpenWrt] Added regexp pattern to maclist elements
Browse files Browse the repository at this point in the history
  • Loading branch information
nemesifier committed Mar 24, 2016
1 parent 26b62dd commit 11da509
Show file tree
Hide file tree
Showing 2 changed files with 37 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 @@ -112,8 +112,9 @@
"items": {
"type": "string",
"title": "MAC address",
"maxLength": 17,
"pattern": "^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$",
"minLength": 17,
"maxLength": 17,
}
}
}
Expand Down
35 changes: 35 additions & 0 deletions tests/openwrt/test_wireless.py
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,41 @@ def test_wifi_macfilter(self):
""")
self.assertEqual(o.render(), expected)

def test_maclist_format(self):
o = OpenWrt({
"interfaces": [
{
"name": "wlan0",
"type": "wireless",
"wireless": {
"radio": "radio0",
"mode": "access_point",
"ssid": "MyWifiAP",
"macfilter": "deny",
"maclist": [
"E8:94:F6:33:8C:1D",
]
}
}
]
})
o.validate()
# too short
o.config['interfaces'][0]['wireless']['maclist'][0] = '00:11:22:33:44'
with self.assertRaises(ValidationError):
o.validate()
# valid
o.config['interfaces'][0]['wireless']['maclist'][0] = '00-11-22-33-44-55'
o.validate()
# should not be valid
o.config['interfaces'][0]['wireless']['maclist'][0] = '00:11:22:33:44:ZY'
with self.assertRaises(ValidationError):
o.validate()
# empty is not valid
o.config['interfaces'][0]['wireless']['maclist'][0] = ''
with self.assertRaises(ValidationError):
o.validate()

def test_wds_bridge(self):
o = OpenWrt({
"interfaces": [
Expand Down

0 comments on commit 11da509

Please sign in to comment.