mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-17 15:03:02 +00:00
fix filter check in Proxy.check_routes
and test that check_routes works as intended
This commit is contained in:
@@ -199,7 +199,7 @@ class Proxy(Base):
|
|||||||
if not routes:
|
if not routes:
|
||||||
routes = yield self.get_routes()
|
routes = yield self.get_routes()
|
||||||
|
|
||||||
have_routes = { r['user'] for r in routes if 'user' in r }
|
have_routes = { r['user'] for r in routes.values() if 'user' in r }
|
||||||
futures = []
|
futures = []
|
||||||
db = inspect(self).session
|
db = inspect(self).session
|
||||||
for user in db.query(User).filter(User.server != None):
|
for user in db.query(User).filter(User.server != None):
|
||||||
|
@@ -47,7 +47,6 @@ def io_loop():
|
|||||||
@fixture(scope='module')
|
@fixture(scope='module')
|
||||||
def app(request):
|
def app(request):
|
||||||
app = MockHub.instance(log_level=logging.DEBUG)
|
app = MockHub.instance(log_level=logging.DEBUG)
|
||||||
print(app)
|
|
||||||
app.start([])
|
app.start([])
|
||||||
def fin():
|
def fin():
|
||||||
MockHub.clear_instance()
|
MockHub.clear_instance()
|
||||||
|
@@ -4,6 +4,7 @@ import json
|
|||||||
import os
|
import os
|
||||||
from subprocess import Popen
|
from subprocess import Popen
|
||||||
|
|
||||||
|
from .. import orm
|
||||||
from .mocking import MockHub
|
from .mocking import MockHub
|
||||||
from .test_api import api_request
|
from .test_api import api_request
|
||||||
from ..utils import wait_for_http_server
|
from ..utils import wait_for_http_server
|
||||||
@@ -19,7 +20,10 @@ def test_external_proxy(request, io_loop):
|
|||||||
proxy_api_port=proxy_port,
|
proxy_api_port=proxy_port,
|
||||||
proxy_auth_token=auth_token,
|
proxy_auth_token=auth_token,
|
||||||
)
|
)
|
||||||
request.addfinalizer(app.stop)
|
def fin():
|
||||||
|
MockHub.clear_instance()
|
||||||
|
app.stop()
|
||||||
|
request.addfinalizer(fin)
|
||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
env['CONFIGPROXY_AUTH_TOKEN'] = auth_token
|
env['CONFIGPROXY_AUTH_TOKEN'] = auth_token
|
||||||
cmd = [app.proxy_cmd,
|
cmd = [app.proxy_cmd,
|
||||||
@@ -102,3 +106,21 @@ def test_external_proxy(request, io_loop):
|
|||||||
routes = io_loop.run_sync(app.proxy.get_routes)
|
routes = io_loop.run_sync(app.proxy.get_routes)
|
||||||
assert sorted(routes.keys()) == ['/', '/user/river']
|
assert sorted(routes.keys()) == ['/', '/user/river']
|
||||||
|
|
||||||
|
def test_check_routes(app, io_loop):
|
||||||
|
proxy = app.proxy
|
||||||
|
r = api_request(app, 'users/zoe', method='post')
|
||||||
|
r.raise_for_status()
|
||||||
|
r = api_request(app, 'users/zoe/server', method='post')
|
||||||
|
r.raise_for_status()
|
||||||
|
zoe = orm.User.find(app.db, 'zoe')
|
||||||
|
assert zoe is not None
|
||||||
|
before = sorted(io_loop.run_sync(app.proxy.get_routes))
|
||||||
|
assert '/user/zoe' in before
|
||||||
|
io_loop.run_sync(app.proxy.check_routes)
|
||||||
|
io_loop.run_sync(lambda : proxy.delete_user(zoe))
|
||||||
|
during = sorted(io_loop.run_sync(app.proxy.get_routes))
|
||||||
|
assert '/user/zoe' not in during
|
||||||
|
io_loop.run_sync(app.proxy.check_routes)
|
||||||
|
after = sorted(io_loop.run_sync(app.proxy.get_routes))
|
||||||
|
assert '/user/zoe' in after
|
||||||
|
assert before == after
|
||||||
|
Reference in New Issue
Block a user