Skip to content

Commit

Permalink
Test subdomain_host
Browse files Browse the repository at this point in the history
  • Loading branch information
manics committed Oct 23, 2024
1 parent a0864f1 commit dcd031a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/test-chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,14 @@ jobs:
--set hub.image.name=quay.io/jupyterhub/k8s-hub-slim
--set prePuller.hook.enabled=true
--set prePuller.hook.pullOnlyOnChanges=true
- k3s-channel: v1.31 # also test hub.existingSecret
- k3s-channel: v1.31 # also test hub.existingSecret and subdomain_host
test: install
local-chart-extra-args: >-
--set hub.existingSecret=test-hub-existing-secret
--set proxy.secretToken=aaaa1111
--set hub.cookieSecret=bbbb2222
--set hub.config.CryptKeeper.keys[0]=cccc3333
--set hub.config.JupyterHub.subdomain_host=jupyterhub.example.org
create-k8s-test-resources: true

# We run three upgrade tests where we first install an already released
Expand Down Expand Up @@ -368,6 +369,9 @@ jobs:
continue-on-error: ${{ matrix.accept-failure == true }}
run: |
. ./ci/common
if [ "${{ contains(matrix.local-chart-extra-args, 'subdomain_host') }}" = "true" ]; then
export CI_SUBDOMAIN_HOST=jupyterhub.example.org
fi
# If you have problems with the tests add '--capture=no' to show stdout
pytest --verbose --maxfail=2 --color=yes ./tests
Expand Down
43 changes: 37 additions & 6 deletions tests/test_spawn.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import json
import os
import subprocess
import time

import pytest
import requests

# If we're testing subdomain hosts in GitHub CI our workflow will set this
CI_SUBDOMAIN_HOST = os.getenv("CI_SUBDOMAIN_HOST")


def test_spawn_basic(
api_request,
Expand All @@ -28,12 +32,39 @@ def test_spawn_basic(
api_request, jupyter_user, request_data["test_timeout"]
)
assert server_model
r = requests.get(
request_data["hub_url"].partition("/hub/api")[0]
+ server_model["url"]
+ "api",
verify=pebble_acme_ca_cert,
)

hub_parent_url = request_data["hub_url"].partition("/hub/api")[0]

if CI_SUBDOMAIN_HOST:
# We can't make a proper request since wildcard DNS isn't setup,
# but we can set the Host header to test that CHP correctly forwards
# the request to the singleuser server
assert (
server_model["url"]
== f"https://{jupyter_user}.{CI_SUBDOMAIN_HOST}/user/{jupyter_user}/"
)

# It shouldn't be possible to access the server without the subdomain,
# should instead be redirected to hub
r_incorrect = requests.get(
f"{hub_parent_url}/user/{jupyter_user}/api",
verify=pebble_acme_ca_cert,
allow_redirects=False,
)
assert r_incorrect.status_code == 302

r = requests.get(
f"{hub_parent_url}/user/{jupyter_user}/api",
headers={"Host": f"{jupyter_user}.{CI_SUBDOMAIN_HOST}"},
verify=False,
allow_redirects=False,
)
else:
r = requests.get(
hub_parent_url + server_model["url"] + "api",
verify=pebble_acme_ca_cert,
)

assert r.status_code == 200
assert "version" in r.json()

Expand Down

0 comments on commit dcd031a

Please sign in to comment.