def setUp(self):
     """
     Initializes a BasicAuthorizer for testing
     """
     super(BasicAuthorizerTests, self).setUp()
     self.username = "******"
     self.password = "******"
     self.authorizer = BasicAuthorizer(self.username, self.password)
class BasicAuthorizerTests(CapturedIOTestCase):
    def setUp(self):
        """
        Initializes a BasicAuthorizer for testing
        """
        super(BasicAuthorizerTests, self).setUp()
        self.username = "******"
        self.password = "******"
        self.authorizer = BasicAuthorizer(self.username, self.password)

    def test_set_authorization_header(self):
        """
        Sets authorization header in a test dictionary, confirms expected value
        """
        header_dict = {}
        self.authorizer.set_authorization_header(header_dict)
        # confirm value
        self.assertEqual(header_dict["Authorization"][:6], "Basic ")
        decoded = base64.b64decode(six.b(
            header_dict["Authorization"][6:])).decode('utf-8')
        self.assertEqual(decoded, "{0}:{1}".format(self.username,
                                                   self.password))

    def test_set_authorization_header_existing(self):
        """
        Confirms that an existing Authorization field is overwritten
        """
        header_dict = {"Header": "value", "Authorization": "previous_value"}
        self.authorizer.set_authorization_header(header_dict)
        # confirm values
        self.assertEqual(header_dict["Authorization"][:6], "Basic ")
        decoded = base64.b64decode(six.b(
            header_dict["Authorization"][6:])).decode('utf-8')
        self.assertEqual(decoded, "{0}:{1}".format(self.username,
                                                   self.password))
        self.assertEqual(header_dict["Header"], "value")

    def test_handle_missing_authorization(self):
        """
        Confirms that BasicAuthorizer doesn't handle missing authorization
        """
        self.assertFalse(self.authorizer.handle_missing_authorization())

    @params(("user", u"テスト"), (u"дум", 'pass'), (u"テスト", u"дум"))
    def test_unicode_handling(self, username, password):
        """
        With a unicode string for the password, set and verify the
        Authorization header.
        """
        header_dict = {}
        authorizer = BasicAuthorizer(username, password)
        authorizer.set_authorization_header(header_dict)
        # confirm value
        self.assertEqual(header_dict["Authorization"][:6], "Basic ")
        decoded = base64.b64decode(six.b(
            header_dict["Authorization"][6:])).decode('utf-8')
        self.assertEqual(decoded, u"{0}:{1}".format(username, password))
def test_unicode_handling(username, password):
    """
    With a unicode string for the password, set and verify the
    Authorization header.
    """
    authorizer = BasicAuthorizer(username, password)
    header_val = authorizer.get_authorization_header()

    assert header_val[:6] == "Basic "
    decoded = base64.b64decode(header_val[6:].encode("utf-8")).decode("utf-8")
    assert decoded == f"{username}:{password}"
def test_unicode_handling(username, password):
    """
    With a unicode string for the password, set and verify the
    Authorization header.
    """
    header_dict = {}
    authorizer = BasicAuthorizer(username, password)
    authorizer.set_authorization_header(header_dict)

    assert header_dict["Authorization"][:6] == "Basic "
    decoded = base64.b64decode(six.b(header_dict["Authorization"][6:])).decode("utf-8")
    assert decoded == u"{}:{}".format(username, password)
 def test_unicode_handling(self, username, password):
     """
     With a unicode string for the password, set and verify the
     Authorization header.
     """
     header_dict = {}
     authorizer = BasicAuthorizer(username, password)
     authorizer.set_authorization_header(header_dict)
     # confirm value
     self.assertEqual(header_dict["Authorization"][:6], "Basic ")
     decoded = base64.b64decode(six.b(
         header_dict["Authorization"][6:])).decode('utf-8')
     self.assertEqual(decoded, u"{0}:{1}".format(username, password))
Esempio n. 6
0
def test_unicode_handling(username, password):
    """
    With a unicode string for the password, set and verify the
    Authorization header.
    """
    header_dict = {}
    authorizer = BasicAuthorizer(username, password)
    authorizer.set_authorization_header(header_dict)

    assert header_dict["Authorization"][:6] == "Basic "
    decoded = base64.b64decode(six.b(
        header_dict["Authorization"][6:])).decode("utf-8")
    assert decoded == u"{}:{}".format(username, password)
 def __init__(self, client_id: str, client_secret: str, **kwargs: Any):
     if "authorizer" in kwargs:
         log.error("ArgumentError(ConfidentialAppClient.authorizer)")
         raise exc.GlobusSDKUsageError(
             "Cannot give a ConfidentialAppAuthClient an authorizer")
     super().__init__(
         client_id=client_id,
         authorizer=BasicAuthorizer(client_id, client_secret),
         **kwargs,
     )
     log.info(f"Finished initializing client, client_id={client_id}")
    def __init__(self, client_id, client_secret, **kwargs):
        if "authorizer" in kwargs:
            logger.error('ArgumentError(ConfidentialAppClient.authorizer)')
            raise GlobusSDKUsageError(
                "Cannot give a ConfidentialAppAuthClient an authorizer")

        AuthClient.__init__(
            self, client_id=client_id,
            authorizer=BasicAuthorizer(client_id, client_secret),
            **kwargs)
        self.logger.info('Finished initializing client, client_id={}'
                         .format(client_id))
Esempio n. 9
0
def authorizer():
    return BasicAuthorizer(USERNAME, PASSWORD)