Exemple #1
0
 def decorated_function(*args, **kwargs):
     authentication_status = check_authentication(request.headers,
                                                  request.json)
     if authentication_status == AuthenticationStatus.OK:
         return f(*args, **kwargs)
     else:
         return {'error': authentication_status}
 def test_check_authentication_with_api_key(self):
     self.headers['API_Key'] = 'bar'
     assert authentication.check_authentication(self.headers, self.data) == authentication.AuthenticationStatus.INVALID_API_KEY
 def test_check_authentication_with_changed_data(self):
     self.data = {'something': 'else'}
     assert authentication.check_authentication(self.headers, self.data) == authentication.AuthenticationStatus.INVALID_SIGNATURE
 def test_check_authentication_without_api_nonce_header(self):
     del self.headers['API_Nonce']
     assert authentication.check_authentication(self.headers, self.data) == authentication.AuthenticationStatus.NO_NONCE
 def test_check_authentication_with_wrong_secret(self):
     self.headers['API_Sign'] = authentication.signature(self.data, NONCE, 'ABCD')
     assert authentication.check_authentication(self.headers, self.data) == authentication.AuthenticationStatus.INVALID_SIGNATURE
 def test_check_authentication_without_api_sign_header(self):
     del self.headers['API_Sign']
     assert authentication.check_authentication(self.headers, self.data) == authentication.AuthenticationStatus.NO_SIGNATURE
 def test_check_authentication_without_api_key_header(self):
     del self.headers['API_Key']
     assert authentication.check_authentication(self.headers, self.data) == authentication.AuthenticationStatus.NO_API_KEY
 def test_check_authentication_with_valid_headers_and_data_and_a_nonce_that_is_higher_than_the_previous_request(self):
     assert authentication.check_authentication(self.headers, self.data) == authentication.AuthenticationStatus.OK
 def test_check_authentication_with_valid_headers_and_data_but_the_same_nonce(self):
     self.headers['API_Sign'] = authentication.signature(self.data, NONCE-1, 'bar1')
     self.headers['API_Nonce'] = NONCE - 1
     assert authentication.check_authentication(self.headers, self.data) == authentication.AuthenticationStatus.INVALID_NONCE
 def test_check_authentication_with_valid_headers_and_data(self):
     assert authentication.check_authentication(self.headers, self.data) == authentication.AuthenticationStatus.OK