Skip to content

Commit 5ed8d97

Browse files
add error if user tries to mo without ff
1 parent 510aa8a commit 5ed8d97

File tree

2 files changed

+72
-3
lines changed

2 files changed

+72
-3
lines changed

src/sentry/integrations/github/integration.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -761,8 +761,8 @@ class GitHubInstallationError(StrEnum):
761761
INSTALLATION_EXISTS = "Github installed on another Sentry organization."
762762
USER_MISMATCH = "Authenticated user is not the same as who installed the app."
763763
MISSING_INTEGRATION = "Integration does not exist."
764-
INVALID_INSTALLATION = "User does not have access to given installation"
765-
FEATURE_NOT_AVAILABLE = "Organization does not have access to this feature"
764+
INVALID_INSTALLATION = "User does not have access to given installation."
765+
FEATURE_NOT_AVAILABLE = "Your organization does not have access to this feature."
766766

767767

768768
def record_event(event: IntegrationPipelineViewType):
@@ -928,7 +928,6 @@ def dispatch(self, request: HttpRequest, pipeline: Pipeline) -> HttpResponseBase
928928
)
929929

930930
if chosen_installation_id := request.GET.get("chosen_installation_id"):
931-
932931
if chosen_installation_id == "-1":
933932
return pipeline.next_step()
934933

tests/sentry/integrations/github/test_integration.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,6 +1530,76 @@ def test_github_installation_calls_ui_no_biz_plan(self, mock_render, mock_record
15301530
# SLO assertions
15311531
assert_success_metric(mock_record)
15321532

1533+
@with_feature(
1534+
{"organizations:github-multi-org": True, "organizations:integrations-scm-multi-org": False}
1535+
)
1536+
@responses.activate
1537+
@patch("sentry.integrations.utils.metrics.EventLifecycle.record_event")
1538+
@patch.object(PipelineView, "render_react_view", return_value=HttpResponse())
1539+
def test_errors_when_invalid_access_to_multi_org(self, mock_render, mock_record):
1540+
self._setup_with_existing_installations()
1541+
installations = [
1542+
{
1543+
"installation_id": "1",
1544+
"github_account": "santry",
1545+
"avatar_url": "https://github.com/knobiknows/all-the-bufo/raw/main/all-the-bufo/bufo-pitchforks.png",
1546+
},
1547+
{
1548+
"installation_id": "2",
1549+
"github_account": "bufo-bot",
1550+
"avatar_url": "https://github.com/knobiknows/all-the-bufo/raw/main/all-the-bufo/bufo-pog.png",
1551+
},
1552+
{
1553+
"installation_id": "-1",
1554+
"github_account": "Integrate with a new GitHub organization",
1555+
"avatar_url": "",
1556+
},
1557+
]
1558+
1559+
resp = self.client.get(self.init_path)
1560+
assert resp.status_code == 302
1561+
redirect = urlparse(resp["Location"])
1562+
assert redirect.scheme == "https"
1563+
assert redirect.netloc == "github.com"
1564+
assert redirect.path == "/login/oauth/authorize"
1565+
assert (
1566+
redirect.query
1567+
== f"client_id=github-client-id&state={self.pipeline.signature}&redirect_uri=http://testserver/extensions/github/setup/"
1568+
)
1569+
resp = self.client.get(
1570+
"{}?{}".format(
1571+
self.setup_path,
1572+
urlencode({"code": "12345678901234567890", "state": self.pipeline.signature}),
1573+
)
1574+
)
1575+
mock_render.assert_called_with(
1576+
request=ANY,
1577+
pipeline_name="githubInstallationSelect",
1578+
props={"installation_info": installations, "has_scm_multi_org": False},
1579+
)
1580+
1581+
# We rendered the GithubOrganizationSelection UI and the user chose to skip
1582+
resp = self.client.get(
1583+
"{}?{}".format(
1584+
self.setup_path,
1585+
urlencode(
1586+
{
1587+
"code": "12345678901234567890",
1588+
"state": self.pipeline.signature,
1589+
"chosen_installation_id": "12345",
1590+
}
1591+
),
1592+
)
1593+
)
1594+
1595+
self.assertTemplateUsed(resp, "sentry/integrations/github-integration-failed.html")
1596+
assert (
1597+
b'{"success":false,"data":{"error":"Your organization does not have access to this feature."}}'
1598+
in resp.content
1599+
)
1600+
assert b'window.opener.postMessage({"success":false' in resp.content
1601+
assert_failure_metric(mock_record, GitHubInstallationError.FEATURE_NOT_AVAILABLE)
1602+
15331603
@with_feature("organizations:integrations-scm-multi-org")
15341604
@with_feature("organizations:github-multi-org")
15351605
@responses.activate

0 commit comments

Comments
 (0)