From dd1e5083d99637d4118d12fa72605096d7b5e587 Mon Sep 17 00:00:00 2001 From: "Kali Kaneko (leap communications)" Date: Thu, 4 May 2017 19:05:26 +0200 Subject: [tests] simple e2e vpn test - Resolves: #8874 --- tests/e2e/check_ip | 45 ++++++++++++++++++++ tests/e2e/e2e-test-mail.sh | 103 +++++++++++++++++++++++++++++++++++++++++++++ tests/e2e/e2e-test-vpn.sh | 50 ++++++++++++++++++++++ tests/e2e/e2e-test.sh | 103 --------------------------------------------- 4 files changed, 198 insertions(+), 103 deletions(-) create mode 100755 tests/e2e/check_ip create mode 100755 tests/e2e/e2e-test-mail.sh create mode 100755 tests/e2e/e2e-test-vpn.sh delete mode 100755 tests/e2e/e2e-test.sh (limited to 'tests/e2e') diff --git a/tests/e2e/check_ip b/tests/e2e/check_ip new file mode 100755 index 00000000..8c12f250 --- /dev/null +++ b/tests/e2e/check_ip @@ -0,0 +1,45 @@ +#!/usr/bin/python3 + +import urllib.request +import json +import sys + +DEMO_ISP = 'Riseup Networks' + +url = 'https://wtfismyip.com/json' + +with urllib.request.urlopen(url) as _url: + data = json.loads(_url.read().decode()) + +isp = data['YourFuckingISP'] +ip = data['YourFuckingIPAddress'] + +print('ISP >> %s' % isp) +print('IP >> %s' % ip) + + +class BadCmd(Exception): + pass + + +try: + cmd = sys.argv[1] + + if cmd == 'vpn_on': + assert isp == DEMO_ISP + elif cmd == 'vpn_off': + assert isp != DEMO_ISP + else: + raise BadCmd() + +except BadCmd: + print("Cannot parse that command. Valid commands: vpn_on, vpn_off") + sys.exit(1) + +except Exception: + print("IP *NOT* as expected") + sys.exit(1) + +else: + print("OK :)") + sys.exit(0) diff --git a/tests/e2e/e2e-test-mail.sh b/tests/e2e/e2e-test-mail.sh new file mode 100755 index 00000000..8818147a --- /dev/null +++ b/tests/e2e/e2e-test-mail.sh @@ -0,0 +1,103 @@ +#!/bin/bash + +# Dependencies +# - swaks and uuid-runtime debian packages +# +# +# Usage +# +# In order to send authenticated mail to the tmp_user you need to +# export these environment variables before running this script: +# - FROM_EXTERNAL_OPTS for sending mails from external mailservers to the tmp_user account +# +# as an example: +# export FROM_EXTERNAL_OPTS='--tlsc --au user@example.or -ap MYPASSWORD -s smtp.example.org' +# +# then: +# +# source venv/bin/activate +# make dev-latest-backend +# make test_e2e +# +# +# TODO: +# - Timeout waiting for mail +# - Decrease poll interval +# - Make it less noisy (fix the vext warnings) +# - move away from cdev.bm +# - remove test user on success + +# exit if any commands returns non-zero status +set -e + +# Check if scipt is run in debug mode so we can hide secrets +if [[ "$-" =~ 'x' ]] +then + echo 'Running with xtrace enabled!' + xtrace=true +else + echo 'Running with xtrace disabled!' + xtrace=false +fi + +PROVIDER='ci.leap.se' +INVITE_CODE=${BITMASK_INVITE_CODE:?"Need to set BITMASK_INVITE_CODE non-empty"} + +BCTL='bitmaskctl' +LEAP_HOME="$HOME/.config/leap" +MAIL_UUID=$(uuidgen) + +username="tmp_user_$(date +%Y%m%d%H%M%S)" +user="${username}@${PROVIDER}" +pw="$(head -c 10 < /dev/urandom | base64)" +SWAKS="swaks --h-Subject $MAIL_UUID --silent 2 --helo ci.leap.se -f ci@leap.se -t $user" + +# Stop any previously started bitmaskd +# and start a new instance +"$BCTL" stop + +[ -d "$LEAP_HOME" ] && rm -rf "$LEAP_HOME" + +"$BCTL" start + +# Register a new user + +# Disable xtrace +set +x +"$BCTL" user create "$user" --pass "$pw" --invite "$INVITE_CODE" +# Enable xtrace again only if it was set at beginning of script +[[ $xtrace == true ]] && set -x + +# Authenticate +"$BCTL" user auth "$user" --pass "$pw" > /dev/null + +# Note that imap_pw is the same for smtp + +imap_pw="None" + +# FIXME -- this would be prettier if we had the auth command block on +# the first-time run, so that we just return when the key has been generated +# and explicitely raise any error found + +while [[ $imap_pw == *"None"* ]]; do + response=$("$BCTL" mail get_token) + sleep 2 + imap_pw=$(echo "$response" | head -n 1 | sed 's/ */ /g' | cut -d' ' -f 2) +done + +$SWAKS $FROM_EXTERNAL_OPTS + + +echo "IMAP/SMTP PASSWD: $imap_pw" + +# Send testmail +$SWAKS $FROM_EXTERNAL_OPTS + +# wait until we the get mail we just sent. +while ! ./tests/e2e/getmail --mailbox INBOX --subject "$MAIL_UUID" "$user" "$imap_pw" > /dev/null +do + echo "Waiting for incoming test mail..." + sleep 10 +done + +echo "Succeeded - mail arrived" diff --git a/tests/e2e/e2e-test-vpn.sh b/tests/e2e/e2e-test-vpn.sh new file mode 100755 index 00000000..90193bec --- /dev/null +++ b/tests/e2e/e2e-test-vpn.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +# Usage + +set -e + +PROVIDER='demo.bitmask.net' +BCTL='bitmaskctl' +LEAP_HOME="$HOME/.config/leap" + +username="tmp_user_$(date +%Y%m%d%H%M%S)" +user="${username}@${PROVIDER}" +pw="$(head -c 10 < /dev/urandom | base64)" + +# Stop any previously started bitmaskd +# and start a new instance +"$BCTL" stop + +[ -d "$LEAP_HOME" ] && rm -rf "$LEAP_HOME" + +"$BCTL" start + + +# Register a new user +"$BCTL" user create "$user" --pass "$pw" + +# Authenticate +"$BCTL" user auth "$user" --pass "$pw" > /dev/null + +# Enable VPN +"$BCTL" vpn enable + +# Get VPN cert +"$BCTL" vpn get_cert "$user" + +"$BCTL" vpn start + +sleep 10 + +"$BCTL" vpn status + +tests/e2e/check_ip vpn_on + +"$BCTL" vpn stop + +sleep 5 + +tests/e2e/check_ip vpn_off + +echo "Succeeded - the vpn routed you through the expected address" diff --git a/tests/e2e/e2e-test.sh b/tests/e2e/e2e-test.sh deleted file mode 100755 index 8818147a..00000000 --- a/tests/e2e/e2e-test.sh +++ /dev/null @@ -1,103 +0,0 @@ -#!/bin/bash - -# Dependencies -# - swaks and uuid-runtime debian packages -# -# -# Usage -# -# In order to send authenticated mail to the tmp_user you need to -# export these environment variables before running this script: -# - FROM_EXTERNAL_OPTS for sending mails from external mailservers to the tmp_user account -# -# as an example: -# export FROM_EXTERNAL_OPTS='--tlsc --au user@example.or -ap MYPASSWORD -s smtp.example.org' -# -# then: -# -# source venv/bin/activate -# make dev-latest-backend -# make test_e2e -# -# -# TODO: -# - Timeout waiting for mail -# - Decrease poll interval -# - Make it less noisy (fix the vext warnings) -# - move away from cdev.bm -# - remove test user on success - -# exit if any commands returns non-zero status -set -e - -# Check if scipt is run in debug mode so we can hide secrets -if [[ "$-" =~ 'x' ]] -then - echo 'Running with xtrace enabled!' - xtrace=true -else - echo 'Running with xtrace disabled!' - xtrace=false -fi - -PROVIDER='ci.leap.se' -INVITE_CODE=${BITMASK_INVITE_CODE:?"Need to set BITMASK_INVITE_CODE non-empty"} - -BCTL='bitmaskctl' -LEAP_HOME="$HOME/.config/leap" -MAIL_UUID=$(uuidgen) - -username="tmp_user_$(date +%Y%m%d%H%M%S)" -user="${username}@${PROVIDER}" -pw="$(head -c 10 < /dev/urandom | base64)" -SWAKS="swaks --h-Subject $MAIL_UUID --silent 2 --helo ci.leap.se -f ci@leap.se -t $user" - -# Stop any previously started bitmaskd -# and start a new instance -"$BCTL" stop - -[ -d "$LEAP_HOME" ] && rm -rf "$LEAP_HOME" - -"$BCTL" start - -# Register a new user - -# Disable xtrace -set +x -"$BCTL" user create "$user" --pass "$pw" --invite "$INVITE_CODE" -# Enable xtrace again only if it was set at beginning of script -[[ $xtrace == true ]] && set -x - -# Authenticate -"$BCTL" user auth "$user" --pass "$pw" > /dev/null - -# Note that imap_pw is the same for smtp - -imap_pw="None" - -# FIXME -- this would be prettier if we had the auth command block on -# the first-time run, so that we just return when the key has been generated -# and explicitely raise any error found - -while [[ $imap_pw == *"None"* ]]; do - response=$("$BCTL" mail get_token) - sleep 2 - imap_pw=$(echo "$response" | head -n 1 | sed 's/ */ /g' | cut -d' ' -f 2) -done - -$SWAKS $FROM_EXTERNAL_OPTS - - -echo "IMAP/SMTP PASSWD: $imap_pw" - -# Send testmail -$SWAKS $FROM_EXTERNAL_OPTS - -# wait until we the get mail we just sent. -while ! ./tests/e2e/getmail --mailbox INBOX --subject "$MAIL_UUID" "$user" "$imap_pw" > /dev/null -do - echo "Waiting for incoming test mail..." - sleep 10 -done - -echo "Succeeded - mail arrived" -- cgit v1.2.3