# How to skip OAuth login when running E2E tests with an admin token in Jupyterhub 4.0

**URL:** <https://discourse.jupyter.org/t/how-to-skip-oauth-login-when-running-e2e-tests-with-an-admin-token-in-jupyterhub-4-0/23726>\
**Category:** JupyterHub\
**Tags:** jupyterhub, how-to, help-wanted\
**Created:** [February 1, 2024, 3:22pm UTC](https://discourse.jupyter.org/t/how-to-skip-oauth-login-when-running-e2e-tests-with-an-admin-token-in-jupyterhub-4-0/23726 "2024-02-01T15:22:18Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![HCharlie](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/hcharlie/32/12285_2.png) [@HCharlie](https://discourse.jupyter.org/u/HCharlie)\
**Post date:** [February 1, 2024, 3:22pm UTC](https://discourse.jupyter.org/t/how-to-skip-oauth-login-when-running-e2e-tests-with-an-admin-token-in-jupyterhub-4-0/23726/1 "2024-02-01T15:22:18Z")

</div>

Hi,

I want to know if is there a way to skip OAuth login when running E2E tests(puppeteer program) with an admin token in Jupyterhub 4.0.

Previously we had these E2E tests working before an upgrade, recently we have had an upgrade of Jupyterhub from version 1.4 to 4.0, and these E2E tests are no longer working.

We find in the old jupyterhub version that `https://<hub_url>/user/<user>/tree?token=<admin_token>` in the incognito browser will all show the files. However, in the new version, we could only see empty pages like below, and click on any button will lead us to the Github OAuth page in the first reply.

 ![Screenshot 2024-02-01 at 16.10.03](https://canada1.discourse-cdn.com/flex031/uploads/jupyter/original/2X/4/400d88232d5288c52835de6313a627c341e0d69a.png)

the \<admin\_token\> above mentioned at the end of the url was generated from an admin via the hub\_url/hub/token page. Also the token works well with both hub rest api(hub\_url/hub/api) and notebook rest api(hub\_url/user//api).

Is this change expected from 1.4 to 4.0, is there some way we could fix this behavior? and in case you need more information, please let me know.

---

<div class="post-metadata">

**Author:** ![HCharlie](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/hcharlie/32/12285_2.png) [@HCharlie](https://discourse.jupyter.org/u/HCharlie)\
**Post date:** [February 1, 2024, 3:23pm UTC](https://discourse.jupyter.org/t/how-to-skip-oauth-login-when-running-e2e-tests-with-an-admin-token-in-jupyterhub-4-0/23726/2 "2024-02-01T15:23:26Z")

</div>

new user is only allowed to give one media in a post, so I put the second here.

 ![Screenshot 2024-02-01 at 16.17.03](https://canada1.discourse-cdn.com/flex031/uploads/jupyter/original/2X/9/9a18bc3753187f0b60cc60c90607f8a3dde0ac5e.png)

---

<div class="post-metadata">

**Author:** ![manics](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/manics/32/85_2.png) [@manics](https://discourse.jupyter.org/u/manics)\
**Post date:** [February 1, 2024, 7:42pm UTC](https://discourse.jupyter.org/t/how-to-skip-oauth-login-when-running-e2e-tests-with-an-admin-token-in-jupyterhub-4-0/23726/3 "2024-02-01T19:42:27Z")

</div>

That was removed a long time ago, in v2!

> <https://github.com/jupyterhub/jupyterhub/pull/3686>
>
> do not allow token-based access to pages
> 
> Tokens are only accepted via Authori…zation header (not in the url via \`?token=...\` like the single-user server), which doesn't make sense to pass to pages, so disallow it explicitly to avoid surprises.

There are also several other security related improvements related to cookies and tokens in subsequent PRs.

How are you running your E2E tests? We use Playwright to test JupyterHub:

> <https://github.com/jupyterhub/jupyterhub/blob/77e90051fd59d1016f141631acdc3cc14b2d3ecb/jupyterhub/tests/browser/test_browser.py#L20-L40>

---

<div class="post-metadata">

**Author:** ![HCharlie](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/hcharlie/32/12285_2.png) [@HCharlie](https://discourse.jupyter.org/u/HCharlie)\
**Post date:** [February 2, 2024, 12:41pm UTC](https://discourse.jupyter.org/t/how-to-skip-oauth-login-when-running-e2e-tests-with-an-admin-token-in-jupyterhub-4-0/23726/4 "2024-02-02T12:41:23Z")

</div>

> [@manics](#):
>
> How are you running your E2E tests? We use Playwright to test JupyterHub:
> 
> [jupyterhub/jupyterhub/tests/browser/test\_browser.py at 77e90051fd59d1016f141631acdc3cc14b2d3ecb · jupyterhub/jupyterhub · GitHub](https://github.com/jupyterhub/jupyterhub/blob/77e90051fd59d1016f141631acdc3cc14b2d3ecb/jupyterhub/tests/browser/test_browser.py#L20-L40)

Hey,

thanks for the fast reply, we run E2E tests not partiicular for the jupyterhub, but mainly on a notebook extension we add to the server. We are using the puppeteer framework and above mentioned trick to login to the server page, then click through all the UI buttons provided by the extnesion. Eventually verify the results.

Currently, after upgrading the jupyterhub, the E2E tests stuck at the very beginning,  
do you see if there is a way to fix this authentication/authorization process?

---

<div class="post-metadata">

**Author:** ![manics](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/manics/32/85_2.png) [@manics](https://discourse.jupyter.org/u/manics)\
**Post date:** [February 5, 2024, 2:40pm UTC](https://discourse.jupyter.org/t/how-to-skip-oauth-login-when-running-e2e-tests-with-an-admin-token-in-jupyterhub-4-0/23726/5 "2024-02-05T14:40:20Z")

</div>

I’ve just realised this is a known bug. It’s been fixed in the main branch

- [singleuser extension: persist token from ?token=... url in cookie by minrk · Pull Request #4560 · jupyterhub/jupyterhub · GitHub](https://github.com/jupyterhub/jupyterhub/pull/4560)  
If you’ve got a test system and you want to verify this fixes the problem install JupyterHub from [GitHub - jupyterhub/jupyterhub: Multi-user server for Jupyter notebooks](https://github.com/jupyterhub/jupyterhub/tree/main/)

This is being backported to JupyterHub 4:

- [Backport PR #4560 on branch 4.x (singleuser extension: persist token from ?token=... url in cookie) by meeseeksmachine · Pull Request #4687 · jupyterhub/jupyterhub · GitHub](https://github.com/jupyterhub/jupyterhub/pull/4687)

---

<div class="post-metadata">

**Author:** ![minrk](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/minrk/32/13_2.png) [@minrk](https://discourse.jupyter.org/u/minrk)\
**Post date:** [February 6, 2024, 7:27am UTC](https://discourse.jupyter.org/t/how-to-skip-oauth-login-when-running-e2e-tests-with-an-admin-token-in-jupyterhub-4-0/23726/6 "2024-02-06T07:27:04Z")

</div>

and the way to work around the bug in the meantime is to set `JUPYTERHUB_SINGLEUSER_EXTENSION=0` to use the older singleuser server integration.

```python
c.Spawner.environment = {"JUPYTERHUB_SINGLEUSER_EXTENSION": "0"}

```

---

<div class="post-metadata">

**Author:** ![HCharlie](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/hcharlie/32/12285_2.png) [@HCharlie](https://discourse.jupyter.org/u/HCharlie)\
**Post date:** [February 7, 2024, 2:40pm UTC](https://discourse.jupyter.org/t/how-to-skip-oauth-login-when-running-e2e-tests-with-an-admin-token-in-jupyterhub-4-0/23726/7 "2024-02-07T14:40:07Z")

</div>

thank you both for the reply, I’ve tried to install the jupyterhub from the main branch(version 5), and it works, but when I try to reinstall the jupyterhub 4(since backported completed ), I see a Database related error. And the jupyterhub is installed in a k8s environment

```auto
FAILED: Can't locate revision identified by '3c2384c5aae1'
[E 2024-02-07 15:30:05.654 JupyterHub app:3382]
    Traceback (most recent call last):
      File "/opt/conda/lib/python3.9/site-packages/jupyterhub/app.py", line 3379, in launch_instance_async
        await self.initialize(argv)
      File "/opt/conda/lib/python3.9/site-packages/jupyterhub/app.py", line 2901, in initialize
        self.init_db()
      File "/opt/conda/lib/python3.9/site-packages/jupyterhub/app.py", line 1835, in init_db
        dbutil.upgrade_if_needed(self.db_url, log=self.log)
      File "/opt/conda/lib/python3.9/site-packages/jupyterhub/dbutil.py", line 135, in upgrade_if_needed
        upgrade(db_url)
      File "/opt/conda/lib/python3.9/site-packages/jupyterhub/dbutil.py", line 84, in upgrade
        check_call(['alembic', '-c', alembic_ini, 'upgrade', revision])
      File "/opt/conda/lib/python3.9/subprocess.py", line 373, in check_call
        raise CalledProcessError(retcode, cmd)
    subprocess.CalledProcessError: Command '['alembic', '-c', '/tmp/tmpsxonbkwg/alembic.ini', 'upgrade', 'head']' returned non-zero exit status 255.

```

I also see the alembic version in the database, is there a graceful way to fix this without deleting the entire database?

```auto
hub=# select * from alembic_version
hub-# ;
 version_num
--------------
 3c2384c5aae1
(1 row)

```

I also tried to fix the token in url issue via the environment variable way.  
`c.Spawner.environment = {"JUPYTERHUB_SINGLEUSER_EXTENSION": "0"}`  
however, this doesn’t work yet on my side, maybe I missed something.

---

<div class="post-metadata">

**Author:** ![manics](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/manics/32/85_2.png) [@manics](https://discourse.jupyter.org/u/manics)\
**Post date:** [February 7, 2024, 4:57pm UTC](https://discourse.jupyter.org/t/how-to-skip-oauth-login-when-running-e2e-tests-with-an-admin-token-in-jupyterhub-4-0/23726/8 "2024-02-07T16:57:54Z")

</div>

> [@HCharlie](#):
>
> I also see the alembic version in the database, is there a graceful way to fix this without deleting the entire database?

Sorry for not highlighting this, it’s why I mentioned a test system! If I remember correctly there should be a backup of the SQLite database file in the same K8s volume.

---

<div class="post-metadata">

**Author:** ![HCharlie](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/hcharlie/32/12285_2.png) [@HCharlie](https://discourse.jupyter.org/u/HCharlie)\
**Post date:** [February 7, 2024, 6:46pm UTC](https://discourse.jupyter.org/t/how-to-skip-oauth-login-when-running-e2e-tests-with-an-admin-token-in-jupyterhub-4-0/23726/9 "2024-02-07T18:46:24Z")

</div>

> [@manics](#):
>
> Sorry for not highlighting this, it’s why I mentioned a test system! If I remember correctly there should be a backup of the SQLite database file in the same K8s volume.

Thanks for the fast reply, I am using a test system so there’s not much to worry, just a bit curious about how to fix it elegantly. I will try to have a look at this SQLite database, if not I will create a new one. : )

---

<div class="post-metadata">

**Author:** ![HCharlie](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/hcharlie/32/12285_2.png) [@HCharlie](https://discourse.jupyter.org/u/HCharlie)\
**Post date:** [February 7, 2024, 8:24pm UTC](https://discourse.jupyter.org/t/how-to-skip-oauth-login-when-running-e2e-tests-with-an-admin-token-in-jupyterhub-4-0/23726/10 "2024-02-07T20:24:42Z")

</div>

Another issue I noticed that after installing the jupyterhub 4.1.0.dev via command

```auto
pip install https://github.com/jupyterhub/jupyterhub/archive/df7ae422f6db2dc0f57d26bec2be1faaa83911ef.zip

```

the admin page becomes empty like screenshot below, is this expected? I fixed the previously mentioned database issue, all data are persisted in the database and deployed version 4.0.2. the Admin’s page seems to work again. Is there something wrong with this Admin page in the new version?

![Screenshot 2024-02-07 at 21.18.00](https://canada1.discourse-cdn.com/flex031/uploads/jupyter/original/2X/4/4cfd266b8c8bdb1320d55b91fadf578edba33ed3.png)  
and the admin-react.js seems missing

 ![Screenshot 2024-02-08 at 09.37.39](https://canada1.discourse-cdn.com/flex031/uploads/jupyter/original/2X/d/d57d22ded03df6e54a72e528acd51734e2223f9b.png)

---

<div class="post-metadata">

**Author:** ![HCharlie](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/hcharlie/32/12285_2.png) [@HCharlie](https://discourse.jupyter.org/u/HCharlie)\
**Post date:** [February 9, 2024, 12:47pm UTC](https://discourse.jupyter.org/t/how-to-skip-oauth-login-when-running-e2e-tests-with-an-admin-token-in-jupyterhub-4-0/23726/11 "2024-02-09T12:47:07Z")

</div>

I see, I think I figured it out, I need to build the package to get data files ready, inspired by the [Dockerfile](https://github.com/jupyterhub/jupyterhub/blob/2c932997643c631f3a7874ab39ee51f6e040622d/Dockerfile)

---

<div class="post-metadata">

**Author:** ![manics](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/manics/32/85_2.png) [@manics](https://discourse.jupyter.org/u/manics)\
**Post date:** [February 9, 2024, 2:51pm UTC](https://discourse.jupyter.org/t/how-to-skip-oauth-login-when-running-e2e-tests-with-an-admin-token-in-jupyterhub-4-0/23726/12 "2024-02-09T14:51:01Z")

</div>

Can you try

```auto
pip install git+https://github.com/jupyterhub/jupyterhub.git@df7ae422f6db2dc0f57d26bec2be1faaa83911ef

```

so the git metadata is included?
