Skip to content

Commit

Permalink
test image whitelist
Browse files Browse the repository at this point in the history
  • Loading branch information
minrk committed Jun 19, 2018
1 parent 369d99c commit f57ef5b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ install:
- pip freeze
script:
- pyflakes dockerspawner
- docker pull jupyterhub/singleuser:$JUPYTERHUB
- docker pull jupyterhub/singleuser:0.8
- docker pull jupyterhub/singleuser:0.9
- travis_retry py.test --cov dockerspawner tests -v
38 changes: 38 additions & 0 deletions tests/test_dockerspawner.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""Tests for DockerSpawner class"""

import json

import pytest

from jupyterhub.tests.test_api import add_user, api_request
from jupyterhub.tests.mocking import public_url
from jupyterhub.tests.utils import async_requests
Expand Down Expand Up @@ -30,3 +33,38 @@ def test_start_stop(app):
r.raise_for_status()
print(r.text)
assert "kernels" in r.json()


@pytest.mark.gen_test
@pytest.mark.parametrize("image", ["0.8", "0.9", "nomatch"])
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")
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()

0 comments on commit f57ef5b

Please sign in to comment.