예제 #1
0
 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)
예제 #2
0
 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))
예제 #3
0
 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)
예제 #4
0
 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)
예제 #5
0
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
예제 #6
0
 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')