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,
         ])
示例#2
0
 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.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],
        )
示例#4
0
 def test_creates_audit_log_entry(self):
     request = self.make_request(user=self.user, method='GET')
     Creator.run(
         name='nulldb',
         organization=self.org,
         scopes=('project:read', ),
         webhook_url='http://example.com',
         schema={'elements': [self.create_issue_link_schema()]},
         request=request,
     )
     assert AuditLogEntry.objects.filter(
         event=AuditLogEntryEvent.SENTRY_APP_ADD).exists()
示例#5
0
 def test_creates_audit_log_entry(self):
     request = self.make_request(user=self.user, method='GET')
     Creator.run(
         name='nulldb',
         user=self.user,
         author='Sentry',
         organization=self.org,
         scopes=('project:read',),
         webhook_url='http://example.com',
         schema={'elements': [self.create_issue_link_schema()]},
         request=request,
     )
     assert AuditLogEntry.objects.filter(event=AuditLogEntryEvent.SENTRY_APP_ADD).exists()
示例#6
0
 def test_creates_audit_log_entry(self):
     request = self.make_request(user=self.user, method="GET")
     Creator.run(
         name="nulldb",
         user=self.user,
         author="Sentry",
         organization=self.org,
         scopes=("project:read",),
         webhook_url="http://example.com",
         schema={"elements": [self.create_issue_link_schema()]},
         request=request,
     )
     assert AuditLogEntry.objects.filter(event=AuditLogEntryEvent.SENTRY_APP_ADD).exists()
示例#7
0
    def post(self, request, organization):
        data = {
            'name': request.json_body.get('name'),
            'user': request.user,
            'author': request.json_body.get('author'),
            'organization': self._get_user_org(request),
            'webhookUrl': request.json_body.get('webhookUrl'),
            'redirectUrl': request.json_body.get('redirectUrl'),
            'isAlertable': request.json_body.get('isAlertable'),
            'scopes': request.json_body.get('scopes', []),
            'events': request.json_body.get('events', []),
            'schema': request.json_body.get('schema', {}),
            'overview': request.json_body.get('overview'),
        }

        serializer = SentryAppSerializer(data=data)

        if serializer.is_valid():
            data['redirect_url'] = data['redirectUrl']
            data['webhook_url'] = data['webhookUrl']
            data['is_alertable'] = data['isAlertable']

            sentry_app = Creator.run(
                request=request,
                **data
            )

            return Response(serialize(sentry_app), status=201)
        return Response(serializer.errors, status=400)
示例#8
0
    def post(self, request, organization):
        data = {
            'name': request.json_body.get('name'),
            'user': request.user,
            'author': request.json_body.get('author'),
            'organization': self._get_user_org(request),
            'webhookUrl': request.json_body.get('webhookUrl'),
            'redirectUrl': request.json_body.get('redirectUrl'),
            'isAlertable': request.json_body.get('isAlertable'),
            'scopes': request.json_body.get('scopes', []),
            'events': request.json_body.get('events', []),
            'schema': request.json_body.get('schema', {}),
            'overview': request.json_body.get('overview'),
        }

        serializer = SentryAppSerializer(data=data)

        if serializer.is_valid():
            data['redirect_url'] = data['redirectUrl']
            data['webhook_url'] = data['webhookUrl']
            data['is_alertable'] = data['isAlertable']

            sentry_app = Creator.run(request=request, **data)

            return Response(serialize(sentry_app), status=201)
        return Response(serializer.errors, status=400)
示例#9
0
    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,
        )
示例#10
0
    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,
        )
示例#11
0
    def setUp(self):
        self.user = self.create_user()
        self.sentry_app = Creator.run(
            name='nulldb',
            user=self.user,
            scopes=('project:read',),
            webhook_url='http://example.com',
        )

        self.updater = Updater(sentry_app=self.sentry_app)
示例#12
0
    def setUp(self):
        self.user = self.create_user()
        self.sentry_app = Creator.run(
            name='nulldb',
            user=self.user,
            scopes=('project:read', ),
            webhook_url='http://example.com',
        )

        self.updater = Updater(sentry_app=self.sentry_app)
示例#13
0
 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 = Creator.run(
         name='Test',
         user=self.user,
         scopes=(),
         webhook_url='https://example.com',
     )
     self.published_app.update(status=SentryAppStatus.PUBLISHED)
     self.unpublished_app = Creator.run(
         name='Testin',
         user=self.user,
         scopes=(),
         webhook_url='https://example.com',
     )
     self.url = reverse('sentry-api-0-sentry-apps')
