@@ -1530,6 +1530,76 @@ def test_github_installation_calls_ui_no_biz_plan(self, mock_render, mock_record
1530
1530
# SLO assertions
1531
1531
assert_success_metric (mock_record )
1532
1532
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
+
1533
1603
@with_feature ("organizations:integrations-scm-multi-org" )
1534
1604
@with_feature ("organizations:github-multi-org" )
1535
1605
@responses .activate
0 commit comments