Skip to content

Commit

Permalink
add autosecuring to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
geohot committed Feb 13, 2018
1 parent b27d185 commit 6b11fb5
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions tests/automated/helpers.py
Expand Up @@ -3,6 +3,7 @@
import time
import random
import subprocess
import requests
from panda import Panda
from nose.tools import timed, assert_equal, assert_less, assert_greater

Expand Down Expand Up @@ -30,22 +31,32 @@ def _connect_wifi(dongle_id, pw):

print("WIFI: connecting to %s" % ssid)

if sys.platform == "darwin":
os.system("networksetup -setairportnetwork en0 %s %s" % (ssid, pw))
else:
cnt = 0
MAX_TRIES = 10
while cnt < MAX_TRIES:
print "WIFI: scanning %d" % cnt
os.system("nmcli device wifi rescan")
wifi_scan = filter(lambda x: ssid in x, subprocess.check_output(["nmcli","dev", "wifi", "list"]).split("\n"))
if len(wifi_scan) != 0:
while 1:
if sys.platform == "darwin":
os.system("networksetup -setairportnetwork en0 %s %s" % (ssid, pw))
else:
cnt = 0
MAX_TRIES = 10
while cnt < MAX_TRIES:
print "WIFI: scanning %d" % cnt
os.system("nmcli device wifi rescan")
wifi_scan = filter(lambda x: ssid in x, subprocess.check_output(["nmcli","dev", "wifi", "list"]).split("\n"))
if len(wifi_scan) != 0:
break
time.sleep(0.1)
# MAX_TRIES tries, ~10 seconds max
cnt += 1
assert cnt < MAX_TRIES
if "-pair" in wifi_scan[0]:
os.system("nmcli d wifi connect %s-pair" % (ssid))
print "connecting to insecure network to secure"
try:
r = requests.get("http://192.168.0.10/secure", timeout=0.01)
except requests.exceptions.Timeout:
pass
else:
os.system("nmcli d wifi connect %s password %s" % (ssid, pw))
break
time.sleep(0.1)
# MAX_TRIES tries, ~10 seconds max
cnt += 1
assert cnt < MAX_TRIES
os.system("nmcli d wifi connect %s password %s" % (ssid, pw))

# TODO: confirm that it's connected to the right panda

Expand Down

0 comments on commit 6b11fb5

Please sign in to comment.