示例#14
0
    def setUp(self):
        self.permission = SentryAppDetailsPermission()
        self.user = self.create_user()
        self.sentry_app = SentryAppCreator.run(
            name='foo',
            user=self.user,
            scopes=(),
            webhook_url='https://example.com',
        )

        self.request = HttpRequest()
        self.request.user = self.user
示例#15
0
    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')
示例#16
0
    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')
示例#17
0
    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)
示例#18
0
    def test_doesnt_update_published_app_scopes(self):
        sentry_app = Creator.run(
            name='sentry',
            organization=self.org,
            scopes=('project:read',),
            webhook_url='http://example.com',
        )
        sentry_app.update(status=SentryAppStatus.PUBLISHED)
        updater = Updater(sentry_app=sentry_app)
        updater.scopes = ('project:read', 'project:write', )

        with self.assertRaises(APIError):
            updater.call()
示例#19
0
    def setUp(self):
        super(TestClientIdSecretAuthentication, self).setUp()

        self.auth = ClientIdSecretAuthentication()

        self.sentry_app = Creator.run(
            name="foo",
            user=self.user,
            scopes=(),
            webhook_url='https://example.com',
        )

        self.api_app = self.sentry_app.application
示例#20
0
    def post(self, request):
        serializer = SentryAppSerializer(data=request.json_body)

        if not serializer.is_valid():
            return Response({'errors': serializer.errors}, status=422)

        sentry_app = Creator.run(
            name=request.json_body.get('name'),
            organization=self._get_user_org(request),
            scopes=request.json_body.get('scopes'),
            webhook_url=request.json_body.get('webhook_url'),
        )

        return Response(serialize(sentry_app), status=201)
示例#21
0
    def setUp(self):
        self.superuser = self.create_user(email='*****@*****.**', is_superuser=True)
        self.super_org = self.create_organization(owner=self.superuser)

        self.user = self.create_user(email='*****@*****.**')
        self.org = self.create_organization(owner=self.user)

        self.published_app = Creator.run(
            name='Test',
            organization=self.org,
            scopes=(),
            webhook_url='https://example.com',
        )
        self.published_app.update(status=SentryAppStatus.PUBLISHED)

        self.unpublished_app = Creator.run(
            name='Testin',
            organization=self.org,
            scopes=(),
            webhook_url='https://example.com',
        )

        self.url = reverse('sentry-api-0-sentry-apps')
示例#22
0
    def post(self, request):
        serializer = SentryAppSerializer(data=request.json_body)

        if not serializer.is_valid():
            return Response({'errors': serializer.errors}, status=422)

        sentry_app = Creator.run(
            name=request.json_body.get('name'),
            organization=self._get_user_org(request),
            scopes=request.json_body.get('scopes'),
            webhook_url=request.json_body.get('webhook_url'),
        )

        return Response(serialize(sentry_app), status=201)
示例#23
0
    def setUp(self):
        self.endpoint = SentryAppDetailsEndpoint()

        self.user = self.create_user()
        self.request = HttpRequest()
        self.request.user = self.user
        self.request.successful_authenticator = True

        self.sentry_app = SentryAppCreator.run(
            name='foo',
            user=self.user,
            scopes=(),
            webhook_url='https://example.com',
        )
示例#24
0
    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)
示例#25
0
    def test_records_analytics(self, record):
        sentry_app = Creator.run(
            name='nulldb',
            user=self.user,
            author='Sentry',
            organization=self.org,
            scopes=('project:read', ),
            webhook_url='http://example.com',
            schema={'elements': [self.create_issue_link_schema()]},
            request=self.make_request(user=self.user, method='GET'))

        record.assert_called_with(
            'sentry_app.created',
            user_id=self.user.id,
            organization_id=self.org.id,
            sentry_app=sentry_app.slug,
        )
示例#26
0
    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)
示例#27
0
    def test_records_analytics(self, record):
        sentry_app = Creator.run(
            name='nulldb',
            user=self.user,
            author='Sentry',
            organization=self.org,
            scopes=('project:read',),
            webhook_url='http://example.com',
            schema={'elements': [self.create_issue_link_schema()]},
            request=self.make_request(user=self.user, method='GET')
        )

        record.assert_called_with(
            'sentry_app.created',
            user_id=self.user.id,
            organization_id=self.org.id,
            sentry_app=sentry_app.slug,
        )
示例#28
0
    def test_records_analytics(self, record):
        sentry_app = Creator.run(
            name="nulldb",
            user=self.user,
            author="Sentry",
            organization=self.org,
            scopes=("project:read",),
            webhook_url="http://example.com",
            schema={"elements": [self.create_issue_link_schema()]},
            request=self.make_request(user=self.user, method="GET"),
        )

        record.assert_called_with(
            "sentry_app.created",
            user_id=self.user.id,
            organization_id=self.org.id,
            sentry_app=sentry_app.slug,
        )
