def _init_async_middleware_list(self):
        if self._init_middleware_list_done:
            return
        self._async_middleware_list.append(
            AsyncSslCheck(verification_token=self._verification_token)
        )
        self._async_middleware_list.append(
            AsyncRequestVerification(self._signing_secret)
        )
        if self._async_oauth_flow is None:
            if self._token:
                self._async_middleware_list.append(AsyncSingleTeamAuthorization())
            elif self._async_authorize is not None:
                self._async_middleware_list.append(
                    AsyncMultiTeamsAuthorization(authorize=self._async_authorize)
                )
            else:
                raise BoltError(error_token_required())
        else:
            self._async_middleware_list.append(
                AsyncMultiTeamsAuthorization(authorize=self._async_authorize)
            )

        self._async_middleware_list.append(AsyncIgnoringSelfEvents())
        self._async_middleware_list.append(AsyncUrlVerification())
        self._init_middleware_list_done = True
    async def test_failure_pattern(self):
        authorization = AsyncSingleTeamAuthorization()
        req = AsyncBoltRequest(body="payload={}", headers={})
        req.context["client"] = AsyncWebClient(
            base_url=self.mock_api_server_base_url, token="dummy")
        resp = BoltResponse(status=404)

        resp = await authorization.async_process(req=req, resp=resp, next=next)

        assert resp.status == 200
        assert resp.body == ":x: Please install this app into the workspace :bow:"
    async def test_success_pattern(self):
        authorization = AsyncSingleTeamAuthorization()
        req = AsyncBoltRequest(body="payload={}", headers={})
        req.context["client"] = AsyncWebClient(
            base_url=self.mock_api_server_base_url, token="xoxb-valid")
        resp = BoltResponse(status=404)

        resp = await authorization.async_process(req=req, resp=resp, next=next)

        assert resp.status == 200
        assert resp.body == ""
Example #4
0
    def _init_async_middleware_list(self):
        if self._init_middleware_list_done:
            return
        self._async_middleware_list.append(
            AsyncSslCheck(verification_token=self._verification_token))
        self._async_middleware_list.append(
            AsyncRequestVerification(self._signing_secret))
        if self._async_oauth_flow is None:
            if self._token:
                self._async_middleware_list.append(
                    AsyncSingleTeamAuthorization())
            else:
                raise BoltError(
                    "AsyncOAuthFlow not found, so could not initialize the Bolt app."
                )
        else:
            self._async_middleware_list.append(
                AsyncMultiTeamsAuthorization(self._async_installation_store))

        self._async_middleware_list.append(AsyncIgnoringSelfEvents())
        self._async_middleware_list.append(AsyncUrlVerification())
        self._init_middleware_list_done = True