コード例 #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}
コード例 #2
0
 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
コード例 #3
0
 def test_check_authentication_with_changed_data(self):
     self.data = {'something': 'else'}
     assert authentication.check_authentication(self.headers, self.data) == authentication.AuthenticationStatus.INVALID_SIGNATURE
コード例 #4
0
 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
コード例 #5
0
 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
コード例 #6
0
 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
コード例 #7
0
 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
コード例 #8
0
 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
コード例 #9
0
 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
コード例 #10
0
 def test_check_authentication_with_valid_headers_and_data(self):
     assert authentication.check_authentication(self.headers, self.data) == authentication.AuthenticationStatus.OK