Commit 527bef59 authored by Nolan's avatar Nolan

Test environment and start of tests.

Currently tests all the way to redirecting the client to boundery.me.
parent 11cde26c
......@@ -68,3 +68,14 @@ upload-rpi3zip: start-vms
vagrant ssh boundery.me -c 'sudo mkdir -p /root/data/sslnginx/html/images'
scp -F $(BOUNDERY_SSHCONF) $(OS_SRC)/build/arm64/images/rpi3.zip \
root@boundery.me:/root/data/sslnginx/html/images/
test-linux-pczip: start-vms
# XXX stop (or destroy?) server.
vagrant provision --provision-with install client
@mdel -ibuild/server.img@@1M ::/pairingkey 2>/dev/null || true
vagrant ssh client -c '/vagrant/run_test.sh pc' &
@echo Waiting for pairingkey to show up...
@while ! mdir -b -ibuild/server.img@@1M ::/pairingkey 2>/dev/null; do sleep 1; done
# XXX boot server.
# XXX Wait for test completion
# XXX verify that preserve.txt contains "precious\n"
......@@ -108,20 +108,34 @@ Vagrant.configure("2") do |config|
client.vm.hostname = "client"
client.vm.network "private_network",
virtualbox__intnet: "client_router", type: "dhcp"
client.vm.network "forwarded_port", host: 5900, guest: 5900
client.vm.network "forwarded_port", host: 22222, guest: 22222
client.vm.provision "shell", inline: <<-SHELL
#XXX Install selenium/chromedriver/any other deps.
#XXX Because we short circuit the dyndns NS forward to the pi, need to explicitly
# check that username.boundery.me gets the right NS destination (30.0.0.150).
# dig ns nolan.boundery.me. @boundery.me.
sudo apt-get update
#XXX We install python3-cffi-backend here due to a briefcase bug. bug 44?
sudo apt-get install -y --no-install-recommends network-manager xvfb x11vnc \
python3-cffi-backend python3-paramiko libnss3-tools
sudo cp /vagrant/client/rc.local /etc/
sudo chmod a+x /etc/rc.local
sudo /etc/rc.local
SHELL
#XXX Provisioner to install client from boundery.me
#XXX Provisioner to copy in (or rely on /vagrant?) and run tests
client.vm.provision "install", type: "shell", run: "never", privileged: false, inline: <<-SHELL
#XXX Sanity check fakedns, other environment stuff?
sudo /etc/rc.local #refetch ssl root cert in case pebble restarted.
rm -rf boundery-linux-client*
wget https://boundery.me/static/clients/boundery-linux-client.tar.gz
tar zxvf boundery-linux-client.tar.gz
#Make root cert available to client's embedded ca list.
cp /etc/ssl/certs/ca-certificates.crt boundery-linux-client/app_packages/certifi/cacert.pem
#Make root cert available to chromium/chromedriver's embedded ca list.
certutil -A -n "fakeroot" -t "TCu,Cu,Tu" -i /usr/local/share/ca-certificates/fakeroot.crt \
-d sql:/home/vagrant/.pki/nssdb || true
SHELL
end
################# HOME SERVER #################
......
#!/bin/sh
echo BROWSE $* | nc localhost 9999
#!/bin/bash
#Sanity checks
if [ -z "$1" ]; then
echo "Usage: $0 zipname" >&2
exit 99
fi
if ps ax | grep -q '[B]oundery Client'; then
echo "Client already running!" >&2
exit 90
fi
if ps ax | grep -q '[t]est_client.py'; then
echo "Tester already running!" >&2
exit 91
fi
#XXX Verify that OS image exists on server.
#Prep
if mount | grep -q ^/dev/sdb1; then
echo "/dev/sdb1 already mounted!" >&2
exit 92
fi
sudo mount -o umask=000 /dev/sdb1 /mnt
set -m #Enable job control
#Setup test environment and run tests.
kill -9 `pidof chromedriver` `pidof Xvfb` 2>/dev/null
Xvfb &> .xvfb.log &
sleep 1
DISPLAY=:0 x11vnc -forever -shared &> .x11vnc.log &
python3 /vagrant/fake_vagrant_sshd.py &
DISPLAY=:0 python3 /vagrant/test_client.py -d &
while ! ss -tln | grep -q ':9999'; do
sleep 1
done
ZIPFILE_NAME="$1" BROWSER=/vagrant/fake_browser.sh boundery-linux-client/Boundery\ Client &
fg %4 #tester
jobs
kill -9 %5 #client
kill -9 %3 #fake_vagrant_sshd.py
kill -9 %2 #x11vnc
kill -9 %1 #Xvfb
import sys, os
import socketserver
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
class TCPCmdHandler(socketserver.StreamRequestHandler):
def handle(self):
global url
cmd = self.rfile.readline().decode().split(' ')
assert(cmd[0] == "BROWSE")
url = cmd[1]
def screenshot(d, name):
d.save_screenshot('/vagrant/build/screenshots/%s.png' % name)
with socketserver.TCPServer(('localhost', 9999), TCPCmdHandler, bind_and_activate=False) as server:
server.allow_reuse_address = True
server.server_bind()
server.server_activate()
server.handle_request()
os.makedirs('/vagrant/build/screenshots', exist_ok=True)
d = webdriver.Chrome()
d.set_page_load_timeout(10)
d.implicitly_wait(10) #10s timeout for finding elements.
#Step 1
print("Navigating to URL:", url)
d.get(url)
ssid_radios = d.find_elements_by_name('ssid')
wired_radio = ssid_radios[-1]
assert(wired_radio.get_attribute('value') == '')
wired_radio.click()
screenshot(d, 'step1')
mount = d.find_element_by_name('mount')
mount.click()
screenshot(d, 'step1_writing')
wait = WebDriverWait(d, 60)
click_here = wait.until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, 'click here')))
screenshot(d, 'step1_done')
os.sync()
os.system('sudo umount /mnt')
click_here.click()
#Step 2
screenshot(d, 'step2')
click_here = d.find_element_by_tag_name('a')
click_here.click()
#Step 3 (boundery.me)
#XXX Because we short circuit the dyndns NS forward to the pi, need to explicitly
# check that username.boundery.me gets the right NS destination (30.0.0.150).
# dig ns nolan.boundery.me. @boundery.me.
if '-d' in sys.argv:
import code
code.InteractiveConsole(locals=locals()).interact()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment