示例#1
0
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)
示例#2
0
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)
示例#3
0
    def get_obo_authenticator(self) -> OboAuthenticator:
        """Creates a new instance of a Obo Authenticator service.

        :return: a new :class:`symphony.bdk.core.auth.obo_authenticator.OboAuthenticator` instance.
        """
        app_config = self._config.app
        if app_config.is_rsa_configuration_valid():
            return OboAuthenticatorRsa(
                app_config,
                AuthenticationApi(self._api_client_factory.get_login_client()),
                self._config.retry
            )
        if app_config.is_certificate_configuration_valid():
            authentication_api = CertificateAuthenticationApi(self._api_client_factory.get_app_session_auth_client())
            return OboAuthenticatorCert(authentication_api, self._config.retry)
        raise AuthInitializationError("Application under 'app' field should be configured with a private key or "
                                      "a certificate in order to use OBO authentication.")
示例#4
0
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)