def test_creates_audit_log_entry(self): request = self.make_request(user=self.user, method='GET') Destroyer.run( sentry_app=self.sentry_app, request=request, ) assert AuditLogEntry.objects.filter(event=AuditLogEntryEvent.SENTRY_APP_REMOVE).exists()
def test_passes_notify_false_if_app_internal(self, run): self.create_project(organization=self.org) internal = self.create_internal_integration(organization=self.org) Destroyer.run(sentry_app=internal, user=self.user) run.assert_called_with( install=internal.installations.first(), user=internal.proxy_user, notify=False )
def test_creates_audit_log_entry(self): request = self.make_request(user=self.user, method='GET') Destroyer.run( user=self.user, sentry_app=self.sentry_app, request=request, ) assert AuditLogEntry.objects.filter(event=AuditLogEntryEvent.SENTRY_APP_REMOVE).exists()
def delete(self, request: Request, sentry_app) -> Response: if sentry_app.is_unpublished or sentry_app.is_internal: Destroyer.run(user=request.user, sentry_app=sentry_app, request=request) return Response(status=204) return Response({"detail": ["Published apps cannot be removed."]}, status=403)
def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.sentry_app = self.create_sentry_app( name="blah", organization=self.org, scopes=("project:read",) ) self.destroyer = Destroyer(sentry_app=self.sentry_app, user=self.user)
def disable_scim(self, user): from sentry.mediators.sentry_apps import Destroyer from sentry.models import SentryAppInstallationForProvider if self.flags.scim_enabled: install = SentryAppInstallationForProvider.objects.get( organization=self.organization, provider=f"{self.provider}_scim" ) Destroyer.run(sentry_app=install.sentry_app_installation.sentry_app, user=user) self.flags.scim_enabled = False
def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.sentry_app = self.create_sentry_app( name='blah', organization=self.org, scopes=('project:read',), ) self.destroyer = Destroyer(sentry_app=self.sentry_app)
def delete(self, request, sentry_app): if not features.has('organizations:internal-catchall', sentry_app.owner, actor=request.user): return Response(status=404) if sentry_app.status == SentryAppStatus.UNPUBLISHED: Destroyer.run(sentry_app=sentry_app) return Response(status=204) return Response({'detail': ['Published apps cannot be removed.']}, status=403)
def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.sentry_app = Creator.run( name='blah', organization=self.org, scopes=('project:read',), webhook_url='https://example.com', ) self.destroyer = Destroyer(sentry_app=self.sentry_app)
def test_records_analytics(self, record): Destroyer.run( user=self.user, sentry_app=self.sentry_app, request=self.make_request(user=self.user, method='GET'), ) record.assert_called_with( 'sentry_app.deleted', user_id=self.user.id, organization_id=self.org.id, sentry_app=self.sentry_app.slug, )
def test_records_analytics(self, record): Destroyer.run( user=self.user, sentry_app=self.sentry_app, request=self.make_request(user=self.user, method="GET"), ) record.assert_called_with( "sentry_app.deleted", user_id=self.user.id, organization_id=self.org.id, sentry_app=self.sentry_app.slug, )
def delete(self, request, sentry_app): if not features.has("organizations:sentry-apps", sentry_app.owner, actor=request.user): return Response(status=404) if sentry_app.is_unpublished or sentry_app.is_internal: Destroyer.run(user=request.user, sentry_app=sentry_app, request=request) return Response(status=204) return Response({"detail": ["Published apps cannot be removed."]}, status=403)
class TestDestroyer(TestCase): def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.sentry_app = self.create_sentry_app( name='blah', organization=self.org, scopes=('project:read',), ) self.destroyer = Destroyer(sentry_app=self.sentry_app) def test_deletes_app_installations(self): install = self.create_sentry_app_installation( organization=self.org, slug=self.sentry_app.slug, user=self.user, ) self.destroyer.call() assert not SentryAppInstallation.objects.filter(pk=install.id).exists() def test_deletes_api_application(self): application = self.sentry_app.application self.destroyer.call() assert not ApiApplication.objects.filter(pk=application.id).exists() def test_deletes_proxy_user(self): proxy_user = self.sentry_app.proxy_user self.destroyer.call() assert not User.objects.filter(pk=proxy_user.id).exists() def test_creates_audit_log_entry(self): request = self.make_request(user=self.user, method='GET') Destroyer.run( sentry_app=self.sentry_app, request=request, ) assert AuditLogEntry.objects.filter(event=AuditLogEntryEvent.SENTRY_APP_REMOVE).exists() def test_soft_deletes_sentry_app(self): self.destroyer.call() with self.assertRaises(SentryApp.DoesNotExist): SentryApp.objects.get(pk=self.sentry_app.id) # The QuerySet will automatically NOT include deleted installs, so we # use a raw sql query to ensure it still exists. c = connection.cursor() c.execute( 'SELECT count(1) ' 'FROM sentry_sentryapp ' 'WHERE id = %s AND date_deleted IS NOT NULL', [self.sentry_app.id]) assert c.fetchone()[0] == 1
def delete(self, request, sentry_app): if not features.has('organizations:internal-catchall', sentry_app.owner, actor=request.user): return Response(status=404) if sentry_app.status == SentryAppStatus.UNPUBLISHED: Destroyer.run(sentry_app=sentry_app) return Response(status=204) return Response( { 'detail': ['Published apps cannot be removed.'] }, status=403 )
class TestDestroyer(TestCase): def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.sentry_app = self.create_sentry_app( name='blah', organization=self.org, scopes=('project:read',), ) self.destroyer = Destroyer(sentry_app=self.sentry_app) def test_deletes_app_installations(self): install = self.create_sentry_app_installation( organization=self.org, slug=self.sentry_app.slug, user=self.user, ) self.destroyer.call() assert not SentryAppInstallation.objects.filter(pk=install.id).exists() def test_deletes_api_application(self): application = self.sentry_app.application self.destroyer.call() assert not ApiApplication.objects.filter(pk=application.id).exists() def test_deletes_proxy_user(self): proxy_user = self.sentry_app.proxy_user self.destroyer.call() assert not User.objects.filter(pk=proxy_user.id).exists() def test_soft_deletes_sentry_app(self): self.destroyer.call() with self.assertRaises(SentryApp.DoesNotExist): SentryApp.objects.get(pk=self.sentry_app.id) # The QuerySet will automatically NOT include deleted installs, so we # use a raw sql query to ensure it still exists. c = connection.cursor() c.execute( 'SELECT count(1) ' 'FROM sentry_sentryapp ' 'WHERE id = %s AND date_deleted IS NOT NULL', [self.sentry_app.id]) assert c.fetchone()[0] == 1
def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.sentry_app = self.create_sentry_app( name='blah', organization=self.org, scopes=('project:read',), ) self.destroyer = Destroyer(sentry_app=self.sentry_app)
class TestDestroyer(TestCase): def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.sentry_app = Creator.run( name='blah', organization=self.org, scopes=('project:read',), webhook_url='https://example.com', ) self.destroyer = Destroyer(sentry_app=self.sentry_app) def test_deletes_api_application(self): application = self.sentry_app.application self.destroyer.call() assert not ApiApplication.objects.filter(pk=application.id).exists() def test_deletes_proxy_user(self): proxy_user = self.sentry_app.proxy_user self.destroyer.call() assert not User.objects.filter(pk=proxy_user.id).exists() def test_soft_deletes_sentry_app(self): self.destroyer.call() with self.assertRaises(SentryApp.DoesNotExist): SentryApp.objects.get(pk=self.sentry_app.id) # The QuerySet will automatically NOT include deleted installs, so we # use a raw sql query to ensure it still exists. c = connection.cursor() c.execute( 'SELECT count(1) ' 'FROM sentry_sentryapp ' 'WHERE id = %s AND date_deleted IS NOT NULL', [self.sentry_app.id]) assert c.fetchone()[0] == 1
class TestDestroyer(TestCase): def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.sentry_app = self.create_sentry_app( name="blah", organization=self.org, scopes=("project:read",) ) self.destroyer = Destroyer(sentry_app=self.sentry_app, user=self.user) @responses.activate def test_deletes_app_installations(self): responses.add(responses.POST, "https://example.com/webhook", status=200) install = self.create_sentry_app_installation( organization=self.org, slug=self.sentry_app.slug, user=self.user ) self.destroyer.call() assert not SentryAppInstallation.objects.filter(pk=install.id).exists() @patch("sentry.mediators.sentry_app_installations.Destroyer.run") def test_passes_notify_false_if_app_internal(self, run): self.create_project(organization=self.org) internal = self.create_internal_integration(organization=self.org) Destroyer.run(sentry_app=internal, user=self.user) run.assert_called_with( install=internal.installations.first(), user=internal.proxy_user, notify=False ) def test_deletes_api_application(self): application = self.sentry_app.application self.destroyer.call() assert not ApiApplication.objects.filter(pk=application.id).exists() def test_deletes_proxy_user(self): proxy_user = self.sentry_app.proxy_user self.destroyer.call() assert not User.objects.filter(pk=proxy_user.id).exists() def test_creates_audit_log_entry(self): request = self.make_request(user=self.user, method="GET") Destroyer.run(user=self.user, sentry_app=self.sentry_app, request=request) assert AuditLogEntry.objects.filter(event=AuditLogEntryEvent.SENTRY_APP_REMOVE).exists() def test_soft_deletes_sentry_app(self): self.destroyer.call() with self.assertRaises(SentryApp.DoesNotExist): SentryApp.objects.get(pk=self.sentry_app.id) # The QuerySet will automatically NOT include deleted installs, so we # use a raw sql query to ensure it still exists. c = connection.cursor() c.execute( "SELECT count(1) " "FROM sentry_sentryapp " "WHERE id = %s AND date_deleted IS NOT NULL", [self.sentry_app.id], ) assert c.fetchone()[0] == 1 @patch("sentry.analytics.record") def test_records_analytics(self, record): Destroyer.run( user=self.user, sentry_app=self.sentry_app, request=self.make_request(user=self.user, method="GET"), ) record.assert_called_with( "sentry_app.deleted", user_id=self.user.id, organization_id=self.org.id, sentry_app=self.sentry_app.slug, )
class TestDestroyer(TestCase): def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.sentry_app = self.create_sentry_app( name='blah', organization=self.org, scopes=('project:read',), ) self.destroyer = Destroyer(sentry_app=self.sentry_app) def test_deletes_app_installations(self): install = self.create_sentry_app_installation( organization=self.org, slug=self.sentry_app.slug, user=self.user, ) self.destroyer.call() assert not SentryAppInstallation.objects.filter(pk=install.id).exists() def test_deletes_api_application(self): application = self.sentry_app.application self.destroyer.call() assert not ApiApplication.objects.filter(pk=application.id).exists() def test_deletes_proxy_user(self): proxy_user = self.sentry_app.proxy_user self.destroyer.call() assert not User.objects.filter(pk=proxy_user.id).exists() def test_creates_audit_log_entry(self): request = self.make_request(user=self.user, method='GET') Destroyer.run( user=self.user, sentry_app=self.sentry_app, request=request, ) assert AuditLogEntry.objects.filter(event=AuditLogEntryEvent.SENTRY_APP_REMOVE).exists() def test_soft_deletes_sentry_app(self): self.destroyer.call() with self.assertRaises(SentryApp.DoesNotExist): SentryApp.objects.get(pk=self.sentry_app.id) # The QuerySet will automatically NOT include deleted installs, so we # use a raw sql query to ensure it still exists. c = connection.cursor() c.execute( 'SELECT count(1) ' 'FROM sentry_sentryapp ' 'WHERE id = %s AND date_deleted IS NOT NULL', [self.sentry_app.id]) assert c.fetchone()[0] == 1 @patch('sentry.analytics.record') def test_records_analytics(self, record): Destroyer.run( user=self.user, sentry_app=self.sentry_app, request=self.make_request(user=self.user, method='GET'), ) record.assert_called_with( 'sentry_app.deleted', user_id=self.user.id, organization_id=self.org.id, sentry_app=self.sentry_app.slug, )