def test_image_whitelist(app, image): name = "checker" add_user(app.db, app, name=name) user = app.users[name] assert isinstance(user.spawner, DockerSpawner) user.spawner.remove_containers = True user.spawner.image_whitelist = { "0.9": "jupyterhub/singleuser:0.9", "0.8": "jupyterhub/singleuser:0.8", } token = user.new_api_token() # start the server r = yield api_request( app, "users", name, "server", method="post", data=json.dumps({"image": image}) ) if image not in user.spawner.image_whitelist: with pytest.raises(Exception): r.raise_for_status() return while r.status_code == 202: # request again r = yield api_request(app, "users", name, "server", method="post") yield gen.sleep(0.1) assert r.status_code == 201, r.text url = url_path_join(public_url(app, user), "api/status") r = yield async_requests.get(url, headers={"Authorization": "token %s" % token}) r.raise_for_status() assert r.headers['x-jupyterhub-version'].startswith(image) r = yield api_request( app, "users", name, "server", method="delete", ) r.raise_for_status()
def test_integration(app, auto_login, logged_in): app.authenticator.auto_login = auto_login # Create a user add_user(app.db, app, name="alice") if auto_login: url = public_url(app, path="/hub/login") resp = yield async_requests.get(url) # Sends back 401 requesting authentication assert resp.status_code == 401 # 401 page is formatted nicely assert "Failed to login with Kerberos." in resp.text assert resp.text.count("/hub/login") >= 2 # Before that was a redirect to the auth handler assert resp.history[0].status_code == 302 # Now use the redirected url with auth enabled location = resp.history[0].headers['location'] netloc = urlparse(app.bind_url).netloc url = 'http://%s%s' % (netloc, location) else: url = public_url(app, path="/hub/kerberos_login") # Go through the login procedure resp = yield async_requests.get( url, auth=HTTPKerberosAuth(hostname_override="address.example.com")) if logged_in: # Successful resp.raise_for_status() # At user notebook, login successful assert resp.url.startswith(public_url(app, path="/user/alice")) else: # Unsuccessful assert resp.status_code == 401
def test_integration(skein_client, app, configure_app): with clean_cluster(skein_client): # Create a user add_user(app.db, app, name="alice") alice = app.users["alice"] assert isinstance(alice.spawner, YarnSpawner) token = alice.new_api_token() # Not started, status should be 0 status = yield alice.spawner.poll() assert status == 0 # Stop can be called before start, no-op yield alice.spawner.stop() # Start the server, and wait for it to start resp = None while resp is None or resp.status_code == 202: yield gen.sleep(2.0) resp = yield api_request(app, "users", "alice", "server", method="post") # Check that everything is running fine url = url_path_join(public_url(app, alice), "api/status") resp = yield async_requests.get( url, headers={'Authorization': 'token %s' % token}) resp.raise_for_status() assert "kernels" in resp.json() # Save the app_id to use later app_id = alice.spawner.app_id # Shutdown the server resp = yield api_request(app, "users", "alice", "server", method="delete") resp.raise_for_status() assert_shutdown_in(skein_client, app_id, timeout=10) # Check status status = yield alice.spawner.poll() assert status == 0
def test_start_stop(app): name = "somebody" add_user(app.db, app, name=name) user = app.users[name] assert isinstance(user.spawner, SwarmSpawner) token = user.new_api_token() # start the server r = yield api_request(app, "users", name, "server", method="post") while r.status_code == 202: # request again r = yield api_request(app, "users", name, "server", method="post") assert r.status_code == 201, r.text url = url_path_join(public_url(app, user), "api/status") r = yield async_requests.get(url, headers={"Authorization": "token %s" % token}) assert r.url == url r.raise_for_status() print(r.text) assert "kernels" in r.json()
def test_start_stop(app): name = getuser() add_user(app.db, app, name=name) user = app.users[name] assert isinstance(user.spawner, SystemUserSpawner) token = user.new_api_token() # start the server r = yield api_request(app, "users", name, "server", method="post") while r.status_code == 202: # request again r = yield api_request(app, "users", name, "server", method="post") assert r.status_code == 201, r.text url = url_path_join(public_url(app, user), "api/status") r = yield async_requests.get(url, headers={"Authorization": "token %s" % token}) assert r.url == url r.raise_for_status() print(r.text) assert "kernels" in r.json()
def test_image_whitelist(app, image): name = "checker" add_user(app.db, app, name=name) user = app.users[name] assert isinstance(user.spawner, DockerSpawner) user.spawner.remove_containers = True user.spawner.image_whitelist = { "0.9": "jupyterhub/singleuser:0.9", "0.8": "jupyterhub/singleuser:0.8", } token = user.new_api_token() # start the server r = yield api_request(app, "users", name, "server", method="post", data=json.dumps({"image": image})) if image not in user.spawner.image_whitelist: with pytest.raises(Exception): r.raise_for_status() return while r.status_code == 202: # request again r = yield api_request(app, "users", name, "server", method="post") yield gen.sleep(0.1) assert r.status_code == 201, r.text url = url_path_join(public_url(app, user), "api/status") r = yield async_requests.get(url, headers={"Authorization": "token %s" % token}) r.raise_for_status() assert r.headers['x-jupyterhub-version'].startswith(image) r = yield api_request( app, "users", name, "server", method="delete", ) r.raise_for_status()