11"""HTTPClient test module."""
2+ from requests_kerberos import HTTPKerberosAuth , OPTIONAL
23
34from splitio .api import client
5+ from splitio .client .config import AuthenticateScheme
46
57class HttpClientTests (object ):
68 """Http Client test cases."""
@@ -19,7 +21,8 @@ def test_get(self, mocker):
1921 client .HttpClient .SDK_URL + '/test1' ,
2022 headers = {'Authorization' : 'Bearer some_api_key' , 'h1' : 'abc' , 'Content-Type' : 'application/json' },
2123 params = {'param1' : 123 },
22- timeout = None
24+ timeout = None ,
25+ auth = None
2326 )
2427 assert response .status_code == 200
2528 assert response .body == 'ok'
@@ -31,7 +34,8 @@ def test_get(self, mocker):
3134 client .HttpClient .EVENTS_URL + '/test1' ,
3235 headers = {'Authorization' : 'Bearer some_api_key' , 'h1' : 'abc' , 'Content-Type' : 'application/json' },
3336 params = {'param1' : 123 },
34- timeout = None
37+ timeout = None ,
38+ auth = None
3539 )
3640 assert get_mock .mock_calls == [call ]
3741 assert response .status_code == 200
@@ -51,7 +55,8 @@ def test_get_custom_urls(self, mocker):
5155 'https://sdk.com/test1' ,
5256 headers = {'Authorization' : 'Bearer some_api_key' , 'h1' : 'abc' , 'Content-Type' : 'application/json' },
5357 params = {'param1' : 123 },
54- timeout = None
58+ timeout = None ,
59+ auth = None
5560 )
5661 assert get_mock .mock_calls == [call ]
5762 assert response .status_code == 200
@@ -63,7 +68,8 @@ def test_get_custom_urls(self, mocker):
6368 'https://events.com/test1' ,
6469 headers = {'Authorization' : 'Bearer some_api_key' , 'h1' : 'abc' , 'Content-Type' : 'application/json' },
6570 params = {'param1' : 123 },
66- timeout = None
71+ timeout = None ,
72+ auth = None
6773 )
6874 assert response .status_code == 200
6975 assert response .body == 'ok'
@@ -85,7 +91,8 @@ def test_post(self, mocker):
8591 json = {'p1' : 'a' },
8692 headers = {'Authorization' : 'Bearer some_api_key' , 'h1' : 'abc' , 'Content-Type' : 'application/json' },
8793 params = {'param1' : 123 },
88- timeout = None
94+ timeout = None ,
95+ auth = None
8996 )
9097 assert response .status_code == 200
9198 assert response .body == 'ok'
@@ -98,7 +105,8 @@ def test_post(self, mocker):
98105 json = {'p1' : 'a' },
99106 headers = {'Authorization' : 'Bearer some_api_key' , 'h1' : 'abc' , 'Content-Type' : 'application/json' },
100107 params = {'param1' : 123 },
101- timeout = None
108+ timeout = None ,
109+ auth = None
102110 )
103111 assert response .status_code == 200
104112 assert response .body == 'ok'
@@ -119,7 +127,8 @@ def test_post_custom_urls(self, mocker):
119127 json = {'p1' : 'a' },
120128 headers = {'Authorization' : 'Bearer some_api_key' , 'h1' : 'abc' , 'Content-Type' : 'application/json' },
121129 params = {'param1' : 123 },
122- timeout = None
130+ timeout = None ,
131+ auth = None
123132 )
124133 assert response .status_code == 200
125134 assert response .body == 'ok'
@@ -132,8 +141,36 @@ def test_post_custom_urls(self, mocker):
132141 json = {'p1' : 'a' },
133142 headers = {'Authorization' : 'Bearer some_api_key' , 'h1' : 'abc' , 'Content-Type' : 'application/json' },
134143 params = {'param1' : 123 },
135- timeout = None
144+ timeout = None ,
145+ auth = None
136146 )
137147 assert response .status_code == 200
138148 assert response .body == 'ok'
139149 assert get_mock .mock_calls == [call ]
150+
151+ def test_authentication_scheme (self , mocker ):
152+ response_mock = mocker .Mock ()
153+ response_mock .status_code = 200
154+ response_mock .text = 'ok'
155+ get_mock = mocker .Mock ()
156+ get_mock .return_value = response_mock
157+ mocker .patch ('splitio.api.client.requests.get' , new = get_mock )
158+ httpclient = client .HttpClient (sdk_url = 'https://sdk.com' , authentication_scheme = AuthenticateScheme .KERBEROS )
159+ response = httpclient .get ('sdk' , '/test1' , 'some_api_key' , {'param1' : 123 }, {'h1' : 'abc' })
160+ call = mocker .call (
161+ 'https://sdk.com/test1' ,
162+ headers = {'Authorization' : 'Bearer some_api_key' , 'h1' : 'abc' , 'Content-Type' : 'application/json' },
163+ params = {'param1' : 123 },
164+ timeout = None ,
165+ auth = HTTPKerberosAuth (mutual_authentication = OPTIONAL )
166+ )
167+
168+ httpclient = client .HttpClient (sdk_url = 'https://sdk.com' , authentication_scheme = AuthenticateScheme .KERBEROS , authentication_params = ['bilal' , 'split' ])
169+ response = httpclient .get ('sdk' , '/test1' , 'some_api_key' , {'param1' : 123 }, {'h1' : 'abc' })
170+ call = mocker .call (
171+ 'https://sdk.com/test1' ,
172+ headers = {'Authorization' : 'Bearer some_api_key' , 'h1' : 'abc' , 'Content-Type' : 'application/json' },
173+ params = {'param1' : 123 },
174+ timeout = None ,
175+ auth = HTTPKerberosAuth (principal = 'bilal' , password = 'split' ,mutual_authentication = OPTIONAL )
176+ )
0 commit comments