示例#1
0
 def test_secret_create(self):
     data = h1.copy()
     data['api_key'] = '123'
     hosts.create('host_1', data)
     h = hosts.get('host_1')
     self.assertNotEqual('123', h.api_key)
     self.assertTrue(SecretField.verify('123', h.api_key))
示例#2
0
文件: api.py 项目: doanac/cya
def _is_host_authenticated(host):
    key = request.headers.get("Authorization", None)
    if key:
        parts = key.split(" ")
        if len(parts) == 2 and parts[0] == "Token":
            return SecretField.verify(parts[1], host.api_key)
    return False
示例#3
0
文件: api.py 项目: doanac/cya
def _is_host_authenticated(host):
    key = request.headers.get('Authorization', None)
    if key:
        parts = key.split(' ')
        if len(parts) == 2 and parts[0] == 'Token':
            return SecretField.verify(parts[1], host.api_key)
    return False
示例#4
0
文件: api.py 项目: doanac/cya
 def wrapper(*args, **kwargs):
     key = request.headers.get("Authorization", None)
     if not key:
         resp = jsonify({"Message": "No Authorization header provided"})
         resp.status_code = 401
         return resp
     parts = key.split(" ")
     if len(parts) != 2 or parts[0] != "Token":
         resp = jsonify({"Message": "Invalid Authorization header"})
         resp.status_code = 401
         return resp
     host = hosts.get(kwargs["name"])
     if not SecretField.verify(parts[1], host.api_key):
         resp = jsonify({"Message": "Incorrect API key for host"})
         resp.status_code = 401
         return resp
     return f(*args, **kwargs)
示例#5
0
文件: api.py 项目: doanac/cya
 def wrapper(*args, **kwargs):
     key = request.headers.get('Authorization', None)
     if not key:
         resp = jsonify({'Message': 'No Authorization header provided'})
         resp.status_code = 401
         return resp
     parts = key.split(' ')
     if len(parts) != 2 or parts[0] != 'Token':
         resp = jsonify({'Message': 'Invalid Authorization header'})
         resp.status_code = 401
         return resp
     host = hosts.get(kwargs['name'])
     if not SecretField.verify(parts[1], host.api_key):
         resp = jsonify({'Message': 'Incorrect API key for host'})
         resp.status_code = 401
         return resp
     return f(*args, **kwargs)
示例#6
0
 def test_secret(self):
     sf = SecretField('test')
     password = '******'
     hashed = sf.save(password)
     self.assertTrue(password != hashed)
     self.assertTrue(sf.verify(password, hashed))