Skip to content

Commit c54001a

Browse files
committed
fix: GitHub token must be base64 encoded
1 parent 9cc0cb7 commit c54001a

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

conda_forge_tick/git_utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Utilities for managing github repos"""
22

3+
import base64
34
import copy
45
import enum
56
import logging
@@ -311,7 +312,7 @@ def add_token(self, git_dir: Path, origin: str, token: str):
311312
"""
312313
Configures git with a local configuration to use the given token for the given origin.
313314
Internally, this sets the `http.<origin>/.extraheader` git configuration key to
314-
`AUTHORIZATION: basic <token>`.
315+
`AUTHORIZATION: basic <base64-encoded HTTP basic token>`.
315316
This is similar to how the GitHub Checkout action does it:
316317
https://github.com/actions/checkout/blob/eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871/adrs/0153-checkout-v2.md#PAT
317318
@@ -320,12 +321,14 @@ def add_token(self, git_dir: Path, origin: str, token: str):
320321
:param origin: The origin to use the token for. Origin is SCHEME://HOST[:PORT] (without trailing slash).
321322
:param token: The token to use.
322323
"""
324+
http_basic_token = base64.b64encode(f"x-access-token:{token}".encode()).decode()
325+
323326
self._run_git_command(
324327
[
325328
"config",
326329
"--local",
327330
f"http.{origin}/.extraheader",
328-
f"AUTHORIZATION: basic {token}",
331+
f"AUTHORIZATION: basic {http_basic_token}",
329332
],
330333
git_dir,
331334
suppress_all_output=True,

tests/test_git_utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import base64
12
import datetime
23
import json
34
import logging
@@ -549,12 +550,14 @@ def test_git_cli_add_token_mock(run_git_command_mock: MagicMock):
549550

550551
cli.add_token(git_dir, origin, token)
551552

553+
http_basic_token = base64.b64encode(f"x-access-token:{token}".encode()).decode()
554+
552555
run_git_command_mock.assert_called_once_with(
553556
[
554557
"config",
555558
"--local",
556559
"http.https://git-repository.com/.extraheader",
557-
"AUTHORIZATION: basic TOKEN",
560+
f"AUTHORIZATION: basic {http_basic_token}",
558561
],
559562
git_dir,
560563
suppress_all_output=True,

0 commit comments

Comments
 (0)