|
| 1 | +from django.test import override_settings |
| 2 | + |
1 | 3 | from sentry.testutils.cases import APITestCase |
2 | 4 |
|
| 5 | +SENTRY_BUILTIN_SOURCES_PLATFORM_TEST = { |
| 6 | + "public-source-1": { |
| 7 | + "id": "sentry:public-1", |
| 8 | + "name": "Public Source 1", |
| 9 | + "type": "http", |
| 10 | + "url": "https://example.com/symbols/", |
| 11 | + }, |
| 12 | + "public-source-2": { |
| 13 | + "id": "sentry:public-2", |
| 14 | + "name": "Public Source 2", |
| 15 | + "type": "http", |
| 16 | + "url": "https://example.com/symbols2/", |
| 17 | + }, |
| 18 | + "nintendo": { |
| 19 | + "id": "sentry:nintendo", |
| 20 | + "name": "Nintendo SDK", |
| 21 | + "type": "s3", |
| 22 | + "bucket": "nintendo-symbols", |
| 23 | + "region": "us-east-1", |
| 24 | + "access_key": "test-key", |
| 25 | + "secret_key": "test-secret", |
| 26 | + "layout": {"type": "native"}, |
| 27 | + "platforms": ["nintendo-switch"], |
| 28 | + }, |
| 29 | +} |
| 30 | + |
3 | 31 |
|
4 | 32 | class BuiltinSymbolSourcesNoSlugTest(APITestCase): |
5 | 33 | endpoint = "sentry-api-0-builtin-symbol-sources" |
@@ -39,3 +67,77 @@ def test_with_slug(self) -> None: |
39 | 67 | assert "id" in body[0] |
40 | 68 | assert "name" in body[0] |
41 | 69 | assert "hidden" in body[0] |
| 70 | + |
| 71 | + |
| 72 | +class BuiltinSymbolSourcesPlatformFilteringTest(APITestCase): |
| 73 | + endpoint = "sentry-api-0-organization-builtin-symbol-sources" |
| 74 | + |
| 75 | + def setUp(self) -> None: |
| 76 | + super().setUp() |
| 77 | + self.organization = self.create_organization(owner=self.user) |
| 78 | + self.login_as(user=self.user) |
| 79 | + |
| 80 | + @override_settings(SENTRY_BUILTIN_SOURCES=SENTRY_BUILTIN_SOURCES_PLATFORM_TEST) |
| 81 | + def test_platform_filtering_nintendo_switch_with_access(self) -> None: |
| 82 | + """Nintendo Switch platform should see nintendo source only if org has access""" |
| 83 | + # Enable nintendo-switch for this organization |
| 84 | + self.organization.update_option("sentry:enabled_console_platforms", ["nintendo-switch"]) |
| 85 | + |
| 86 | + resp = self.get_response(self.organization.slug, qs_params={"platform": "nintendo-switch"}) |
| 87 | + assert resp.status_code == 200 |
| 88 | + |
| 89 | + body = resp.data |
| 90 | + source_keys = [source["sentry_key"] for source in body] |
| 91 | + |
| 92 | + # Nintendo Switch with access should see nintendo |
| 93 | + assert "nintendo" in source_keys |
| 94 | + # Should also see public sources (no platform restriction) |
| 95 | + assert "public-source-1" in source_keys |
| 96 | + assert "public-source-2" in source_keys |
| 97 | + |
| 98 | + @override_settings(SENTRY_BUILTIN_SOURCES=SENTRY_BUILTIN_SOURCES_PLATFORM_TEST) |
| 99 | + def test_platform_filtering_nintendo_switch_without_access(self) -> None: |
| 100 | + """Nintendo Switch platform should NOT see nintendo if org lacks access""" |
| 101 | + # Organization does not have nintendo-switch enabled (default is empty list) |
| 102 | + |
| 103 | + resp = self.get_response(self.organization.slug, qs_params={"platform": "nintendo-switch"}) |
| 104 | + assert resp.status_code == 200 |
| 105 | + |
| 106 | + body = resp.data |
| 107 | + source_keys = [source["sentry_key"] for source in body] |
| 108 | + |
| 109 | + # Should NOT see nintendo without console platform access |
| 110 | + assert "nintendo" not in source_keys |
| 111 | + # Should still see public sources |
| 112 | + assert "public-source-1" in source_keys |
| 113 | + assert "public-source-2" in source_keys |
| 114 | + |
| 115 | + @override_settings(SENTRY_BUILTIN_SOURCES=SENTRY_BUILTIN_SOURCES_PLATFORM_TEST) |
| 116 | + def test_platform_filtering_unity(self) -> None: |
| 117 | + """Unity platform should NOT see nintendo source""" |
| 118 | + resp = self.get_response(self.organization.slug, qs_params={"platform": "unity"}) |
| 119 | + assert resp.status_code == 200 |
| 120 | + |
| 121 | + body = resp.data |
| 122 | + source_keys = [source["sentry_key"] for source in body] |
| 123 | + |
| 124 | + # Unity should see public sources (no platform restriction) |
| 125 | + assert "public-source-1" in source_keys |
| 126 | + assert "public-source-2" in source_keys |
| 127 | + # Unity should NOT see nintendo (restricted to nintendo-switch) |
| 128 | + assert "nintendo" not in source_keys |
| 129 | + |
| 130 | + @override_settings(SENTRY_BUILTIN_SOURCES=SENTRY_BUILTIN_SOURCES_PLATFORM_TEST) |
| 131 | + def test_no_platform_parameter(self) -> None: |
| 132 | + """Without platform parameter, should see public sources but not platform-restricted ones""" |
| 133 | + resp = self.get_response(self.organization.slug) |
| 134 | + assert resp.status_code == 200 |
| 135 | + |
| 136 | + body = resp.data |
| 137 | + source_keys = [source["sentry_key"] for source in body] |
| 138 | + |
| 139 | + # Should see public sources (no platform restriction) |
| 140 | + assert "public-source-1" in source_keys |
| 141 | + assert "public-source-2" in source_keys |
| 142 | + # Should NOT see platform-restricted source when no platform is provided |
| 143 | + assert "nintendo" not in source_keys |
0 commit comments