From 6a897fd1c9a34d27571a94a15bf78665c7e3904e Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sun, 13 Sep 2026 00:57:26 +0000 Subject: [PATCH] feat: send Authorization Bearer for HTTP API requests AuthenticatedClient already defaults to Bearer. Stop overriding that with the deprecated access-token header. Co-authored-by: Fang-Pen Lin --- beanhub_cli/http_client.py | 2 -- tests/connect/test_dump.py | 6 +++--- tests/connect/test_sync.py | 38 +++++++++++++++++++------------------- tests/inbox/test_dump.py | 14 +++++++------- tests/test_git_repo.py | 4 ++-- tests/test_http_client.py | 2 +- 6 files changed, 32 insertions(+), 34 deletions(-) diff --git a/beanhub_cli/http_client.py b/beanhub_cli/http_client.py index c034391..deea1a0 100644 --- a/beanhub_cli/http_client.py +++ b/beanhub_cli/http_client.py @@ -32,8 +32,6 @@ def make_client(base_url: str) -> Client: def make_auth_client(base_url: str, token: str) -> AuthenticatedClient: return AuthenticatedClient( base_url=base_url, - prefix="", - auth_header_name="access-token", token=token, headers=get_client_headers(), ) diff --git a/tests/connect/test_dump.py b/tests/connect/test_dump.py index 9826b9b..1a09a70 100644 --- a/tests/connect/test_dump.py +++ b/tests/connect/test_dump.py @@ -60,7 +60,7 @@ def test_dump( public_key=public_key, output_accounts=output_accounts, ), - match_headers={"access-token": mock_config.access_token.token}, + match_headers={"Authorization": f"Bearer {mock_config.access_token.token}"}, ) httpx_mock.add_response( url=f"https://api.beanhub.io/v1/repos/{mock_config.repo.default}/connect/dumps/{dump_id}", @@ -70,7 +70,7 @@ def test_dump( id=str(dump_id), state="PROCESSING", ), - match_headers={"access-token": mock_config.access_token.token}, + match_headers={"Authorization": f"Bearer {mock_config.access_token.token}"}, ) httpx_mock.add_response( url=f"https://api.beanhub.io/v1/repos/{mock_config.repo.default}/connect/dumps/{dump_id}", @@ -87,7 +87,7 @@ def test_dump( else {} ), ), - match_headers={"access-token": mock_config.access_token.token}, + match_headers={"Authorization": f"Bearer {mock_config.access_token.token}"}, ) httpx_mock.add_response( url=mock_download_url, diff --git a/tests/connect/test_sync.py b/tests/connect/test_sync.py index a66f7de..a921248 100644 --- a/tests/connect/test_sync.py +++ b/tests/connect/test_sync.py @@ -59,7 +59,7 @@ def _mock_list_repo( ) ] ), - match_headers={"access-token": mock_config.access_token.token}, + match_headers={"Authorization": f"Bearer {mock_config.access_token.token}"}, ) @@ -76,7 +76,7 @@ def test_sync( json=dict( id=str(batch_id), ), - match_headers={"access-token": mock_config.access_token.token}, + match_headers={"Authorization": f"Bearer {mock_config.access_token.token}"}, ) httpx_mock.add_response( url=f"https://api.beanhub.io/v1/repos/{mock_config.repo.default}/connect/sync_batches/{batch_id}", @@ -103,7 +103,7 @@ def test_sync( ), ], ), - match_headers={"access-token": mock_config.access_token.token}, + match_headers={"Authorization": f"Bearer {mock_config.access_token.token}"}, ) httpx_mock.add_response( url=f"https://api.beanhub.io/v1/repos/{mock_config.repo.default}/connect/sync_batches/{batch_id}", @@ -132,7 +132,7 @@ def test_sync( ), ], ), - match_headers={"access-token": mock_config.access_token.token}, + match_headers={"Authorization": f"Bearer {mock_config.access_token.token}"}, ) cli_runner.mix_stderr = False result = cli_runner.invoke(cli, ["connect", "sync"]) @@ -153,7 +153,7 @@ def test_sync_shows_sync_complete_items( method="POST", status_code=201, json=dict(id=str(batch_id)), - match_headers={"access-token": mock_config.access_token.token}, + match_headers={"Authorization": f"Bearer {mock_config.access_token.token}"}, ) httpx_mock.add_response( url=f"https://api.beanhub.io/v1/repos/{mock_config.repo.default}/connect/sync_batches/{batch_id}", @@ -182,7 +182,7 @@ def test_sync_shows_sync_complete_items( ), ], ), - match_headers={"access-token": mock_config.access_token.token}, + match_headers={"Authorization": f"Bearer {mock_config.access_token.token}"}, ) cli_runner.mix_stderr = False result = cli_runner.invoke(cli, ["connect", "sync"]) @@ -210,7 +210,7 @@ def test_sync_sends_cli_version_header( status_code=201, json=dict(id=str(batch_id)), match_headers={ - "access-token": mock_config.access_token.token, + "Authorization": f"Bearer {mock_config.access_token.token}", CLIENT_VERSION_HEADER: cli_version, }, ) @@ -234,7 +234,7 @@ def test_sync_sends_cli_version_header( ], ), match_headers={ - "access-token": mock_config.access_token.token, + "Authorization": f"Bearer {mock_config.access_token.token}", CLIENT_VERSION_HEADER: cli_version, }, ) @@ -256,7 +256,7 @@ def test_sync_with_skipped_state( json=dict( id=str(batch_id), ), - match_headers={"access-token": mock_config.access_token.token}, + match_headers={"Authorization": f"Bearer {mock_config.access_token.token}"}, ) httpx_mock.add_response( url=f"https://api.beanhub.io/v1/repos/{mock_config.repo.default}/connect/sync_batches/{batch_id}", @@ -283,7 +283,7 @@ def test_sync_with_skipped_state( ), ], ), - match_headers={"access-token": mock_config.access_token.token}, + match_headers={"Authorization": f"Bearer {mock_config.access_token.token}"}, ) httpx_mock.add_response( url=f"https://api.beanhub.io/v1/repos/{mock_config.repo.default}/connect/sync_batches/{batch_id}", @@ -313,7 +313,7 @@ def test_sync_with_skipped_state( ), ], ), - match_headers={"access-token": mock_config.access_token.token}, + match_headers={"Authorization": f"Bearer {mock_config.access_token.token}"}, ) cli_runner.mix_stderr = False result = cli_runner.invoke(cli, ["connect", "sync"]) @@ -335,7 +335,7 @@ def test_sync_with_import_and_commit( json=dict( id=str(batch_id), ), - match_headers={"access-token": mock_config.access_token.token}, + match_headers={"Authorization": f"Bearer {mock_config.access_token.token}"}, match_json={"import_and_commit": True}, ) httpx_mock.add_response( @@ -357,7 +357,7 @@ def test_sync_with_import_and_commit( ), ], ), - match_headers={"access-token": mock_config.access_token.token}, + match_headers={"Authorization": f"Bearer {mock_config.access_token.token}"}, ) httpx_mock.add_response( url=f"https://api.beanhub.io/v1/repos/{mock_config.repo.default}/connect/sync_batches/{batch_id}", @@ -378,7 +378,7 @@ def test_sync_with_import_and_commit( ), ], ), - match_headers={"access-token": mock_config.access_token.token}, + match_headers={"Authorization": f"Bearer {mock_config.access_token.token}"}, ) httpx_mock.add_response( url=f"https://api.beanhub.io/v1/repos/{mock_config.repo.default}/connect/sync_batches/{batch_id}", @@ -400,7 +400,7 @@ def test_sync_with_import_and_commit( ), ], ), - match_headers={"access-token": mock_config.access_token.token}, + match_headers={"Authorization": f"Bearer {mock_config.access_token.token}"}, ) cli_runner.mix_stderr = False result = cli_runner.invoke(cli, ["connect", "sync", "-i"]) @@ -423,7 +423,7 @@ def test_sync_with_import_and_commit_failed( json=dict( id=str(batch_id), ), - match_headers={"access-token": mock_config.access_token.token}, + match_headers={"Authorization": f"Bearer {mock_config.access_token.token}"}, match_json={"import_and_commit": True}, ) httpx_mock.add_response( @@ -463,7 +463,7 @@ def test_sync_with_import_and_commit_failed( ), ], ), - match_headers={"access-token": mock_config.access_token.token}, + match_headers={"Authorization": f"Bearer {mock_config.access_token.token}"}, ) cli_runner.mix_stderr = False result = cli_runner.invoke(cli, ["connect", "sync", "-i"]) @@ -496,7 +496,7 @@ def test_sync_with_import_and_commit_rejected_by_api( method="GET", status_code=200, json=dict(repositories=[]), - match_headers={"access-token": mock_config.access_token.token}, + match_headers={"Authorization": f"Bearer {mock_config.access_token.token}"}, ) httpx_mock.add_response( url=f"https://api.beanhub.io/v1/repos/{mock_config.repo.default}/connect/sync_batches", @@ -509,7 +509,7 @@ def test_sync_with_import_and_commit_rejected_by_api( "exporting data." ), ), - match_headers={"access-token": mock_config.access_token.token}, + match_headers={"Authorization": f"Bearer {mock_config.access_token.token}"}, match_json={"import_and_commit": True}, ) cli_runner.mix_stderr = False diff --git a/tests/inbox/test_dump.py b/tests/inbox/test_dump.py index d80fc46..db8c401 100644 --- a/tests/inbox/test_dump.py +++ b/tests/inbox/test_dump.py @@ -152,7 +152,7 @@ def test_dump( ], cursor="MOCK_CURSOR0", ), - match_headers={"access-token": mock_config.access_token.token}, + match_headers={"Authorization": f"Bearer {mock_config.access_token.token}"}, ) httpx_mock.add_response( url=f"https://api.beanhub.io/v1/repos/{mock_config.repo.default}/inbox/emails?cursor=MOCK_CURSOR0", @@ -164,7 +164,7 @@ def test_dump( ], cursor="MOCK_CURSOR1", ), - match_headers={"access-token": mock_config.access_token.token}, + match_headers={"Authorization": f"Bearer {mock_config.access_token.token}"}, ) httpx_mock.add_response( url=f"https://api.beanhub.io/v1/repos/{mock_config.repo.default}/inbox/emails?cursor=MOCK_CURSOR1", @@ -173,7 +173,7 @@ def test_dump( json=dict( emails=[], ), - match_headers={"access-token": mock_config.access_token.token}, + match_headers={"Authorization": f"Bearer {mock_config.access_token.token}"}, ) httpx_mock.add_response( url=f"https://api.beanhub.io/v1/repos/{mock_config.repo.default}/inbox/dumps", @@ -191,7 +191,7 @@ def test_dump( emails[4].id, ], ), - match_headers={"access-token": mock_config.access_token.token}, + match_headers={"Authorization": f"Bearer {mock_config.access_token.token}"}, ) httpx_mock.add_response( url=f"https://api.beanhub.io/v1/repos/{mock_config.repo.default}/inbox/dumps/{dump_id}", @@ -201,7 +201,7 @@ def test_dump( id=str(dump_id), state="PROCESSING", ), - match_headers={"access-token": mock_config.access_token.token}, + match_headers={"Authorization": f"Bearer {mock_config.access_token.token}"}, ) httpx_mock.add_response( url=f"https://api.beanhub.io/v1/repos/{mock_config.repo.default}/inbox/dumps/{dump_id}", @@ -213,7 +213,7 @@ def test_dump( download_url=mock_download_url, encryption_key=encryption_key, ), - match_headers={"access-token": mock_config.access_token.token}, + match_headers={"Authorization": f"Bearer {mock_config.access_token.token}"}, ) httpx_mock.add_response( url=mock_download_url, @@ -251,7 +251,7 @@ def test_dump_without_emails( json=dict( emails=[], ), - match_headers={"access-token": mock_config.access_token.token}, + match_headers={"Authorization": f"Bearer {mock_config.access_token.token}"}, ) cli_runner.mix_stderr = False diff --git a/tests/test_git_repo.py b/tests/test_git_repo.py index 48f991a..f75951f 100644 --- a/tests/test_git_repo.py +++ b/tests/test_git_repo.py @@ -150,7 +150,7 @@ def test_ensure_auth_config_uses_git_remote_when_active( ) ] ), - match_headers={"access-token": "test-token"}, + match_headers={"Authorization": "Bearer test-token"}, ) with switch_cwd(repo_root): @@ -187,7 +187,7 @@ def test_ensure_auth_config_falls_back_to_single_active_repo( ) ] ), - match_headers={"access-token": "test-token"}, + match_headers={"Authorization": "Bearer test-token"}, ) with switch_cwd(repo_root): diff --git a/tests/test_http_client.py b/tests/test_http_client.py index 014fec9..9742c9c 100644 --- a/tests/test_http_client.py +++ b/tests/test_http_client.py @@ -30,7 +30,7 @@ def test_make_auth_client_includes_version_headers(): client = make_auth_client(base_url="https://api.beanhub.io", token="test-token") with client: httpx_client = client.get_httpx_client() - assert httpx_client.headers["access-token"] == "test-token" + assert httpx_client.headers["Authorization"] == "Bearer test-token" assert httpx_client.headers["User-Agent"] == get_client_headers()["User-Agent"] assert ( httpx_client.headers[CLIENT_VERSION_HEADER]