Esempio n. 1
0
    def test_create_release(self):
        responses.add(
            responses.POST,
            absolute_uri("/api/0/organizations/%s/releases/" % self.organization.slug),
            json={},
        )

        with override_options({"vercel.client-secret": SECRET}):
            response = self._get_response(EXAMPLE_DEPLOYMENT_WEBHOOK_RESPONSE, SIGNATURE)

            assert response.status_code == 201

            assert len(responses.calls) == 2
            release_request = responses.calls[0].request
            release_body = json.loads(release_request.body)
            set_refs_body = json.loads(responses.calls[1].request.body)
            assert release_body == {
                "projects": [self.project.slug],
                "version": "7488658dfcf24d9b735e015992b316e2a8340d9d",
            }
            assert set_refs_body == {
                "projects": [self.project.slug],
                "version": "7488658dfcf24d9b735e015992b316e2a8340d9d",
                "refs": [
                    {
                        "commit": "7488658dfcf24d9b735e015992b316e2a8340d9d",
                        "repository": "MeredithAnya/nextjsblog-demo",
                    }
                ],
            }
            assert release_request.headers["User-Agent"] == f"sentry_vercel/{VERSION}"
Esempio n. 2
0
    def test_create_release(self):
        responses.add(
            responses.POST,
            absolute_uri("/api/0/organizations/%s/releases/" %
                         self.organization.slug),
            json={},
        )

        with override_options({"vercel.client-secret": secret}):
            response = self.client.post(
                path=webhook_url,
                data=EXAMPLE_DEPLOYMENT_WEBHOOK_RESPONSE,
                content_type="application/json",
                HTTP_X_ZEIT_SIGNATURE=signature,
            )

            assert response.status_code == 201

            assert len(responses.calls) == 2
            release_body = json.loads(responses.calls[0].request.body)
            set_refs_body = json.loads(responses.calls[1].request.body)
            assert release_body == {
                "projects": [self.project.slug],
                "version": "7488658dfcf24d9b735e015992b316e2a8340d9d",
            }
            assert set_refs_body == {
                "projects": [self.project.slug],
                "version":
                "7488658dfcf24d9b735e015992b316e2a8340d9d",
                "refs": [{
                    "commit": "7488658dfcf24d9b735e015992b316e2a8340d9d",
                    "repository": "MeredithAnya/nextjsblog-demo",
                }],
            }
Esempio n. 3
0
 def test_install_v2(self):
     with override_options(
         {"slack-v2.client-id": "other-id", "slack-v2.client-secret": "other-secret"}
     ):
         self.assert_setup_flow(
             expected_client_id="other-id",
             expected_client_secret="other-secret",
         )
Esempio n. 4
0
    def test_signing_secret(self):
        with override_options({"slack.signing-secret": "secret"}):
            self.request.data = {"challenge": "abc123", "type": "url_verification"}

            # we get a url encoded body with Slack
            self.request.body = urlencode(self.request.data)

            self.set_signature(options.get("slack.signing-secret"), self.request.body)
            self.slack_request.validate()
    def test_sources_ignored_alias(self, sources, reversed_alias_map):
        with override_options({"symbolicator.ignored_sources":
                               ["sentry:ios"]}):
            sources = filter_ignored_sources(sources, reversed_alias_map)

            source_ids = list(map(lambda s: s["id"], sources))
            assert source_ids == [
                "sentry:microsoft", "sentry:electron", "custom"
            ]
Esempio n. 6
0
 def test_install_v2(self):
     with override_options(
         {"slack-v2.client-id": "other-id", "slack-v2.client-secret": "other-secret"}
     ):
         self.assert_setup_flow(
             is_wst_app=False,
             access_token="xoxa-xxxxxxxxx-xxxxxxxxxx-xxxxxxxxxxxx",
             expected_client_id="other-id",
             expected_client_secret="other-secret",
         )
Esempio n. 7
0
    def test_valid_signature(self):
        with override_options({"vercel.client-secret": secret}):
            response = self.client.post(
                path=self.url,
                data=EXAMPLE_DEPLOYMENT_WEBHOOK_RESPONSE,
                content_type="application/json",
                HTTP_X_ZEIT_SIGNATURE=signature,
            )

            assert response.status_code == 200
Esempio n. 8
0
    def test_invalid_signature(self):
        with override_options({"vercel.client-secret": SECRET}):
            response = self.client.post(
                path=self.webhook_url,
                data=EXAMPLE_DEPLOYMENT_WEBHOOK_RESPONSE,
                content_type="application/json",
                HTTP_X_ZEIT_SIGNATURE="xxxinvalidsignaturexxx",
            )

            assert response.status_code == 401
