-
Notifications
You must be signed in to change notification settings - Fork 25
feat(github): GitHub App authentication #774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
github-runner-manager/tests/integration/test_github_app_auth.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| # Copyright 2026 Canonical Ltd. | ||
| # See LICENSE file for licensing details. | ||
|
|
||
| """Integration tests for GitHub App authentication.""" | ||
|
|
||
| import secrets | ||
|
|
||
| import pytest | ||
|
|
||
| from github_runner_manager.configuration.github import ( | ||
| GitHubAppAuth, | ||
| GitHubPath, | ||
| parse_github_path, | ||
| ) | ||
| from github_runner_manager.github_client import GithubClient | ||
| from github_runner_manager.manager.models import InstanceID | ||
|
|
||
|
|
||
| @pytest.fixture(autouse=True, scope="module") | ||
| def openstack_cleanup(): | ||
| """Override the autouse openstack_cleanup fixture — this module has no OpenStack dependency.""" | ||
| yield | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def github_app_auth(pytestconfig: pytest.Config) -> GitHubAppAuth: | ||
| """Get GitHub App auth configuration, skip if credentials not provided.""" | ||
| app_client_id = pytestconfig.getoption("--github-app-client-id") | ||
| installation_id = pytestconfig.getoption("--github-app-installation-id") | ||
| private_key = pytestconfig.getoption("--github-app-private-key") | ||
|
|
||
| if not all([app_client_id, installation_id, private_key]): | ||
| pytest.skip("GitHub App credentials not provided") | ||
|
|
||
| return GitHubAppAuth( | ||
| app_client_id=app_client_id, | ||
| installation_id=int(installation_id), | ||
| private_key=private_key, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def github_app_client(github_app_auth: GitHubAppAuth) -> GithubClient: | ||
| """Create a GithubClient using GitHub App authentication.""" | ||
| return GithubClient(auth=github_app_auth) | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def github_path(pytestconfig: pytest.Config) -> GitHubPath: | ||
| """Get the GitHub path from test configuration.""" | ||
| path_str = pytestconfig.getoption("--github-repository") | ||
| if not path_str: | ||
| pytest.skip("GitHub repository path not provided") | ||
| return parse_github_path(path_str, runner_group="default") | ||
|
|
||
|
|
||
| def test_get_jit_token_with_github_app_auth( | ||
| github_app_client: GithubClient, github_path: GitHubPath | ||
| ) -> None: | ||
| """ | ||
| arrange: GithubClient created with GitHubAppAuth credentials. | ||
| act: Request a JIT config token to register a runner. | ||
| assert: Token is returned and runner is created, then clean up. | ||
| """ | ||
| prefix = "test-app-auth" | ||
| instance_id = InstanceID(prefix=prefix, suffix=secrets.token_hex(6)) | ||
|
|
||
| runner = None | ||
| try: | ||
| jit_token, runner = github_app_client.get_runner_registration_jittoken( | ||
| github_path, instance_id=instance_id, labels=[prefix] | ||
| ) | ||
|
|
||
| assert jit_token, "JIT config token should be non-empty" | ||
| assert runner.id > 0 | ||
| assert runner.identity.instance_id == instance_id | ||
| finally: | ||
| if runner is not None: | ||
| github_app_client.delete_runner(github_path, runner.id) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.