1
1
import json
2
+ import os
2
3
import subprocess
3
4
import time
4
5
5
6
import pytest
6
7
import requests
7
8
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
+
8
12
9
13
def test_spawn_basic (
10
14
api_request ,
@@ -28,12 +32,39 @@ def test_spawn_basic(
28
32
api_request , jupyter_user , request_data ["test_timeout" ]
29
33
)
30
34
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
+
37
68
assert r .status_code == 200
38
69
assert "version" in r .json ()
39
70
0 commit comments