Skip to content

Commit dcd031a

Browse files
committed
Test subdomain_host
1 parent a0864f1 commit dcd031a

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

.github/workflows/test-chart.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,14 @@ jobs:
137137
--set hub.image.name=quay.io/jupyterhub/k8s-hub-slim
138138
--set prePuller.hook.enabled=true
139139
--set prePuller.hook.pullOnlyOnChanges=true
140-
- k3s-channel: v1.31 # also test hub.existingSecret
140+
- k3s-channel: v1.31 # also test hub.existingSecret and subdomain_host
141141
test: install
142142
local-chart-extra-args: >-
143143
--set hub.existingSecret=test-hub-existing-secret
144144
--set proxy.secretToken=aaaa1111
145145
--set hub.cookieSecret=bbbb2222
146146
--set hub.config.CryptKeeper.keys[0]=cccc3333
147+
--set hub.config.JupyterHub.subdomain_host=jupyterhub.example.org
147148
create-k8s-test-resources: true
148149

149150
# We run three upgrade tests where we first install an already released
@@ -368,6 +369,9 @@ jobs:
368369
continue-on-error: ${{ matrix.accept-failure == true }}
369370
run: |
370371
. ./ci/common
372+
if [ "${{ contains(matrix.local-chart-extra-args, 'subdomain_host') }}" = "true" ]; then
373+
export CI_SUBDOMAIN_HOST=jupyterhub.example.org
374+
fi
371375
# If you have problems with the tests add '--capture=no' to show stdout
372376
pytest --verbose --maxfail=2 --color=yes ./tests
373377

tests/test_spawn.py

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import json
2+
import os
23
import subprocess
34
import time
45

56
import pytest
67
import requests
78

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

913
def test_spawn_basic(
1014
api_request,
@@ -28,12 +32,39 @@ def test_spawn_basic(
2832
api_request, jupyter_user, request_data["test_timeout"]
2933
)
3034
assert server_model
31-
r = requests.get(
32-
request_data["hub_url"].partition("/hub/api")[0]
33-
+ server_model["url"]
34-
+ "api",
35-
verify=pebble_acme_ca_cert,
36-
)
35+
36+
hub_parent_url = request_data["hub_url"].partition("/hub/api")[0]
37+
38+
if CI_SUBDOMAIN_HOST:
39+
# We can't make a proper request since wildcard DNS isn't setup,
40+
# but we can set the Host header to test that CHP correctly forwards
41+
# the request to the singleuser server
42+
assert (
43+
server_model["url"]
44+
== f"https://{jupyter_user}.{CI_SUBDOMAIN_HOST}/user/{jupyter_user}/"
45+
)
46+
47+
# It shouldn't be possible to access the server without the subdomain,
48+
# should instead be redirected to hub
49+
r_incorrect = requests.get(
50+
f"{hub_parent_url}/user/{jupyter_user}/api",
51+
verify=pebble_acme_ca_cert,
52+
allow_redirects=False,
53+
)
54+
assert r_incorrect.status_code == 302
55+
56+
r = requests.get(
57+
f"{hub_parent_url}/user/{jupyter_user}/api",
58+
headers={"Host": f"{jupyter_user}.{CI_SUBDOMAIN_HOST}"},
59+
verify=False,
60+
allow_redirects=False,
61+
)
62+
else:
63+
r = requests.get(
64+
hub_parent_url + server_model["url"] + "api",
65+
verify=pebble_acme_ca_cert,
66+
)
67+
3768
assert r.status_code == 200
3869
assert "version" in r.json()
3970

0 commit comments

Comments
 (0)