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_by_file = httpauth.HTTPBasicAuthByFile( self.user_config)
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_by_file = httpauth.HTTPBasicAuthByFile( './conf/users.json') req = falcon.Request( create_environ(headers={'Authorization': 'basic YTph'})) resp = falcon.Response() self.assertEquals(None, self.http_basic_auth_by_file.authenticate(req, resp))
def test_authenticate_with_invalid_user(self): """ Verify authenticate denies with a proper JSON file, Authorization header, and no matching user. """ self.http_basic_auth_by_file = httpauth.HTTPBasicAuthByFile( './conf/users.json') req = falcon.Request( create_environ(headers={'Authorization': 'basic Yjpi'})) resp = falcon.Response() self.assertRaises(falcon.HTTPForbidden, self.http_basic_auth_by_file.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_by_file = httpauth.HTTPBasicAuthByFile( self.user_config) req = falcon.Request( create_environ(headers={'Authorization': 'basic YTpiCg=='})) resp = falcon.Response() self.assertRaises(falcon.HTTPForbidden, self.http_basic_auth_by_file.authenticate, req, resp)
def create_app(ds): # pragma: no cover # TODO: Make this configurable try: http_auth = httpauth.HTTPBasicAuthByEtcd(ds) except etcd.EtcdKeyNotFound: # TODO: Fall back to empty users file instead http_auth = httpauth.HTTPBasicAuthByFile('./conf/users.json') app = falcon.API(middleware=[http_auth, JSONify()]) app.add_route('/api/v0/status', StatusResource(ds, None)) app.add_route('/api/v0/host/{address}', HostResource(ds, None)) app.add_route('/api/v0/hosts', HostsResource(ds, None)) return app
def setUp(self): """ Sets up a fresh instance of the class before each run. """ self.http_basic_auth_by_file = httpauth.HTTPBasicAuthByFile( './conf/users.json')