|
10 | 10 | from sentry.constants import ObjectStatus |
11 | 11 | from sentry.integrations.github.integration import GitHubIntegrationProvider |
12 | 12 | from sentry.integrations.github_enterprise.integration import GitHubEnterpriseIntegrationProvider |
| 13 | +from sentry.integrations.gitlab.integration import GitlabIntegration |
13 | 14 | from sentry.integrations.models.organization_integration import OrganizationIntegration |
14 | 15 | from sentry.integrations.source_code_management.sync_repos import ( |
15 | 16 | sync_repos_for_org, |
@@ -572,6 +573,40 @@ def test_creates_new_repos_for_gitlab(self) -> None: |
572 | 573 | assert len(repos) == 2 |
573 | 574 | assert repos[0].provider == "integrations:gitlab" |
574 | 575 |
|
| 576 | + @responses.activate |
| 577 | + def test_error_dict_response_raises_integration_error(self) -> None: |
| 578 | + integration = self.create_provider_integration( |
| 579 | + provider="gitlab", |
| 580 | + name="Example Gitlab 2", |
| 581 | + external_id="example2.gitlab.com:group-y", |
| 582 | + metadata={ |
| 583 | + "instance": "example.gitlab.com", |
| 584 | + "base_url": "https://example.gitlab.com", |
| 585 | + "domain_name": "example.gitlab.com/group-y", |
| 586 | + "verify_ssl": False, |
| 587 | + "group_id": 1, |
| 588 | + "webhook_secret": "secret123", |
| 589 | + }, |
| 590 | + ) |
| 591 | + identity = Identity.objects.create( |
| 592 | + idp=self.create_identity_provider(type="gitlab", config={}), |
| 593 | + user=self.user, |
| 594 | + external_id="gitlab456", |
| 595 | + data={"access_token": "123456789"}, |
| 596 | + ) |
| 597 | + integration.add_organization(self.organization, self.user, identity.id) |
| 598 | + installation = integration.get_installation(organization_id=self.organization.id) |
| 599 | + |
| 600 | + responses.add( |
| 601 | + responses.GET, |
| 602 | + "https://example.gitlab.com/api/v4/groups/1/projects?search=&simple=True&include_subgroups=False&page=1&per_page=100&order_by=last_activity_at", |
| 603 | + json={"status": "error", "error": "group not accessible"}, |
| 604 | + ) |
| 605 | + |
| 606 | + assert isinstance(installation, GitlabIntegration) |
| 607 | + with pytest.raises(IntegrationError, match="Expected list of projects"): |
| 608 | + installation.get_repositories() |
| 609 | + |
575 | 610 |
|
576 | 611 | @control_silo_test |
577 | 612 | class SyncReposForOrgBitbucketTestCase(TestCase): |
@@ -762,6 +797,21 @@ def _wrap_identity_not_valid(*args: object, **kwargs: object) -> None: |
762 | 797 | with assume_test_silo_mode(SiloMode.CELL): |
763 | 798 | assert Repository.objects.count() == 0 |
764 | 799 |
|
| 800 | + def test_vsts_message_from_error_handles_string_json(self) -> None: |
| 801 | + integration = self.create_provider_integration( |
| 802 | + provider="vsts", |
| 803 | + external_id="vsts-account-id-2", |
| 804 | + name="MyVSTSAccount", |
| 805 | + metadata={"domain_name": "https://myvstsaccount.visualstudio.com/"}, |
| 806 | + ) |
| 807 | + integration.add_organization(self.organization, self.user) |
| 808 | + installation = integration.get_installation(organization_id=self.organization.id) |
| 809 | + |
| 810 | + exc = ApiForbiddenError("ADO OAuth tokens disabled") |
| 811 | + exc.json = "ADO OAuth tokens disabled" # type: ignore[assignment] |
| 812 | + msg = installation.message_from_error(exc) |
| 813 | + assert "unknown error" in msg |
| 814 | + |
765 | 815 |
|
766 | 816 | @control_silo_test |
767 | 817 | class SyncReposForOrgBrokenIdentityTestCase(TestCase): |
|
0 commit comments