Skip to content

Commit

Permalink
maint: adjust test against jupyterhub to pass _xsrf token
Browse files Browse the repository at this point in the history
  • Loading branch information
consideRatio committed Jun 4, 2023
1 parent a9b6812 commit 76510b0
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions binderhub/tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,22 @@ async def test_auth(app, path, authenticated, use_session):
# not authenticated, we should get the page and be done
assert r.url == url
return
assert "/hub/login" in urlparse(r.url).path

# acquire a _xsrf cookie to pass in the post request we are about to make
login_url = f"{app.hub_url}/hub/login"
r2 = await async_requests.get(login_url)
assert r2.status_code == 200, f"{r2.status_code} {r2.url}"
_xsrf_cookie = r2.cookies.get("_xsrf", path="/hub/")
assert _xsrf_cookie

# submit login form
assert "/hub/login" in urlparse(r.url).path
r2 = await async_requests.post(
r.url, data={"username": "dummy", "password": "dummy"}
r3 = await async_requests.post(
r.url, data={"username": "dummy", "password": "dummy", "_xsrf": _xsrf_cookie}
)
assert r2.status_code == 200, f"{r2.status_code} {r.url}"
assert r3.status_code == 200, f"{r3.status_code} {r3.url}"
# verify that we landed at the destination after auth
assert r2.url == url
assert r3.url == url


@skip_remote
Expand Down

0 comments on commit 76510b0

Please sign in to comment.