示例#29
0
 def test_cannot_update_non_owned_apps(self):
     self.login_as(user=self.user)
     app = Creator.run(
         name='SampleApp',
         organization=self.super_org,
         scopes=(),
         webhook_url='https://sample.com',
     )
     url = reverse('sentry-api-0-sentry-app-details', args=[app.slug])
     response = self.client.put(
         url,
         data={
             'name': 'NewName',
             'webhook_url': 'https://newurl.com',
         },
         format='json',
     )
     assert response.status_code == 403
示例#30
0
    def post(self, request, organization):
        serializer = SentryAppSerializer(data=request.json_body)

        if serializer.is_valid():
            result = serializer.object

            sentry_app = Creator.run(
                name=result.get('name'),
                organization=self._get_user_org(request),
                scopes=result.get('scopes'),
                events=result.get('events'),
                webhook_url=result.get('webhookUrl'),
                redirect_url=result.get('redirectUrl'),
                is_alertable=result.get('isAlertable'),
                overview=result.get('overview'),
            )

            return Response(serialize(sentry_app), status=201)

        return Response({'errors': serializer.errors}, status=422)
示例#31
0
    def create_sentry_app(self, name=None, organization=None, published=False, scopes=(),
                          webhook_url=None, **kwargs):
        if not name:
            name = 'Test App'
        if not organization:
            organization = self.create_organization()
        if not webhook_url:
            webhook_url = 'https://example.com/webhook'

        app = SentryAppCreator.run(
            name=name,
            organization=organization,
            scopes=scopes,
            webhook_url=webhook_url,
            **kwargs
        )
        if published:
            app.update(status=SentryAppStatus.PUBLISHED)

        return app
示例#32
0
    def post(self, request, organization):
        serializer = SentryAppSerializer(data=request.json_body)

        if serializer.is_valid():
            result = serializer.object

            sentry_app = Creator.run(
                name=result.get('name'),
                organization=self._get_user_org(request),
                scopes=result.get('scopes'),
                events=result.get('events'),
                webhook_url=result.get('webhookUrl'),
                redirect_url=result.get('redirectUrl'),
                is_alertable=result.get('isAlertable'),
                overview=result.get('overview'),
            )

            return Response(serialize(sentry_app), status=201)

        return Response(serializer.errors, status=422)
    def test_install_unpublished_app(self):
        self.login_as(user=self.user)
        app = SentryAppCreator.run(
            name='Sample',
            organization=self.org,
            scopes=(),
            webhook_url='https://example.com',
        )
        response = self.client.post(
            self.url,
            data={'slug': app.slug},
            format='json',
        )
        expected = {
            'app': app.slug,
            'organization': self.org.slug,
        }

        assert response.status_code == 200, response.content
        assert six.viewitems(expected) <= six.viewitems(response.data)
示例#34
0
    def test_install_unpublished_app(self):
        self.login_as(user=self.user)
        app = SentryAppCreator.run(
            name='Sample',
            organization=self.org,
            scopes=(),
            webhook_url='https://example.com',
        )
        response = self.client.post(
            self.url,
            data={'slug': app.slug},
            format='json',
        )
        expected = {
            'app': app.slug,
            'organization': self.org.slug,
        }

        assert response.status_code == 200, response.content
        assert six.viewitems(expected) <= six.viewitems(response.data)
 def test_members_cannot_install_apps(self):
     user = self.create_user('*****@*****.**')
     self.create_member(
         organization=self.org,
         user=user,
         role='member',
     )
     self.login_as(user)
     app = SentryAppCreator.run(
         name='Sample',
         organization=self.org,
         scopes=(),
         webhook_url='https://example.com',
     )
     app.update(status=SentryAppStatus.PUBLISHED)
     response = self.client.post(
         self.url,
         data={'slug': app.slug},
         format='json',
     )
     assert response.status_code == 403
示例#36
0
    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 = 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,
        )
示例#37
0
    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
示例#38
0
 def test_members_cannot_install_apps(self):
     user = self.create_user('*****@*****.**')
     self.create_member(
         organization=self.org,
         user=user,
         role='member',
     )
     self.login_as(user)
     app = SentryAppCreator.run(
         name='Sample',
         organization=self.org,
         scopes=(),
         webhook_url='https://example.com',
     )
     app.update(status=SentryAppStatus.PUBLISHED)
     response = self.client.post(
         self.url,
         data={'slug': app.slug},
         format='json',
     )
     assert response.status_code == 403
示例#39
0
    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,
        )
示例#40
0
    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,
        )