async def test_bot_session_cert(mocked_api_client): session_auth_client = mocked_api_client() key_auth_client = mocked_api_client() session_auth_client.call_api.return_value = Token(token="session_token") key_auth_client.call_api.return_value = Token(token="km_token") bot_authenticator = BotAuthenticatorCert(session_auth_client, key_auth_client, minimal_retry_config()) session_token = await bot_authenticator.retrieve_session_token() km_token = await bot_authenticator.retrieve_key_manager_token() assert session_token == "session_token" assert km_token == "km_token"
async def test_bot_session_rsa(config, mocked_api_client): with patch("symphony.bdk.core.auth.bot_authenticator.create_signed_jwt", return_value="privateKey"): login_api_client = mocked_api_client() relay_api_client = mocked_api_client() login_api_client.call_api.return_value = Token(token="session_token") relay_api_client.call_api.return_value = Token(token="km_token") bot_authenticator = BotAuthenticatorRsa(config, login_api_client, relay_api_client, minimal_retry_config()) session_token = await bot_authenticator.retrieve_session_token() km_token = await bot_authenticator.retrieve_key_manager_token() assert session_token == "session_token" assert km_token == "km_token"
async def test_api_exception_cert_auth_in_userid_authenticate(): with patch( "symphony.bdk.core.auth.obo_authenticator.CertificateAuthenticationApi" ) as auth_api: auth_api.v1_app_authenticate_post = AsyncMock(return_value=Token( token="app_token")) auth_api.v1_app_user_uid_authenticate_post = AsyncMock( side_effect=ApiException(400)) obo_authenticator = OboAuthenticatorCert(auth_api, minimal_retry_config()) with pytest.raises(ApiException): await obo_authenticator.retrieve_obo_session_token_by_user_id(1234)
async def test_api_exception_in_authenticate_userid(config): with patch("symphony.bdk.core.auth.obo_authenticator.create_signed_jwt", return_value="signed_jwt"), \ patch("symphony.bdk.core.auth.obo_authenticator.AuthenticationApi") as auth_api: auth_api.pubkey_app_authenticate_post = AsyncMock(return_value=Token( token="app_token")) auth_api.pubkey_app_user_user_id_authenticate_post = AsyncMock( side_effect=ApiException(400)) obo_authenticator = OboAuthenticatorRsa(config, auth_api, minimal_retry_config()) with pytest.raises(ApiException): await obo_authenticator.retrieve_obo_session_token_by_user_id(1234)
async def test_authenticate_by_user_id(config): signed_jwt = "signed_jwt" app_token = "app_token" session_token = "session_token" user_id = 1234 with patch("symphony.bdk.core.auth.obo_authenticator.create_signed_jwt", return_value=signed_jwt) as create_jwt, \ patch("symphony.bdk.core.auth.obo_authenticator.AuthenticationApi") as auth_api: auth_api.pubkey_app_authenticate_post = AsyncMock(return_value=Token( token=app_token)) auth_api.pubkey_app_user_user_id_authenticate_post = AsyncMock( return_value=Token(token=session_token)) obo_authenticator = OboAuthenticatorRsa(config, auth_api, minimal_retry_config()) obo_session = obo_authenticator.authenticate_by_user_id(1234) assert await obo_session.session_token == "session_token" create_jwt.assert_called_once_with(config.private_key, config.app_id) auth_api.pubkey_app_authenticate_post.assert_called_once_with( AuthenticateRequest(token=signed_jwt)) auth_api.pubkey_app_user_user_id_authenticate_post.assert_called_once_with( session_token=app_token, user_id=user_id)
async def test_authenticate_by_user_id_cert_authentication(): with patch( "symphony.bdk.core.auth.obo_authenticator.CertificateAuthenticationApi" ) as auth_api: user_id = 1234 app_token = "app_token" session_token = "session_token" auth_api.v1_app_authenticate_post = AsyncMock(return_value=Token( token=app_token)) auth_api.v1_app_user_uid_authenticate_post = AsyncMock( return_value=OboAuthResponse(session_token=session_token)) obo_authenticator = OboAuthenticatorCert(auth_api, minimal_retry_config()) obo_session = obo_authenticator.authenticate_by_user_id(user_id) assert obo_session.user_id == user_id assert await obo_session.session_token == session_token auth_api.v1_app_authenticate_post.assert_called_once() auth_api.v1_app_user_uid_authenticate_post.assert_called_once_with( session_token=app_token, uid=user_id)
async def test_obo_session_username_cert_authentication(): with patch( "symphony.bdk.core.auth.obo_authenticator.CertificateAuthenticationApi" ) as auth_api: username = "******" app_token = "app_token" session_token = "session_token" auth_api.v1_app_authenticate_post = AsyncMock(return_value=Token( token=app_token)) auth_api.v1_app_username_username_authenticate_post = AsyncMock( return_value=OboAuthResponse(session_token=session_token)) obo_authenticator = OboAuthenticatorCert(auth_api, minimal_retry_config()) retrieved_session_token = await obo_authenticator.retrieve_obo_session_token_by_username( username) assert retrieved_session_token == session_token auth_api.v1_app_authenticate_post.assert_called_once() auth_api.v1_app_username_username_authenticate_post.assert_called_once_with( session_token=app_token, username=username)