def test_given_valid_creds_expect_success(self):
     b64_username_pwd = base64.b64encode(
         'user1:password'.encode('utf-8')).decode('utf-8')
     self.assertTrue(
         handle_basic_authentication(
             {'Authorization': 'Basic {}'.format(b64_username_pwd)}, 'v1',
             self.settings, self.credentials))
示例#2
0
    def should_fail_with_not_authorized(self):
        '''
        Checks if authentication is required:
        - if it is not returns false, None
        - if it is required validates provided credentials

        Returns
        -------
        bool
            False if authentication is not required or is
            required and validation for credentials passes.
            True if validation for credentials failed.
        '''
        logger.debug('Checking if need to handle authentication')
        return not handle_basic_authentication(self.request.headers, "v1",
                                               self.settings, self.credentials)
 def test_given_headers_not_provided_expect_failure(self):
     self.assertFalse(
         handle_basic_authentication({}, 'v1', self.settings,
                                     self.credentials))
 def test_given_features_not_configured_expect_success(self):
     self.assertTrue(
         handle_basic_authentication({}, 'v0.4yota', self.settings,
                                     self.credentials))
 def test_given_auth_method_is_unknown_expect_failure(self):
     self.assertFalse(
         handle_basic_authentication({}, 'v0.3gamma', self.settings,
                                     self.credentials))
 def test_given_auth_method_not_provided_expect_failure(self):
     self.assertFalse(
         handle_basic_authentication({}, 'v0.2beta', self.settings,
                                     self.credentials))
 def test_given_unknown_api_version_expect_failure(self):
     self.assertFalse(
         handle_basic_authentication({}, 'v0.314p', self.settings,
                                     self.credentials))