From ffec1c990aa5517d517179f721d77f800023a6bd Mon Sep 17 00:00:00 2001
From: Varac <varac@leap.se>
Date: Fri, 21 Jul 2017 17:54:39 +0200
Subject: [PATCH] [tests] Check egress IP for VPN steps

---
 Makefile                                |  7 +++--
 tests/functional/features/smoke.feature | 30 +++++++++++++++-------
 tests/functional/features/steps/vpn.py  | 34 +++++++++++++++++++++++--
 3 files changed, 58 insertions(+), 13 deletions(-)

diff --git a/Makefile b/Makefile
index c9ce3a7ee..543447aca 100644
--- a/Makefile
+++ b/Makefile
@@ -38,10 +38,13 @@ test_functional_setup:
 	pip install behave selenium
 
 test_functional:
-	xvfb-run --server-args="-screen 0 1280x1024x24" behave --tags ~@wip --tags @smoke tests/functional/features -k -D host=localhost
+	xvfb-run --server-args="-screen 0 1280x1024x24" behave --tags ~@wip --tags @smoke tests/functional/features -k --no-capture -D host=localhost
 
 test_functional_graphical:
-	behave --tags ~@wip --tags @smoke tests/functional/features -k -D host=localhost
+	behave --tags ~@wip --tags @smoke tests/functional/features -k --no-capture -D host=localhost
+
+test_functional_graphical_wip:
+	behave --tags @wip tests/functional/features -k --no-capture -D host=localhost
 
 install_helpers:
 	cp src/leap/bitmask/vpn/helpers/linux/bitmask-root /usr/local/sbin/
diff --git a/tests/functional/features/smoke.feature b/tests/functional/features/smoke.feature
index efa3cad76..1e2201160 100644
--- a/tests/functional/features/smoke.feature
+++ b/tests/functional/features/smoke.feature
@@ -1,19 +1,31 @@
 Feature: login and logout
 
+  @smoke
   Scenario: See user panel after login
     Given I start bitmask for the first time
-    When I login
-    Then I should see the user panel
+    When  I login
+    Then  I should see the user panel
 
+  @smoke
   Scenario: Log in and log out
     Given I start bitmask for the first time
-    When I login
-    And I logout
-    Then I should see the second login page
+    When  I login
+    And   I logout
+    Then  I should see the second login page
 
   @smoke
-  Scenario: Use VPN
+  Scenario: Turn VPN on
+    Given I start bitmask for the first time
+    And   An initial network configuration
+    When  I login
+    And   I activate VPN
+    Then  I should have my ass covered
+
+  @wip
+  Scenario: Turn VPN on and off
     Given I start bitmask for the first time
-    When I login
-    And I activate VPN
-    Then I should have my ass covered
+    And   An initial network configuration
+    When  I login
+    And   I activate VPN
+    And   I deactivate VPN
+    Then  My network should be configured as before
diff --git a/tests/functional/features/steps/vpn.py b/tests/functional/features/steps/vpn.py
index 056b2cdfd..05ed2b54d 100644
--- a/tests/functional/features/steps/vpn.py
+++ b/tests/functional/features/steps/vpn.py
@@ -1,10 +1,28 @@
-from behave import when, then
+from behave import given, when, then
 from common import (
     click_button,
     wait_until_button_is_visible,
     find_element_containing_text
 )
 from selenium.common.exceptions import TimeoutException
+# For checking IP
+import requests
+
+
+@given('An initial network configuration')
+def record_ip(context):
+    context.initial_ip = _current_ip()
+
+
+def _current_ip():
+    url = 'https://wtfismyip.com/json'
+
+    r = requests.get(url)
+    data = r.json()
+
+    current_ip = data['YourFuckingIPAddress']
+    print("Current IP: %s\n\n" % current_ip)
+    return current_ip
 
 
 @when('I activate VPN')
@@ -19,4 +37,16 @@ def activate_vpn(context):
 @then('I should have my ass covered')
 def assert_vpn(context):
     wait_until_button_is_visible(context, 'Turn OFF')
-    assert find_element_containing_text(context, 'Turn OFF', 'button')
+    assert _current_ip() != context.initial_ip
+
+
+@when('I deactivate VPN')
+def deactivate_vpn(context):
+    click_button(context, 'Turn OFF')
+    wait_until_button_is_visible(context, 'Turn ON')
+
+
+@then('My network should be configured as before')
+def network_as_before(context):
+    ip = _current_ip()
+    assert ip == context.initial_ip
-- 
GitLab