Skip to content

Commit aff93cf

Browse files
authored
Merge pull request #413 from github-community-projects/jm_fix_app_id
fix: convert app_id to string before login_as_app_installation call
2 parents 1cdbda1 + d8b88f5 commit aff93cf

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

.github/pull_request_template.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,3 @@ examples: "feat: add new logger" or "fix: remove unused imports"
2020
- [ ] If documentation is needed for this change, has that been included in this pull request
2121
- [ ] run `make lint` and fix any issues that you have introduced
2222
- [ ] run `make test` and ensure you have test coverage for the lines you are introducing
23-
- [ ] If publishing new data to the public (scorecards, security scan results, code quality results, live dashboards, etc.), please request review from `@jeffrey-luszcz`

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ __pycache__/
1313
# C extensions
1414
*.so
1515

16+
# ai
17+
**/.claude/*.local.*
18+
1619
# Distribution / packaging
1720
.Python
1821
build/

auth.py

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

test_auth.py

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

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

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

0 commit comments

Comments
 (0)