Use enums to describe target WPS state.

To avoid confusion about wps = True/False/None.
Came about because of #130
This commit is contained in:
derv82
2018-09-09 10:39:57 -07:00
parent 355f891d0f
commit e190794149
8 changed files with 38 additions and 24 deletions

View File

@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
from .dependency import Dependency
from ..model.target import WPSState
from ..util.process import Process
import re
@@ -188,7 +189,6 @@ class Tshark(Dependency):
if ',' not in line:
continue
bssid, locked = line.split(',')
# Ignore if WPS is locked?
if '1' not in locked:
wps_bssids.add(bssid.upper())
else:
@@ -197,11 +197,11 @@ class Tshark(Dependency):
for t in targets:
target_bssid = t.bssid.upper()
if target_bssid in wps_bssids:
t.wps = True
t.wps = WPSState.UNLOCKED
elif target_bssid in locked_bssids:
t.wps = None
t.wps = WPSState.LOCKED
else:
t.wps = False
t.wps = WPSState.NONE
if __name__ == '__main__':
@@ -224,7 +224,8 @@ if __name__ == '__main__':
# Should update 'wps' field of a target
Tshark.check_for_wps_and_update_targets(test_file, targets)
print('Target(BSSID={}).wps = {} (Expected: True)'.format(targets[0].bssid, targets[0].wps))
assert targets[0].wps == True
print('Target(BSSID={}).wps = {} (Expected: 1)'.format(
targets[0].bssid, targets[0].wps))
assert targets[0].wps == WPSState.UNLOCKED
print(Tshark.bssids_with_handshakes(test_file, bssid=target_bssid))