|
14 | 14 | PULL_REQUEST_OPENED_EVENT_EXAMPLE, |
15 | 15 | PUSH_EVENT_EXAMPLE_INSTALLATION, |
16 | 16 | ) |
| 17 | +from sentry.integrations.github_enterprise.webhook import ( |
| 18 | + GitHubEnterpriseInstallationRepositoriesEventWebhook, |
| 19 | +) |
17 | 20 | from sentry.integrations.services.integration import integration_service |
18 | 21 | from sentry.models.commit import Commit |
19 | 22 | from sentry.models.commitauthor import CommitAuthor |
@@ -253,6 +256,66 @@ def test_missing_signature_fail_without_option_set(self, mock_installation: Magi |
253 | 256 | assert b"Missing headers X-Hub-Signature-256 or X-Hub-Signature" in response.content |
254 | 257 |
|
255 | 258 |
|
| 259 | +@patch("sentry.integrations.github_enterprise.client.get_jwt") |
| 260 | +@patch("sentry.integrations.github_enterprise.webhook.get_installation_metadata") |
| 261 | +class InstallationRepositoriesEventWebhookTest(APITestCase): |
| 262 | + def setUp(self) -> None: |
| 263 | + self.url = "/extensions/github-enterprise/webhook/" |
| 264 | + self.metadata = { |
| 265 | + "url": "35.232.149.196", |
| 266 | + "id": "2", |
| 267 | + "name": "test-app", |
| 268 | + "webhook_secret": "b3002c3e321d4b7880360d397db2ccfd", |
| 269 | + "private_key": "private_key", |
| 270 | + "verify_ssl": True, |
| 271 | + } |
| 272 | + |
| 273 | + @patch( |
| 274 | + "sentry.integrations.github.tasks.sync_repos_on_install_change.sync_repos_on_install_change.apply_async" |
| 275 | + ) |
| 276 | + def test_handler_dispatches_task_with_ghe_provider( |
| 277 | + self, |
| 278 | + mock_apply_async: MagicMock, |
| 279 | + mock_get_installation_metadata: MagicMock, |
| 280 | + mock_get_jwt: MagicMock, |
| 281 | + ) -> None: |
| 282 | + """Verify the GHE handler looks up integrations with the correct provider.""" |
| 283 | + mock_get_jwt.return_value = "" |
| 284 | + mock_get_installation_metadata.return_value = self.metadata |
| 285 | + |
| 286 | + integration = self.create_integration( |
| 287 | + external_id="35.232.149.196:12345", |
| 288 | + organization=self.project.organization, |
| 289 | + provider="github_enterprise", |
| 290 | + metadata={ |
| 291 | + "domain_name": "35.232.149.196/testorg", |
| 292 | + "installation_id": "12345", |
| 293 | + "installation": { |
| 294 | + "id": "2", |
| 295 | + "private_key": "private_key", |
| 296 | + "verify_ssl": True, |
| 297 | + }, |
| 298 | + }, |
| 299 | + ) |
| 300 | + |
| 301 | + handler = GitHubEnterpriseInstallationRepositoriesEventWebhook() |
| 302 | + handler( |
| 303 | + event={ |
| 304 | + "installation": {"id": 12345}, |
| 305 | + "action": "added", |
| 306 | + "repositories_added": [{"id": 1, "full_name": "testorg/repo", "private": False}], |
| 307 | + "repositories_removed": [], |
| 308 | + "repository_selection": "selected", |
| 309 | + "sender": {"id": 1, "login": "testuser"}, |
| 310 | + }, |
| 311 | + host="35.232.149.196", |
| 312 | + ) |
| 313 | + |
| 314 | + mock_apply_async.assert_called_once() |
| 315 | + kwargs = mock_apply_async.call_args[1]["kwargs"] |
| 316 | + assert kwargs["integration_id"] == integration.id |
| 317 | + |
| 318 | + |
256 | 319 | @patch("sentry.integrations.github_enterprise.client.get_jwt") |
257 | 320 | @patch("sentry.integrations.github_enterprise.webhook.get_installation_metadata") |
258 | 321 | class PushEventWebhookTest(APITestCase): |
|
0 commit comments