|
| 1 | +import json |
1 | 2 | import logging
|
2 | 3 | from contextlib import nullcontext
|
| 4 | +from unittest import mock |
3 | 5 |
|
4 | 6 | import pytest
|
5 | 7 |
|
@@ -177,3 +179,33 @@ def test_password_required(identity_provider_class, password_set, password_requi
|
177 | 179 |
|
178 | 180 | with ctx:
|
179 | 181 | idp.validate_security(app, ssl_options=None)
|
| 182 | + |
| 183 | + |
| 184 | +async def test_auth_disabled(request, jp_serverapp, jp_fetch): |
| 185 | + idp = PasswordIdentityProvider( |
| 186 | + parent=jp_serverapp, |
| 187 | + hashed_password="", |
| 188 | + token="", |
| 189 | + ) |
| 190 | + assert not idp.auth_enabled |
| 191 | + |
| 192 | + with mock.patch.dict(jp_serverapp.web_app.settings, {"identity_provider": idp}): |
| 193 | + |
| 194 | + resp = await jp_fetch("/api/me", headers={"Authorization": "", "Cookie": ""}) |
| 195 | + |
| 196 | + user_info = json.loads(resp.body.decode("utf8")) |
| 197 | + # anonymous login sets a cookie |
| 198 | + assert "Set-Cookie" in resp.headers |
| 199 | + cookie = resp.headers["Set-Cookie"] |
| 200 | + |
| 201 | + # second request, with cookie keeps the same anonymous user |
| 202 | + resp = await jp_fetch("/api/me", headers={"Authorization": "", "Cookie": cookie}) |
| 203 | + |
| 204 | + user_info_repeat = json.loads(resp.body.decode("utf8")) |
| 205 | + assert user_info_repeat["identity"] == user_info["identity"] |
| 206 | + |
| 207 | + # another request, no cookie, new anonymous user |
| 208 | + resp = await jp_fetch("/api/me", headers={"Authorization": "", "Cookie": ""}) |
| 209 | + |
| 210 | + user_info_2 = json.loads(resp.body.decode("utf8")) |
| 211 | + assert user_info_2["identity"]["username"] != user_info["identity"]["username"] |
0 commit comments