Skip to content

Commit 322e81b

Browse files
committed
fix: cast gh_app_id to string for JWT encoding compatibility
Relates to github-community-projects/evergreen#508 ## What Cast gh_app_id to str() when passing it to login_as_app_installation, which internally calls jwt.encode expecting the iss claim to be a string. Updated tests to pass integer app IDs and assert the string conversion occurs. ## Why Since v2.0.0, GitHub App authentication fails with "TypeError: Issuer (iss) must be a string" because newer versions of PyJWT enforce that the iss claim is a string, but gh_app_id was being passed as an integer. ## Notes - Tests now use assert_called_once_with instead of assert_called_once to verify the exact arguments, preventing this class of regression - Test inputs changed from strings to integers to mirror real-world usage where env vars are parsed as ints Signed-off-by: jmeridth <jmeridth@gmail.com>
1 parent e26b4f3 commit 322e81b

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def auth_to_github(
3333
else:
3434
gh = github3.github.GitHub()
3535
gh.login_as_app_installation(
36-
gh_app_private_key_bytes, gh_app_id, gh_app_installation_id
36+
gh_app_private_key_bytes, str(gh_app_id), gh_app_installation_id
3737
)
3838
github_connection = gh
3939
elif ghe and token:

test_auth.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def test_auth_to_github_with_github_app(self, mock_login):
2828
mock_login.return_value = MagicMock()
2929
result = auth_to_github("", 12345, 678910, b"hello", "", False)
3030

31+
mock_login.assert_called_once_with(b"hello", "12345", 678910)
3132
self.assertIsInstance(result, github3.github.GitHub, False)
3233

3334
def test_auth_to_github_with_token(self):
@@ -65,9 +66,9 @@ def test_auth_to_github_with_ghe_and_ghe_app(self, mock_ghe):
6566
mock = mock_ghe.return_value
6667
mock.login_as_app_installation = MagicMock(return_value=True)
6768
result = auth_to_github(
68-
"", "123", "123", b"123", "https://github.example.com", True
69+
"", 123, 456, b"123", "https://github.example.com", True
6970
)
70-
mock.login_as_app_installation.assert_called_once()
71+
mock.login_as_app_installation.assert_called_once_with(b"123", "123", 456)
7172
self.assertEqual(result, mock)
7273

7374
@patch("github3.apps.create_jwt_headers", MagicMock(return_value="gh_token"))

0 commit comments

Comments
 (0)