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))
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
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
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)
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)
def test_secret(self): sf = SecretField('test') password = '******' hashed = sf.save(password) self.assertTrue(password != hashed) self.assertTrue(sf.verify(password, hashed))