11import  json 
2+ import  os 
23import  subprocess 
34import  time 
45
56import  pytest 
67import  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
913def  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