示例#1
0
 def test_create_jwt_session_creates_session_with_expected_address(
         self, session_modifier_factory, auth_handler_factory,
         mock_session):
     factory = SessionFactory(Session, session_modifier_factory,
                              auth_handler_factory)
     session = factory.create_jwt_session(TARGET_HOST_ADDRESS, mock_session)
     assert session.host_address == TARGET_HOST_ADDRESS
示例#2
0
 def test_create_basic_auth_session_creates_session_with_expected_address(
         self, session_modifier_factory, auth_handler_factory):
     factory = SessionFactory(Session, session_modifier_factory,
                              auth_handler_factory)
     session = factory.create_basic_auth_session(TARGET_HOST_ADDRESS,
                                                 u"username", u"password")
     assert session.host_address == TARGET_HOST_ADDRESS
示例#3
0
 def test_create_storage_session_creates_session_with_expected_address(
         self, session_modifier_factory, auth_handler_factory,
         login_token_provider):
     factory = SessionFactory(Session, session_modifier_factory,
                              auth_handler_factory)
     session = factory.create_storage_session(TARGET_HOST_ADDRESS,
                                              login_token_provider)
     assert session.host_address == TARGET_HOST_ADDRESS
示例#4
0
 def from_local_account(cls, host_address, username, password):
     session_impl = Session
     session_factory = SessionFactory(session_impl,
                                      SessionModifierFactory(),
                                      AuthHandlerFactory())
     basic_auth_session = session_factory.create_basic_auth_session(
         host_address, username, password)
     sdk_dependencies = SDKDependencies(host_address, session_factory,
                                        basic_auth_session)
     return cls(sdk_dependencies)
示例#5
0
 def test_create_jwt_session_uses_auth_handler_with_expected_provider_and_modifier(
         self, mocker, session_modifier_factory, auth_handler_factory,
         mock_session):
     modifier = mocker.MagicMock(spec=HeaderModifier)
     session_modifier_factory.create_header_modifier.return_value = modifier
     factory = SessionFactory(Session, session_modifier_factory,
                              auth_handler_factory)
     factory.create_jwt_session(TARGET_HOST_ADDRESS, mock_session)
     provider = auth_handler_factory.create_auth_handler.call_args[0][0]
     called_modifier = auth_handler_factory.create_auth_handler.call_args[
         0][1]
     assert type(provider) == C42ApiV3TokenProvider
     assert modifier == called_modifier
示例#6
0
 def test_create_basic_auth_session_uses_auth_handler_with_expected_provider_and_modifier(
         self, mocker, session_modifier_factory, auth_handler_factory):
     modifier = mocker.MagicMock(spec=HeaderModifier)
     session_modifier_factory.create_header_modifier.return_value = modifier
     factory = SessionFactory(Session, session_modifier_factory,
                              auth_handler_factory)
     factory.create_basic_auth_session(TARGET_HOST_ADDRESS, u"username",
                                       u"password")
     provider = auth_handler_factory.create_auth_handler.call_args[0][0]
     called_modifier = auth_handler_factory.create_auth_handler.call_args[
         0][1]
     assert type(provider) == BasicAuthProvider
     assert modifier == called_modifier
示例#7
0
    def from_local_account(cls, host_address, username, password):
        """Creates a :class:`~py42.sdk.SDKClient` object for accessing the Code42 REST APIs using
        the supplied credentials. Currently, only accounts created within the Code42 console or
        using the APIs (including py42) are supported. Username/passwords that are based on Active
        Directory, Okta, or other Identity providers cannot be used with this method.

        Args:
            host_address (str): The domain name of the Code42 instance being authenticated to, e.g.
                console.us.code42.com
            username (str): The username of the authenticating account.
            password (str): The password of the authenticating account.

        Returns:
            :class:`py42.sdk.SDKClient`
        """
        session_impl = Session
        session_factory = SessionFactory(session_impl,
                                         SessionModifierFactory(),
                                         AuthHandlerFactory())
        basic_auth_session = session_factory.create_basic_auth_session(
            host_address, username, password)
        sdk_dependencies = SDKDependencies(host_address, session_factory,
                                           basic_auth_session)
        return cls(sdk_dependencies)
示例#8
0
 def test_create_anonymous_session_does_not_use_auth_handler(
         self, session_modifier_factory, auth_handler_factory):
     factory = SessionFactory(Session, session_modifier_factory,
                              auth_handler_factory)
     factory.create_anonymous_session(TARGET_HOST_ADDRESS)
     assert auth_handler_factory.create_auth_handler.call_count == 0