Esempio n. 9
0
    def test_use_verification_token(self):
        with override_options({"slack.signing-secret": None}):
            self.request.data = {
                "token": options.get("slack.verification-token"),
                "challenge": "abc123",
                "type": "url_verification",
            }
            self.request.body = json.dumps(self.request.data).encode("utf-8")

            self.slack_request.validate()
    def test_sources_ignored_custom(self, sources):
        with override_options({"symbolicator.ignored_sources": ["custom"]}):
            sources = filter_ignored_sources(sources)

            source_ids = map(lambda s: s["id"], sources)
            assert source_ids == [
                "sentry:microsoft",
                "sentry:electron",
                "sentry:ios-source",
                "sentry:tvos-source",
            ]
Esempio n. 11
0
    def test_uninstall(self):
        with override_options({"vercel.client-secret": SECRET}):
            response = self.client.post(
                path=self.url,
                data=POST_DELETE_RESPONSE,
                content_type="application/json",
                HTTP_X_VERCEL_SIGNATURE="9fe7776332998c90980cc537b24b196f37e17c99",
            )

            assert response.status_code == 204
            assert not Integration.objects.filter(id=self.integration.id).exists()
            assert not OrganizationIntegration.objects.filter(
                integration_id=self.integration.id, organization_id=self.organization.id
            ).exists()
Esempio n. 12
0
    def test_no_installation(self):
        responses.add(
            responses.POST,
            absolute_uri("/api/0/organizations/%s/releases/" % self.organization.slug),
            json={},
        )
        self.installation_for_provider.delete()

        with override_options({"vercel.client-secret": SECRET}):
            response = self._get_response(EXAMPLE_DEPLOYMENT_WEBHOOK_RESPONSE, SIGNATURE)

            assert len(responses.calls) == 0
            assert response.status_code == 404
            assert response.data["detail"] == "Installation not found"
Esempio n. 13
0
    def test_create_release_fails(self):
        responses.add(
            responses.POST,
            absolute_uri("/api/0/organizations/%s/releases/" % self.organization.slug),
            json={},
            status=400,
        )

        with override_options({"vercel.client-secret": SECRET}):
            response = self._get_response(EXAMPLE_DEPLOYMENT_WEBHOOK_RESPONSE, SIGNATURE)

            assert len(responses.calls) == 1
            assert response.status_code == 400
            assert "Error creating release" in response.data["detail"]
Esempio n. 14
0
    def test_signing_secret_bad(self):
        with override_options({"slack.signing-secret": "secret"}):
            # even though we provide the token, should still fail
            self.request.data = {
                "token": options.get("slack.verification-token"),
                "challenge": "abc123",
                "type": "url_verification",
            }
            self.request.body = urlencode(self.request.data).encode("utf-8")

            self.set_signature("bad_key", self.request.body)
            with self.assertRaises(SlackRequestError) as e:
                self.slack_request.validate()
                assert e.status == 401
Esempio n. 15
0
    def test_release_already_created(self):
        responses.add(
            responses.POST,
            absolute_uri("/api/0/organizations/%s/releases/" % self.organization.slug),
            json={},
        )

        self.create_release(
            project=self.project, version="7488658dfcf24d9b735e015992b316e2a8340d9d"
        )

        with override_options({"vercel.client-secret": SECRET}):
            response = self._get_response(EXAMPLE_DEPLOYMENT_WEBHOOK_RESPONSE, SIGNATURE)

            assert response.status_code == 201
Esempio n. 16
0
    def test_no_match(self):
        responses.add(
            responses.POST,
            absolute_uri("/api/0/organizations/%s/releases/" % self.organization.slug),
            json={},
        )

        self.org_integration.config = {}
        self.org_integration.save()

        with override_options({"vercel.client-secret": SECRET}):
            response = self._get_response(EXAMPLE_DEPLOYMENT_WEBHOOK_RESPONSE, SIGNATURE)

            assert len(responses.calls) == 0
            assert response.status_code == 204
Esempio n. 17
0
    def test_set_refs_failed(self):
        def request_callback(request):
            payload = json.loads(request.body)
            status_code = 400 if payload.get("refs") else 200
            return (status_code, {}, json.dumps({}))

        responses.add_callback(
            responses.POST,
            absolute_uri("/api/0/organizations/%s/releases/" % self.organization.slug),
            callback=request_callback,
        )

        with override_options({"vercel.client-secret": SECRET}):
            response = self._get_response(EXAMPLE_DEPLOYMENT_WEBHOOK_RESPONSE, SIGNATURE)

            assert len(responses.calls) == 2
            assert response.status_code == 400
            assert "Error setting refs" in response.data["detail"]
