Skip to content

Commit 26b62dd

Browse files
committed
[schema] Added pattern for BSSID attribute
1 parent 468a5df commit 26b62dd

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

Diff for: netjsonconfig/schema.py

+1
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@
331331
"bssid": {
332332
"type": "string",
333333
"title": "BSSID",
334+
"pattern": "^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$",
334335
"minLength": 17,
335336
"maxLength": 17,
336337
"propertyOrder": 4,

Diff for: tests/openwrt/test_wireless.py

+32
Original file line numberDiff line numberDiff line change
@@ -1130,3 +1130,35 @@ def test_mesh_80211s(self):
11301130
option network 'lan'
11311131
""")
11321132
self.assertEqual(o.render(), expected)
1133+
1134+
def test_bssid_format(self):
1135+
o = OpenWrt({
1136+
"interfaces": [
1137+
{
1138+
"name": "wlan0",
1139+
"type": "wireless",
1140+
"wireless": {
1141+
"radio": "radio1",
1142+
"mode": "adhoc",
1143+
"ssid": "adhoc-ssid",
1144+
"bssid": "00:11:22:33:44:55"
1145+
}
1146+
}
1147+
]
1148+
})
1149+
o.validate()
1150+
# too short
1151+
o.config['interfaces'][0]['wireless']['bssid'] = '00:11:22:33:44'
1152+
with self.assertRaises(ValidationError):
1153+
o.validate()
1154+
# valid
1155+
o.config['interfaces'][0]['wireless']['bssid'] = '00-11-22-33-44-55'
1156+
o.validate()
1157+
# should not be valid
1158+
o.config['interfaces'][0]['wireless']['bssid'] = '00:11:22:33:44:ZY'
1159+
with self.assertRaises(ValidationError):
1160+
o.validate()
1161+
# empty is not valid
1162+
o.config['interfaces'][0]['wireless']['bssid'] = ''
1163+
with self.assertRaises(ValidationError):
1164+
o.validate()

0 commit comments

Comments
 (0)