def test_authenticate_with_invalid_user(self):
        """
        Verify authenticate denies with a proper JSON in Etcd, Authorization header, and no matching user.
        """
        with mock.patch('cherrypy.engine.publish') as _publish:
            # Mock the return of the Etcd get result
            return_value = mock.MagicMock(etcd.EtcdResult)
            with open(self.user_config, 'r') as users_file:
                return_value.value = users_file.read()

            manager = mock.MagicMock(StoreHandlerManager)
            _publish.return_value = [manager]

            manager.get.return_value = return_value

            # Reload with the data from the mock'd Etcd
            http_basic_auth = httpbasicauth.HTTPBasicAuth()

            # Test the call
            req = falcon.Request(
                create_environ(headers={'Authorization': 'basic Yjpi'}))
            resp = falcon.Response()
            self.assertRaises(
                falcon.HTTPForbidden,
                http_basic_auth.authenticate,
                req, resp)
 def test_authenticate_with_valid_user(self):
     """
     Verify authenticate works with a proper JSON file, Authorization header, and a matching user.
     """
     self.http_basic_auth = httpbasicauth.HTTPBasicAuth(self.user_config)
     req = falcon.Request(
         create_environ(headers={'Authorization': 'basic YTph'}))
     resp = falcon.Response()
     self.assertEquals(
         None,
         self.http_basic_auth.authenticate(req, resp))
 def test_authenticate_with_invalid_password(self):
     """
     Verify authenticate denies with a proper JSON file, Authorization header, and the wrong password.
     """
     self.http_basic_auth= httpbasicauth.HTTPBasicAuth(self.user_config)
     req = falcon.Request(
         create_environ(headers={'Authorization': 'basic YTpiCg=='}))
     resp = falcon.Response()
     self.assertRaises(
         falcon.HTTPForbidden,
         self.http_basic_auth.authenticate,
         req, resp)
 def setUp(self):
     """
     Sets up a fresh instance of the class before each run.
     """
     self.user_config = get_fixture_file_path('conf/users.json')
     self.http_basic_auth = httpbasicauth.HTTPBasicAuth(self.user_config)
 def setUp(self):
     """
     Sets up a fresh instance of the class before each run.
     """
     # Empty users dict prevents it from trying to load from etcd.
     self.http_basic_auth = httpbasicauth.HTTPBasicAuth(users={})