Make validation less crashy

This commit is contained in:
polyfloyd 2020-05-07 14:51:55 +02:00
parent 5e355569bb
commit de3275ca28

View file

@ -17,13 +17,12 @@ def read_ap(filepath):
regexp_mac = re.compile('^(:?[0-9a-f]{2}:){5}[0-9a-f]{2}$') regexp_mac = re.compile('^(:?[0-9a-f]{2}:){5}[0-9a-f]{2}$')
associations = json.loads(subprocess.check_output([ filepath ]).decode('utf8')) associations = json.loads(subprocess.check_output([ filepath ]).decode('utf8'))
assert type(associations) is list, 'The value returned by the AP driver is not a list' assert type(associations) is list, 'The value returned by the AP driver is not a list'
for assoc in associations:
assert type(assoc['mac']) is str def valid(assoc):
assert regexp_mac.match(assoc['mac']), 'Invalid MAC: %s' % assoc['mac'] return type(assoc['mac']) is str \
assert type(assoc['ssid']) is str and len(assoc['ssid']) > 1, 'Invalid SSID: %s' % assoc['ssid'] and regexp_mac.match(assoc['mac']) \
if 'signal' in assoc: and type(assoc['ssid']) is str and len(assoc['ssid']) > 1
assert type(assoc['signal']) is int return [ assoc for assoc in associations if valid(assoc)]
return associations
class Activity(object): class Activity(object):