def test_invalid(self): middleware = RequestVerification(signing_secret=self.signing_secret) req = BoltRequest(body="payload={}", headers={}) resp = BoltResponse(status=404) resp = middleware.process(req=req, resp=resp, next=next) assert resp.status == 401 assert resp.body == """{"error": "invalid request"}"""
def test_valid(self): middleware = RequestVerification(signing_secret=self.signing_secret) timestamp = str(int(time())) raw_body = "payload={}" req = BoltRequest(body=raw_body, headers=self.build_headers(timestamp, raw_body)) resp = BoltResponse(status=404, body="default") resp = middleware.process(req=req, resp=resp, next=next) assert resp.status == 200 assert resp.body == "next"
def _init_middleware_list(self): if self._init_middleware_list_done: return self._middleware_list.append( SslCheck(verification_token=self._verification_token) ) self._middleware_list.append(RequestVerification(self._signing_secret)) if self._oauth_flow is None: if self._token is not None: try: auth_test_result = self._client.auth_test(token=self._token) self._middleware_list.append( SingleTeamAuthorization(auth_test_result=auth_test_result) ) except SlackApiError as err: raise BoltError(error_auth_test_failure(err.response)) elif self._authorize is not None: self._middleware_list.append( MultiTeamsAuthorization(authorize=self._authorize) ) else: raise BoltError(error_token_required()) else: self._middleware_list.append( MultiTeamsAuthorization(authorize=self._authorize) ) self._middleware_list.append(IgnoringSelfEvents()) self._middleware_list.append(UrlVerification()) self._init_middleware_list_done = True
def _init_middleware_list(self): if self._init_middleware_list_done: return self._middleware_list.append( SslCheck(verification_token=self._verification_token)) self._middleware_list.append(RequestVerification(self._signing_secret)) if self._oauth_flow is None: if self._token: self._middleware_list.append(SingleTeamAuthorization()) else: raise BoltError( "OAuthFlow not found, so could not initialize the Bolt app." ) else: self._middleware_list.append( MultiTeamsAuthorization( installation_store=self._installation_store, verification_enabled=self._authorization_test_enabled, )) self._middleware_list.append(IgnoringSelfEvents()) self._middleware_list.append(UrlVerification()) self._init_middleware_list_done = True