diff --git a/jupyterhub/services/auth.py b/jupyterhub/services/auth.py index 4ce9ed84..1020ae31 100644 --- a/jupyterhub/services/auth.py +++ b/jupyterhub/services/auth.py @@ -99,6 +99,11 @@ class _ExpiringDict(dict): except KeyError: return default + def clear(self): + """Clear the cache""" + self.values.clear() + self.timestamps.clear() + class HubAuth(SingletonConfigurable): """A class for authenticating with JupyterHub diff --git a/jupyterhub/tests/test_services_auth.py b/jupyterhub/tests/test_services_auth.py index ce253e05..64326fa2 100644 --- a/jupyterhub/tests/test_services_auth.py +++ b/jupyterhub/tests/test_services_auth.py @@ -170,6 +170,10 @@ def test_hub_authenticated(request): assert r.status_code == 302 assert auth.login_url in r.headers['Location'] + # clear the cache because we are going to request + # the same url again with a different result + auth.cache.clear() + # upstream 403 m.get(bad_url, status_code=403) r = requests.get('http://127.0.0.1:%i' % port,