Repository navigation
BED-10295: Model GitHub App registration ownership #94
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
Merged
Merged
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| from unittest.mock import MagicMock | ||
|
|
||
| import pytest | ||
|
|
||
| from openhound_github.models.app_installation import App, Owner | ||
|
|
||
|
|
||
| def _app(owner: Owner | None) -> App: | ||
| return App( | ||
| id=123, | ||
| slug="example-app", | ||
| client_id="Iv1.example", | ||
| node_id="APP_NODE_123", | ||
| owner=owner, | ||
| name="Example App", | ||
| permissions={}, | ||
| events=[], | ||
| org_login="installed-org", | ||
| org_node_id="ORG_NODE_789", | ||
| ) | ||
|
|
||
|
|
||
| def _owner(owner_type: str, node_id: str = "OWNER_NODE_456") -> Owner: | ||
| return Owner( | ||
| login="example-owner", | ||
| id=456, | ||
| node_id=node_id, | ||
| type=owner_type, | ||
| ) | ||
|
|
||
|
|
||
| def test_app_node_includes_registration_owner_properties() -> None: | ||
| app = _app(_owner("Organization")) | ||
| lookup = MagicMock() | ||
| lookup.is_tenant_organization_node_id.return_value = True | ||
| app._lookup = lookup | ||
|
|
||
| properties = app.as_node.properties | ||
|
|
||
| assert properties.owner_login == "example-owner" | ||
| assert properties.owner_node_id == "OWNER_NODE_456" | ||
| assert properties.owner_type == "Organization" | ||
| assert properties.query_owner == ( | ||
| "MATCH p=(owner)-[:GH_Owns]->" | ||
| "(:GH_App {node_id:'APP_NODE_123'}) RETURN p" | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("owner_type", "owner_node_id", "tenant_org", "enterprise_id", "expected"), | ||
| [ | ||
| ("Organization", "ORG_NODE_1", True, "ENT_NODE_1", "tenant_owned"), | ||
| ("Organization", "EXTERNAL_ORG", False, "ENT_NODE_1", "third_party"), | ||
| ("Organization", "UNRESOLVED_ORG", False, None, "unknown"), | ||
| ("User", "USER_NODE_1", False, "ENT_NODE_1", "third_party"), | ||
| ("Enterprise", "ENT_NODE_1", False, "ENT_NODE_1", "tenant_owned"), | ||
| ("Enterprise", "EXTERNAL_ENT", False, "ENT_NODE_1", "third_party"), | ||
| ("Enterprise", "ENT_NODE_1", False, None, "unknown"), | ||
| ("Bot", "BOT_NODE_1", False, "ENT_NODE_1", "unknown"), | ||
| ], | ||
| ) | ||
| def test_app_classifies_registration_origin( | ||
| owner_type: str, | ||
| owner_node_id: str, | ||
| tenant_org: bool, | ||
| enterprise_id: str | None, | ||
| expected: str, | ||
| ) -> None: | ||
| app = _app(_owner(owner_type, owner_node_id)) | ||
| lookup = MagicMock() | ||
| lookup.is_tenant_organization_node_id.return_value = tenant_org | ||
| lookup.enterprise_id.return_value = enterprise_id | ||
| app._lookup = lookup | ||
|
|
||
| assert app.as_node.properties.registration_origin == expected | ||
|
|
||
|
|
||
| def test_app_with_missing_owner_has_unknown_registration_origin() -> None: | ||
| app = _app(None) | ||
|
|
||
| properties = app.as_node.properties | ||
|
|
||
| assert properties.owner_login is None | ||
| assert properties.owner_node_id is None | ||
| assert properties.owner_type is None | ||
| assert properties.registration_origin == "unknown" | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("owner_type", "owner_node_id"), | ||
| [ | ||
| ("Organization", "ORG_NODE_1"), | ||
| ("Enterprise", "ENT_NODE_1"), | ||
| ("User", "USER_NODE_1"), | ||
| ], | ||
| ) | ||
| def test_app_emits_registration_edge_for_collected_owner( | ||
| owner_type: str, owner_node_id: str | ||
| ) -> None: | ||
| app = _app(_owner(owner_type, owner_node_id)) | ||
| lookup = MagicMock() | ||
| lookup.is_tenant_organization_node_id.return_value = True | ||
| lookup.enterprise_id.return_value = owner_node_id | ||
| lookup.is_collected_user_node_id.return_value = True | ||
| app._lookup = lookup | ||
|
|
||
| edge = app.edges[0] | ||
|
|
||
| assert edge.kind == "GH_Owns" | ||
| assert edge.start.value == owner_node_id | ||
| assert edge.end.value == "APP_NODE_123" | ||
| assert edge.properties.traversable is True | ||
|
|
||
|
|
||
| def test_app_skips_registration_edge_for_uncollected_owner() -> None: | ||
| app = _app(_owner("Organization", "EXTERNAL_ORG")) | ||
| lookup = MagicMock() | ||
| lookup.is_tenant_organization_node_id.return_value = False | ||
| app._lookup = lookup | ||
|
|
||
| assert app.edges == [] |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Include enterprise owners in the property descriptions.
The new diagram documents
GH_Enterprise -> GH_App, and the runtime acceptsEnterpriseowners and emits this edge. Theowner_loginandowner_node_idrows still mention only users and organizations. Update these rows and includeEnterprisein theowner_typeexamples. Enterprise-owned GitHub Apps are supported. (raw.githubusercontent.com)