def setUp(self): self.superuser = self.create_user(email='*****@*****.**', is_superuser=True) self.user = self.create_user(email='*****@*****.**') self.org = self.create_organization(owner=self.user) self.super_org = self.create_organization(owner=self.superuser) self.published_app = SentryAppCreator.run( name='Test', organization=self.super_org, scopes=(), webhook_url='https://example.com', ) self.published_app.update(status=SentryAppStatus.PUBLISHED) self.installation, _ = Creator.run( slug=self.published_app.slug, organization=self.super_org, ) self.unpublished_app = SentryAppCreator.run( name='Testin', organization=self.org, scopes=(), webhook_url='https://example.com', ) self.installation2, _ = Creator.run( slug=self.unpublished_app.slug, organization=self.org, ) self.url = reverse( 'sentry-api-0-organization-sentry-app-installations', args=[self.org.slug])
def setUp(self): self.superuser = self.create_user(email='*****@*****.**', is_superuser=True) self.user = self.create_user(email='*****@*****.**') self.org = self.create_organization(owner=self.user) self.super_org = self.create_organization(owner=self.superuser) self.published_app = SentryAppCreator.run( name='Test', organization=self.super_org, scopes=(), webhook_url='https://example.com', ) self.published_app.update(status=SentryAppStatus.PUBLISHED) self.installation, _ = Creator.run( slug=self.published_app.slug, organization=self.super_org, ) self.unpublished_app = SentryAppCreator.run( name='Testin', organization=self.org, scopes=(), webhook_url='https://example.com', ) self.installation2, _ = Creator.run( slug=self.unpublished_app.slug, organization=self.org, ) self.url = reverse( 'sentry-api-0-organization-sentry-app-installations-details', args=[ self.org.slug, self.installation2.uuid, ])
def setUp(self): self.superuser = self.create_user(email='*****@*****.**', is_superuser=True) self.user = self.create_user(email='*****@*****.**') self.org = self.create_organization(owner=self.user) self.super_org = self.create_organization(owner=self.superuser) self.published_app = self.create_sentry_app( name='Test', organization=self.super_org, published=True, ) self.installation = Creator.run( slug=self.published_app.slug, organization=self.super_org, user=self.superuser, ) self.unpublished_app = self.create_sentry_app( name='Testin', organization=self.org, ) self.installation2 = Creator.run( slug=self.unpublished_app.slug, organization=self.org, user=self.user, ) self.url = reverse( 'sentry-api-0-sentry-app-installation-details', args=[self.installation2.uuid], )
class TestCreator(TestCase): def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.sentry_app = self.create_sentry_app( name='nulldb', organization=self.org, scopes=('project:read', ), ) self.creator = Creator(organization=self.org, slug='nulldb') def test_creates_api_authorization(self): install, grant = self.creator.call() assert ApiAuthorization.objects.get( application=self.sentry_app.application, user=self.sentry_app.proxy_user, scopes=self.sentry_app.scopes, ) def test_creates_installation(self): install, grant = self.creator.call() assert install.pk def test_creates_api_grant(self): install, grant = self.creator.call() assert grant.pk def test_associations(self): install, grant = self.creator.call() assert install.api_grant == grant assert install.authorization is not None
def setUp(self): self.superuser = self.create_user(email='*****@*****.**', is_superuser=True) self.user = self.create_user(email='*****@*****.**') self.org = self.create_organization(owner=self.user) self.super_org = self.create_organization(owner=self.superuser) self.published_app = self.create_sentry_app( name='Test', organization=self.super_org, published=True, ) self.installation, _ = Creator.run( slug=self.published_app.slug, organization=self.super_org, user=self.superuser, ) self.unpublished_app = self.create_sentry_app( name='Testin', organization=self.org, ) self.installation2, _ = Creator.run( slug=self.unpublished_app.slug, organization=self.org, user=self.user, ) self.url = reverse( 'sentry-api-0-sentry-app-installation-details', args=[self.installation2.uuid], )
def test_creates_audit_log_entry(self): responses.add(responses.POST, "https://example.com/webhook") request = self.make_request(user=self.user, method="GET") Creator.run(organization=self.org, slug="nulldb", user=self.user, request=request) assert AuditLogEntry.objects.filter( event=AuditLogEntryEvent.SENTRY_APP_INSTALL).exists()
def test_creates_audit_log_entry(self): responses.add(responses.POST, 'https://example.com/webhook') request = self.make_request(user=self.user, method='GET') Creator.run( organization=self.org, slug='nulldb', user=self.user, request=request, ) assert AuditLogEntry.objects.filter(event=AuditLogEntryEvent.SENTRY_APP_INSTALL).exists()
def test_installed_status(self): responses.add(responses.POST, "https://example.com/webhook") internal_app = self.create_internal_integration(name="internal", organization=self.org) creator = Creator(organization=self.org, slug=internal_app.slug, user=self.user) install = creator.call() assert install.status == SentryAppInstallationStatus.INSTALLED
def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.sentry_app = self.create_sentry_app( name='nulldb', organization=self.org, scopes=('project:read', ), ) self.creator = Creator(organization=self.org, slug='nulldb')
def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.sentry_app = SentryAppCreator.run( name='nulldb', user=self.user, scopes=('project:read', ), webhook_url='http://example.com', ) self.creator = Creator(organization=self.org, slug='nulldb')
def test_records_analytics(self, record): Creator.run( organization=self.org, slug="nulldb", user=self.user, request=self.make_request(user=self.user, method="GET"), ) record.assert_called_with( "sentry_app.installed", user_id=self.user.id, organization_id=self.org.id, sentry_app="nulldb", )
def test_records_analytics(self, record): Creator.run( organization=self.org, slug='nulldb', user=self.user, request=self.make_request(user=self.user, method='GET'), ) record.assert_called_with( 'sentry_app.installed', user_id=self.user.id, organization_id=self.org.id, sentry_app='nulldb', )
def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.sentry_app = SentryAppCreator.run( name='nulldb', organization=self.create_organization(), scopes=('org:read', ), webhook_url='http://example.com', ) self.other_sentry_app = SentryAppCreator.run( name='slowdb', organization=self.create_organization(), scopes=(), webhook_url='http://example.com', ) self.install, self.grant = SentryAppInstallationCreator.run( organization=self.org, slug='nulldb', user=self.user, ) self.url = reverse( 'sentry-api-0-sentry-app-authorizations', args=[self.install.uuid], )
def setUp(self): super(FromSentryAppTest, self).setUp() # Partner's normal Sentry account. self.user = self.create_user('*****@*****.**') self.org = self.create_organization() self.out_of_scope_org = self.create_organization() self.team = self.create_team(organization=self.org) self.out_of_scope_team = self.create_team( organization=self.out_of_scope_org ) self.sentry_app = SentryAppCreator.run( name='SlowDB', organization=self.org, scopes=(), webhook_url='http://example.com', ) self.proxy_user = self.sentry_app.proxy_user self.install = SentryAppInstallationCreator.run( organization=self.org, slug=self.sentry_app.slug, )
def setUp(self): super(FromSentryAppTest, self).setUp() # Partner's normal Sentry account. self.user = self.create_user('*****@*****.**') self.org = self.create_organization() self.out_of_scope_org = self.create_organization() self.team = self.create_team(organization=self.org) self.out_of_scope_team = self.create_team( organization=self.out_of_scope_org) self.sentry_app = SentryAppCreator.run( name='SlowDB', organization=self.org, scopes=(), webhook_url='http://example.com', ) self.proxy_user = self.sentry_app.proxy_user self.install = SentryAppInstallationCreator.run( organization=self.org, slug=self.sentry_app.slug, )
class TestCreator(TestCase): def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.sentry_app = self.create_sentry_app( name='nulldb', organization=self.org, scopes=('project:read', ), ) self.creator = Creator( organization=self.org, slug='nulldb', user=self.user, ) def test_creates_api_authorization(self): install, grant = self.creator.call() assert ApiAuthorization.objects.get( application=self.sentry_app.application, user=self.sentry_app.proxy_user, scopes=self.sentry_app.scopes, ) def test_creates_installation(self): install, grant = self.creator.call() assert install.pk def test_creates_api_grant(self): install, grant = self.creator.call() assert grant.pk @patch('sentry.tasks.app_platform.installation_webhook.delay') def test_notifies_service(self, installation_webhook): install, _ = self.creator.call() installation_webhook.assert_called_once_with(install.id, self.user.id) def test_associations(self): install, grant = self.creator.call() assert install.api_grant == grant assert install.authorization is not None
def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.project1 = self.create_project(organization=self.org) self.project2 = self.create_project(organization=self.org) self.sentry_app = self.create_sentry_app( name='nulldb', organization=self.org, scopes=('project:read', ), events=('issue.created', ), ) self.creator = Creator( organization=self.org, slug='nulldb', user=self.user, )
def setUp(self): super().setUp() self.sentry_app = self.create_sentry_app( name="external_app", organization=self.org, scopes=("org:write", "team:admin") ) self.sentry_app_installation = SentryAppInstallationCreator.run( slug=(self.sentry_app.slug), organization=self.org, user=(self.user) )
def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.project1 = self.create_project(organization=self.org) self.project2 = self.create_project(organization=self.org) responses.add(responses.POST, "https://example.com/webhook") self.sentry_app = self.create_sentry_app( name="nulldb", organization=self.org, scopes=("project:read", ), events=("issue.created", ), ) self.creator = Creator(organization=self.org, slug="nulldb", user=self.user)
def post(self, request, organization): serializer = OrganizationSentryAppInstallationsSerializer(data=request.DATA) if not serializer.is_valid(): return Response(serializer.errors, status=400) slug = serializer.object.get('slug') install, _ = Creator.run( organization=organization, slug=slug, ) return Response(serialize(install))
def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.project1 = self.create_project(organization=self.org) self.project2 = self.create_project(organization=self.org) responses.add(responses.POST, 'https://example.com/webhook') self.sentry_app = self.create_sentry_app( name='nulldb', organization=self.org, scopes=('project:read', ), events=('issue.created', ), ) self.creator = Creator( organization=self.org, slug='nulldb', user=self.user, )
def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.sentry_app = SentryAppCreator.run( name='nulldb', user=self.user, scopes=('project:read',), webhook_url='http://example.com', ) self.creator = Creator(organization=self.org, slug='nulldb')
def post(self, request, organization): serializer = SentryAppInstallationsSerializer(data=request.data) if not serializer.is_valid(): return Response(serializer.errors, status=400) install = Creator.run( organization=organization, slug=serializer.validated_data.get('slug'), user=request.user, ) return Response(serialize(install))
def setUp(self): super(TestCreatorExternal, self).setUp() self.sentry_app = self.create_sentry_app( name='external_app', organization=self.org, scopes=('org:write', 'team:admin'), ) self.sentry_app_installation = SentryAppInstallationCreator.run( slug=(self.sentry_app.slug), organization=self.org, user=(self.user), )
def test_invalid_installation(self): self.install, _ = SentryAppInstallationCreator.run( organization=self.org, slug='slowdb', ) # URL with this new Install's uuid in it self.url = reverse( 'sentry-api-0-sentry-app-authorizations', args=[self.install.uuid], ) response = self._run_request() assert response.status_code == 403
class TestCreator(TestCase): def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.sentry_app = SentryAppCreator.run( name='nulldb', user=self.user, scopes=('project:read',), webhook_url='http://example.com', ) self.creator = Creator(organization=self.org, slug='nulldb') def test_creates_api_authorization(self): install, grant = self.creator.call() assert ApiAuthorization.objects.get( application=self.sentry_app.application, user=self.sentry_app.proxy_user, scopes=self.sentry_app.scopes, ) def test_creates_installation(self): install, grant = self.creator.call() assert install.pk def test_creates_api_grant(self): install, grant = self.creator.call() assert grant.pk def test_associations(self): install, grant = self.creator.call() assert install.api_grant == grant assert install.authorization is not None
def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.sentry_app = self.create_sentry_app( name='nulldb', organization=self.org, scopes=('project:read', ), ) self.install, self.grant = Creator.run( organization=self.org, slug='nulldb', ) self.destroyer = Destroyer(install=self.install)
def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.sentry_app = SentryAppCreator.run( name='nulldb', organization=self.org, scopes=('project:read', ), webhook_url='https://example.com', ) self.install, self.grant = Creator.run( organization=self.org, slug='nulldb', ) self.destroyer = Destroyer(install=self.install)
def setUp(self): self.endpoint = SentryAppInstallationBaseEndpoint() self.user = self.create_user() self.org = self.create_organization(owner=self.user) self.request = self.make_request(user=self.user, method='GET') self.sentry_app = self.create_sentry_app( name='foo', organization=self.org, ) self.installation, _ = SentryAppInstallationCreator.run( slug=self.sentry_app.slug, organization=self.org, )
def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.sentry_app = self.create_sentry_app( name='nulldb', organization=self.org, scopes=('project:read',), ) self.install = Creator.run( organization=self.org, slug='nulldb', user=self.user, ) self.destroyer = Destroyer(install=self.install)
def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.sentry_app = SentryAppCreator.run( name='nulldb', user=self.user, scopes=('project:read',), webhook_url='https://example.com', ) self.install, self.grant = Creator.run( organization=self.org, slug='nulldb', ) self.destroyer = Destroyer(install=self.install)
def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.project = self.create_project(organization=self.org) responses.add(responses.POST, "https://example.com/webhook") self.sentry_app = self.create_sentry_app( name="nulldb", organization=self.org, scopes=("project:read", "event:read"), events=("issue",), ) self.install = Creator.run(organization=self.org, slug="nulldb", user=self.user) self.destroyer = Destroyer(install=self.install, user=self.user)
def setUp(self): super(TestInstallationNotifier, self).setUp() self.user = self.create_user(name='foo') self.org = self.create_organization(owner=self.user) self.sentry_app = sentry_apps.Creator.run( name='foo', organization=self.org, webhook_url='https://example.com', scopes=(), ) self.install = Creator.run( slug='foo', organization=self.org, user=self.user, )
def post(self, request, organization): serializer = SentryAppInstallationsSerializer(data=request.data) if not serializer.is_valid(): return Response(serializer.errors, status=400) # check for an exiting installation and return that if it exists slug = serializer.validated_data.get("slug") try: install = SentryAppInstallation.objects.get( sentry_app__slug=slug, organization=organization ) except SentryAppInstallation.DoesNotExist: install = Creator.run( organization=organization, slug=slug, user=request.user, request=request ) return Response(serialize(install))
def setUp(self): self.permission = SentryAppInstallationDetailsPermission() self.user = self.create_user() self.member = self.create_user() self.org = self.create_organization(owner=self.member) self.sentry_app = self.create_sentry_app( name='foo', organization=self.org, ) self.installation, _ = SentryAppInstallationCreator.run( slug=self.sentry_app.slug, organization=self.org, ) self.request = HttpRequest() self.request.user = self.user
def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.project1 = self.create_project(organization=self.org) self.project2 = self.create_project(organization=self.org) self.sentry_app = self.create_sentry_app( name='nulldb', organization=self.org, scopes=('project:read',), events=('issue.created', ), ) self.creator = Creator( organization=self.org, slug='nulldb', user=self.user, )
def setUp(self): self.endpoint = SentryAppInstallationDetailsEndpoint() self.user = self.create_user() self.org = self.create_organization(owner=self.user) self.request = HttpRequest() self.request.user = self.user self.request.successful_authenticator = True self.sentry_app = self.create_sentry_app( name='foo', organization=self.org, ) self.installation, _ = SentryAppInstallationCreator.run( slug=self.sentry_app.slug, organization=self.org, )
def setUp(self): self.permission = SentryAppInstallationPermission() self.user = self.create_user() self.member = self.create_user() self.org = self.create_organization(owner=self.member) self.sentry_app = self.create_sentry_app( name='foo', organization=self.org, ) self.installation = SentryAppInstallationCreator.run( slug=self.sentry_app.slug, organization=self.org, user=self.user, ) self.request = self.make_request(user=self.user, method='GET')
def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.project1 = self.create_project(organization=self.org) self.project2 = self.create_project(organization=self.org) responses.add(responses.POST, 'https://example.com/webhook') self.sentry_app = self.create_sentry_app( name='nulldb', organization=self.org, scopes=('project:read',), events=('issue.created', ), ) self.creator = Creator( organization=self.org, slug='nulldb', user=self.user, )
def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.sentry_app = self.create_sentry_app( name='nulldb', organization=self.org, ) self.install, self.grant = Creator.run( organization=self.org, slug='nulldb', ) self.authorizer = Authorizer( install=self.install, grant_type='authorization_code', code=self.grant.code, client_id=self.sentry_app.application.client_id, user=self.sentry_app.proxy_user, )
def setUp(self): self.permission = SentryAppInstallationDetailsPermission() self.user = self.create_user() self.member = self.create_user() self.org = self.create_organization(owner=self.member) self.sentry_app = SentryAppCreator.run( name='foo', user=self.user, scopes=(), webhook_url='https://example.com', ) self.installation, _ = SentryAppInstallationCreator.run( slug=self.sentry_app.slug, organization=self.org, ) self.request = HttpRequest() self.request.user = self.user
def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.sentry_app = SentryAppCreator.run( name='nulldb', organization=self.org, scopes=(), webhook_url='http://example.com', ) self.install, self.grant = Creator.run( organization=self.org, slug='nulldb', ) self.authorizer = Authorizer( install=self.install, grant_type='authorization_code', code=self.grant.code, client_id=self.sentry_app.application.client_id, user=self.sentry_app.proxy_user, )
def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.project = self.create_project(organization=self.org) responses.add(responses.POST, 'https://example.com/webhook') self.sentry_app = self.create_sentry_app( name='nulldb', organization=self.org, scopes=('project:read', 'event:read'), events=('issue',), ) self.install = Creator.run( organization=self.org, slug='nulldb', user=self.user, ) self.destroyer = Destroyer( install=self.install, user=self.user, )
class TestCreator(TestCase): def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.project1 = self.create_project(organization=self.org) self.project2 = self.create_project(organization=self.org) responses.add(responses.POST, 'https://example.com/webhook') self.sentry_app = self.create_sentry_app( name='nulldb', organization=self.org, scopes=('project:read',), events=('issue.created', ), ) self.creator = Creator( organization=self.org, slug='nulldb', user=self.user, ) @responses.activate def test_creates_installation(self): responses.add(responses.POST, 'https://example.com/webhook') install = self.creator.call() assert install.pk @responses.activate def test_creates_api_grant(self): responses.add(responses.POST, 'https://example.com/webhook') install = self.creator.call() assert ApiGrant.objects.filter(id=install.api_grant_id).exists() @responses.activate def test_creates_service_hooks(self): responses.add(responses.POST, 'https://example.com/webhook') install = self.creator.call() hook = ServiceHook.objects.get(organization_id=self.org.id) assert hook.application_id == self.sentry_app.application.id assert hook.actor_id == install.id assert hook.organization_id == self.org.id assert hook.events == self.sentry_app.events assert hook.url == self.sentry_app.webhook_url assert not ServiceHookProject.objects.all() @responses.activate def test_creates_audit_log_entry(self): responses.add(responses.POST, 'https://example.com/webhook') request = self.make_request(user=self.user, method='GET') Creator.run( organization=self.org, slug='nulldb', user=self.user, request=request, ) assert AuditLogEntry.objects.filter(event=AuditLogEntryEvent.SENTRY_APP_INSTALL).exists() @responses.activate @patch('sentry.mediators.sentry_app_installations.InstallationNotifier.run') def test_notifies_service(self, run): with self.tasks(): responses.add(responses.POST, 'https://example.com/webhook') install = self.creator.call() run.assert_called_once_with(install=install, user=self.user, action='created') @responses.activate def test_associations(self): responses.add(responses.POST, 'https://example.com/webhook') install = self.creator.call() assert install.api_grant is not None @patch('sentry.analytics.record') def test_records_analytics(self, record): Creator.run( organization=self.org, slug='nulldb', user=self.user, request=self.make_request(user=self.user, method='GET'), ) record.assert_called_with( 'sentry_app.installed', user_id=self.user.id, organization_id=self.org.id, sentry_app='nulldb', )
class TestCreator(TestCase): def setUp(self): self.user = self.create_user() self.org = self.create_organization() self.project1 = self.create_project(organization=self.org) self.project2 = self.create_project(organization=self.org) self.sentry_app = self.create_sentry_app( name='nulldb', organization=self.org, scopes=('project:read',), events=('issue.created', ), ) self.creator = Creator( organization=self.org, slug='nulldb', user=self.user, ) def test_creates_api_authorization(self): self.creator.call() assert ApiAuthorization.objects.filter( application=self.sentry_app.application, user=self.sentry_app.proxy_user, scopes=self.sentry_app.scopes, ).exists() def test_creates_installation(self): install = self.creator.call() assert install.pk def test_creates_api_grant(self): install = self.creator.call() assert ApiGrant.objects.filter(id=install.api_grant_id).exists() def test_creates_service_hooks(self): install = self.creator.call() hook = ServiceHook.objects.get(project_id=self.project1.id) assert hook.application_id == self.sentry_app.application.id assert hook.actor_id == install.id assert hook.project_id == self.project1.id assert hook.events == self.sentry_app.events assert hook.url == self.sentry_app.webhook_url def test_creates_service_hooks_for_all_projects(self): self.creator.call() assert ServiceHook.objects.get(project_id=self.project1.id).events == self.sentry_app.events assert ServiceHook.objects.get(project_id=self.project2.id).events == self.sentry_app.events @patch('sentry.tasks.app_platform.installation_webhook.delay') def test_notifies_service(self, installation_webhook): install = self.creator.call() installation_webhook.assert_called_once_with(install.id, self.user.id) def test_associations(self): install = self.creator.call() assert install.api_grant is not None assert install.authorization is not None