Skip to content

Commit

Permalink
Add singleuser net-policy test for 1.12.3 only
Browse files Browse the repository at this point in the history
  • Loading branch information
manics committed Dec 8, 2018
1 parent 5bc3795 commit f659a7a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions ci/minikube-1.10.0.env
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export KUBEVAL_VERSION=0.7.1
export PATH="$PWD/bin:$PATH"
export MINIKUBE_ARGS="--vm-driver=none --kubernetes-version=v${KUBE_VERSION}"
export Z2JH_HELM_ARGS="-f minikube-config.yaml"
export DISABLE_TEST_NETPOL=1
1 change: 1 addition & 0 deletions ci/minikube-1.9.4.env
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export KUBEVAL_VERSION=0.7.1
export PATH="$PWD/bin:$PATH"
export MINIKUBE_ARGS="--vm-driver=none --kubernetes-version=v${KUBE_VERSION}"
export Z2JH_HELM_ARGS="-f minikube-config.yaml"
export DISABLE_TEST_NETPOL=1
30 changes: 30 additions & 0 deletions tests/test_spawn.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import requests
import pytest
import time
Expand Down Expand Up @@ -52,6 +53,35 @@ def test_api_request_user_spawn(api_request, jupyter_user, request_data):
_delete_server(api_request, jupyter_user, API_TIMEOUT)


@pytest.mark.skipif(os.getenv('DISABLE_TEST_NETPOL') == '1',
reason="DISABLE_TEST_NETPOL set")
def test_singleuser_netpol(api_request, jupyter_user, request_data):
print("asking kubespawner to spawn a singleuser-server pod to test network policies")
r = api_request.post('/users/' + jupyter_user + '/server')
assert r.status_code in (201, 202)
try:
server_model = _wait_for_user_to_spawn(api_request, jupyter_user, API_TIMEOUT)
assert server_model
print(server_model)
pod_name = server_model['state']['pod_name']

allowed_url = 'http://www.ebi.ac.uk'
blocked_url = 'http://www.bbc.co.uk'

c = subprocess.run([
'kubectl', '--namespace=jupyterhub-test', 'exec', pod_name, '--',
'wget', '-q', '-t1', '-T5', allowed_url])
assert c.returncode == 0, "Unable to get allowed domain"

c = subprocess.run([
'kubectl', '--namespace=jupyterhub-test', 'exec', pod_name, '--',
'wget', '-q', '-t1', '-T5', blocked_url])
assert c.returncode > 0, "Blocked domain was allowed"

finally:
_delete_server(api_request, jupyter_user, API_TIMEOUT)


def _wait_for_user_to_spawn(api_request, jupyter_user, timeout):
t = 0
while t < timeout:
Expand Down

0 comments on commit f659a7a

Please sign in to comment.