Esempio n. 1
0
 async def test_instantiation(self):
     oauth_flow = AsyncOAuthFlow.sqlite3(
         database="./logs/test_db",
         client_id="111.222",
         client_secret="xxx",
         scopes=["chat:write", "commands"],
     )
     assert oauth_flow is not None
     assert oauth_flow.logger is not None
     assert oauth_flow.client is not None
 async def test_handle_installation(self):
     oauth_flow = AsyncOAuthFlow.sqlite3(
         database="./logs/test_db",
         client_id="111.222",
         client_secret="xxx",
         scopes=["chat:write", "commands"],
     )
     req = AsyncBoltRequest(body="")
     resp = await oauth_flow.handle_installation(req)
     assert resp.status == 200
     assert resp.headers.get("content-type") == ["text/html; charset=utf-8"]
     assert "https://slack.com/oauth/v2/authorize?state=" in resp.body
Esempio n. 3
0
 async def test_handle_callback_invalid_state(self):
     oauth_flow = AsyncOAuthFlow.sqlite3(
         database="./logs/test_db",
         client_id="111.222",
         client_secret="xxx",
         scopes=["chat:write", "commands"],
     )
     state = await oauth_flow.issue_new_state(None)
     req = AsyncBoltRequest(
         body="",
         query=f"code=foo&state=invalid",
         headers={"cookie": [f"{oauth_flow.settings.state_cookie_name}={state}"]},
     )
     resp = await oauth_flow.handle_callback(req)
     assert resp.status == 400
Esempio n. 4
0
 async def test_handle_callback(self):
     oauth_flow = AsyncOAuthFlow.sqlite3(
         database="./logs/test_db",
         client=AsyncWebClient(base_url=self.mock_api_server_base_url),
         client_id="111.222",
         client_secret="xxx",
         scopes=["chat:write", "commands"],
         success_url="https://www.example.com/completion",
         failure_url="https://www.example.com/failure",
     )
     state = await oauth_flow.issue_new_state(None)
     req = AsyncBoltRequest(
         body="",
         query=f"code=foo&state={state}",
         headers={"cookie": [f"{oauth_flow.settings.state_cookie_name}={state}"]},
     )
     resp = await oauth_flow.handle_callback(req)
     assert resp.status == 200
     assert "https://www.example.com/completion" in resp.body
    async def test_handle_callback_using_options(self):
        async def success(args: AsyncSuccessArgs) -> BoltResponse:
            assert args.request is not None
            return BoltResponse(status=200, body="customized")

        async def failure(args: AsyncFailureArgs) -> BoltResponse:
            assert args.request is not None
            assert args.reason is not None
            return BoltResponse(status=502, body="customized")

        oauth_flow = AsyncOAuthFlow.sqlite3(
            client=AsyncWebClient(base_url=self.mock_api_server_base_url),
            database="./logs/test_db",
            client_id="111.222",
            client_secret="xxx",
            scopes=["chat:write", "commands"],
            callback_options=AsyncCallbackOptions(
                success=success,
                failure=failure,
            ),
        )
        state = await oauth_flow.issue_new_state(None)
        req = AsyncBoltRequest(
            body="",
            query=f"code=foo&state={state}",
            headers={
                "cookie": [f"{oauth_flow.settings.state_cookie_name}={state}"]
            },
        )
        resp = await oauth_flow.handle_callback(req)
        assert resp.status == 200
        assert resp.body == "customized"

        req = AsyncBoltRequest(
            body="",
            query=f"code=foo&state=invalid",
            headers={
                "cookie": [f"{oauth_flow.settings.state_cookie_name}={state}"]
            },
        )
        resp = await oauth_flow.handle_callback(req)
        assert resp.status == 502
        assert resp.body == "customized"