Skip to content

Commit 2f73601

Browse files
authored
fix: convert app_id to string before login_as_app_installation call (#340)
Fixes #333 ## What Wrapped `gh_app_id` with `str()` in the `login_as_app_installation` call in auth.py, and added a targeted test for integer app_id inputs. Existing tests were also tightened to assert on exact call arguments. ## Why When `gh_app_id` is passed as an integer, PyJWT raises a TypeError on the `iss` claim during JWT encoding because it expects a string. This surfaces at runtime when the environment variable is parsed as an int rather than str. ## Notes - Only `gh_app_id` is converted; `gh_app_installation_id` is left as-is since `login_as_app_installation` accepts it in its original form — reviewers should verify this is intentional - The existing tests previously used `assert_called_once()` without argument checks, so bugs like this were invisible; the tightened assertions now catch argument type mismatches Signed-off-by: jmeridth <jmeridth@gmail.com>
1 parent 56fce7d commit 2f73601

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

auth.py

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

test_auth.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def test_auth_to_github_with_ghe_and_ghe_app(self, mock_ghe):
5757
result = auth.auth_to_github(
5858
"", "123", "123", b"123", "https://github.example.com", True
5959
)
60-
mock.login_as_app_installation.assert_called_once()
60+
mock.login_as_app_installation.assert_called_once_with(b"123", "123", "123")
6161
self.assertEqual(result, mock)
6262

6363
@patch("github3.github.GitHub")
@@ -70,7 +70,21 @@ def test_auth_to_github_with_app(self, mock_gh):
7070
result = auth.auth_to_github(
7171
"", "123", "123", b"123", "https://github.example.com", False
7272
)
73-
mock.login_as_app_installation.assert_called_once()
73+
mock.login_as_app_installation.assert_called_once_with(b"123", "123", "123")
74+
self.assertEqual(result, mock)
75+
76+
@patch("github3.github.GitHub")
77+
def test_auth_to_github_with_app_int_app_id(self, mock_gh):
78+
"""
79+
Test that an integer app_id is converted to a string before passing
80+
to login_as_app_installation, to avoid PyJWT TypeError on the iss claim.
81+
"""
82+
mock = mock_gh.return_value
83+
mock.login_as_app_installation = MagicMock(return_value=True)
84+
result = auth.auth_to_github("", 123, 456, b"private_key", "", False)
85+
mock.login_as_app_installation.assert_called_once_with(
86+
b"private_key", "123", 456
87+
)
7488
self.assertEqual(result, mock)
7589

7690
@patch("github3.login")

0 commit comments

Comments
 (0)