Esempio n. 18
0
    def test_no_installation(self):
        responses.add(
            responses.POST,
            absolute_uri("/api/0/organizations/%s/releases/" % self.organization.slug),
            json={},
        )
        self.installation_for_provider.delete()

        with override_options({"vercel.client-secret": secret}):
            response = self.client.post(
                path=webhook_url,
                data=EXAMPLE_DEPLOYMENT_WEBHOOK_RESPONSE,
                content_type="application/json",
                HTTP_X_ZEIT_SIGNATURE=signature,
            )

            assert len(responses.calls) == 0
            assert response.status_code == 404
            assert response.data["detail"] == "Installation not found"
Esempio n. 19
0
    def test_create_release_fails(self):
        responses.add(
            responses.POST,
            absolute_uri("/api/0/organizations/%s/releases/" % self.organization.slug),
            json={},
            status=400,
        )

        with override_options({"vercel.client-secret": secret}):
            response = self.client.post(
                path=webhook_url,
                data=EXAMPLE_DEPLOYMENT_WEBHOOK_RESPONSE,
                content_type="application/json",
                HTTP_X_ZEIT_SIGNATURE=signature,
            )

            assert len(responses.calls) == 1
            assert response.status_code == 400
            assert "Error creating release" in response.data["detail"]
Esempio n. 20
0
    def test_release_already_created(self):
        responses.add(
            responses.POST,
            absolute_uri("/api/0/organizations/%s/releases/" %
                         self.organization.slug),
            json={},
        )

        self.create_release(project=self.project,
                            version="7488658dfcf24d9b735e015992b316e2a8340d9d")

        with override_options({"vercel.client-secret": SECRET}):
            response = self.client.post(
                path=self.webhook_url,
                data=EXAMPLE_DEPLOYMENT_WEBHOOK_RESPONSE,
                content_type="application/json",
                **{f"HTTP_X_{self.header}_SIGNATURE": SIGNATURE},
            )

            assert response.status_code == 201
Esempio n. 21
0
    def test_no_match(self):
        responses.add(
            responses.POST,
            absolute_uri("/api/0/organizations/%s/releases/" % self.organization.slug),
            json={},
        )

        self.org_integration.config = {}
        self.org_integration.save()

        with override_options({"vercel.client-secret": secret}):
            response = self.client.post(
                path=webhook_url,
                data=EXAMPLE_DEPLOYMENT_WEBHOOK_RESPONSE,
                content_type="application/json",
                HTTP_X_ZEIT_SIGNATURE=signature,
            )

            assert len(responses.calls) == 0
            assert response.status_code == 204
Esempio n. 22
0
    def test_no_project(self):
        responses.add(
            responses.POST,
            absolute_uri("/api/0/organizations/%s/releases/" %
                         self.organization.slug),
            json={},
        )
        self.project.delete()

        with override_options({"vercel.client-secret": SECRET}):
            response = self.client.post(
                path=self.webhook_url,
                data=EXAMPLE_DEPLOYMENT_WEBHOOK_RESPONSE,
                content_type="application/json",
                **{f"HTTP_X_{self.header}_SIGNATURE": SIGNATURE},
            )

            assert len(responses.calls) == 0
            assert response.status_code == 404
            assert response.data["detail"] == "Project not found"
Esempio n. 23
0
    def test_set_refs_failed(self):
        def request_callback(request):
            payload = json.loads(request.body)
            status_code = 400 if payload.get("refs") else 200
            return (status_code, {}, json.dumps({}))

        responses.add_callback(
            responses.POST,
            absolute_uri("/api/0/organizations/%s/releases/" % self.organization.slug),
            callback=request_callback,
        )

        with override_options({"vercel.client-secret": secret}):
            response = self.client.post(
                path=webhook_url,
                data=EXAMPLE_DEPLOYMENT_WEBHOOK_RESPONSE,
                content_type="application/json",
                HTTP_X_ZEIT_SIGNATURE=signature,
            )

            assert len(responses.calls) == 2
            assert response.status_code == 400
            assert "Error setting refs" in response.data["detail"]
    def test_sources_included_and_ignored_empty(self):
        with override_options({"symbolicator.ignored_sources": []}):
            sources = filter_ignored_sources([])

            assert sources == []