Skip to content

Commit 314c598

Browse files
committed
Remove HTTPKerberosAuth shim
1 parent 9dbee0e commit 314c598

File tree

4 files changed

+21
-123
lines changed

4 files changed

+21
-123
lines changed

HISTORY.rst

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ History
66

77
- Fork project to httpx-gssapi
88
- Replace all requests handling to support HTTPX
9+
- Remove HTTPKerberosAuth shim
910

1011

1112
1.2.0: 2020-02-18

httpx_gssapi/__init__.py

-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"""
1616
__all__ = (
1717
'HTTPSPNEGOAuth',
18-
'HTTPKerberosAuth',
1918
'MutualAuthenticationError',
2019
'REQUIRED',
2120
'OPTIONAL',
@@ -27,7 +26,6 @@
2726

2827
from .gssapi_ import HTTPSPNEGOAuth, REQUIRED, OPTIONAL, DISABLED
2928
from .exceptions import MutualAuthenticationError
30-
from .compat import HTTPKerberosAuth
3129

3230
from ._version import get_versions
3331
__version__ = get_versions()['version']

httpx_gssapi/compat.py

-72
This file was deleted.

test_httpx_gssapi.py

+20-49
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def test_negotate_value_extraction_none():
9999

100100

101101
def test_force_preemptive(patched_ctx):
102-
auth = httpx_gssapi.HTTPKerberosAuth(force_preemptive=True)
102+
auth = httpx_gssapi.HTTPSPNEGOAuth(opportunistic_auth=True)
103103

104104
request = null_request()
105105

@@ -111,7 +111,7 @@ def test_force_preemptive(patched_ctx):
111111

112112

113113
def test_no_force_preemptive(patched_ctx):
114-
auth = httpx_gssapi.HTTPKerberosAuth()
114+
auth = httpx_gssapi.HTTPSPNEGOAuth()
115115

116116
request = null_request()
117117

@@ -124,7 +124,7 @@ def test_no_force_preemptive(patched_ctx):
124124
def test_generate_request_header(patched_ctx):
125125
resp = null_response(headers=neg_token)
126126
host = resp.url.host
127-
auth = httpx_gssapi.HTTPKerberosAuth()
127+
auth = httpx_gssapi.HTTPSPNEGOAuth()
128128
assert auth.generate_request_header(host, resp) == b64_negotiate_response
129129
check_init()
130130
fake_resp.assert_called_with(b"token")
@@ -133,7 +133,7 @@ def test_generate_request_header(patched_ctx):
133133
def test_generate_request_header_init_error(patched_ctx_fail):
134134
response = null_response(headers=neg_token)
135135
host = response.url.host
136-
auth = httpx_gssapi.HTTPKerberosAuth()
136+
auth = httpx_gssapi.HTTPSPNEGOAuth()
137137
with pytest.raises(httpx_gssapi.exceptions.SPNEGOExchangeError):
138138
auth.generate_request_header(host, response)
139139
check_init()
@@ -142,7 +142,7 @@ def test_generate_request_header_init_error(patched_ctx_fail):
142142
def test_generate_request_header_step_error(patched_ctx_fail):
143143
response = null_response(headers=neg_token)
144144
host = response.url.host
145-
auth = httpx_gssapi.HTTPKerberosAuth()
145+
auth = httpx_gssapi.HTTPSPNEGOAuth()
146146
with pytest.raises(httpx_gssapi.exceptions.SPNEGOExchangeError):
147147
auth.generate_request_header(host, response)
148148
check_init()
@@ -155,7 +155,7 @@ def test_authenticate_user(patched_ctx):
155155
request=null_request(),
156156
headers=neg_token,
157157
)
158-
auth = httpx_gssapi.HTTPKerberosAuth()
158+
auth = httpx_gssapi.HTTPSPNEGOAuth()
159159
request = auth.authenticate_user(response)
160160
assert 'Authorization' in request.headers
161161
assert request.headers['Authorization'] == b64_negotiate_response
@@ -170,7 +170,7 @@ def test_handle_401(patched_ctx):
170170
headers=neg_token,
171171
)
172172

173-
auth = httpx_gssapi.HTTPKerberosAuth()
173+
auth = httpx_gssapi.HTTPSPNEGOAuth()
174174
request = auth.handle_401(response)
175175
assert 'Authorization' in request.headers
176176
assert request.headers['Authorization'] == b64_negotiate_response
@@ -184,7 +184,7 @@ def test_authenticate_server(patched_ctx):
184184
'authorization': b64_negotiate_response,
185185
})
186186

187-
auth = httpx_gssapi.HTTPKerberosAuth()
187+
auth = httpx_gssapi.HTTPSPNEGOAuth()
188188
auth.context = {"www.example.org": gssapi.SecurityContext}
189189
assert auth.authenticate_server(response_ok)
190190
fake_resp.assert_called_with(b"servertoken")
@@ -196,7 +196,7 @@ def test_handle_other(patched_ctx):
196196
'authorization': b64_negotiate_response,
197197
})
198198

199-
auth = httpx_gssapi.HTTPKerberosAuth(mutual_authentication=REQUIRED)
199+
auth = httpx_gssapi.HTTPSPNEGOAuth(mutual_authentication=REQUIRED)
200200
auth.context = {"www.example.org": gssapi.SecurityContext}
201201

202202
auth.handle_mutual_auth(response_ok) # No error raised
@@ -209,7 +209,7 @@ def test_handle_response_200(patched_ctx):
209209
'authorization': b64_negotiate_response,
210210
})
211211

212-
auth = httpx_gssapi.HTTPKerberosAuth(mutual_authentication=REQUIRED)
212+
auth = httpx_gssapi.HTTPSPNEGOAuth(mutual_authentication=REQUIRED)
213213
auth.context = {"www.example.org": gssapi.SecurityContext}
214214

215215
flow = auth.handle_response(response_ok)
@@ -221,7 +221,7 @@ def test_handle_response_200(patched_ctx):
221221
def test_handle_response_200_mutual_auth_required_failure(patched_ctx_fail):
222222
response_ok = null_response()
223223

224-
auth = httpx_gssapi.HTTPKerberosAuth(mutual_authentication=REQUIRED)
224+
auth = httpx_gssapi.HTTPSPNEGOAuth(mutual_authentication=REQUIRED)
225225
auth.context = {"www.example.org": "CTX"}
226226

227227
flow = auth.handle_response(response_ok)
@@ -237,7 +237,7 @@ def test_handle_response_200_mutual_auth_required_failure_2(patched_ctx_fail):
237237
'authorization': b64_negotiate_response,
238238
})
239239

240-
auth = httpx_gssapi.HTTPKerberosAuth(mutual_authentication=REQUIRED)
240+
auth = httpx_gssapi.HTTPSPNEGOAuth(mutual_authentication=REQUIRED)
241241
auth.context = {"www.example.org": gssapi.SecurityContext}
242242

243243
flow = auth.handle_response(response_ok)
@@ -253,7 +253,7 @@ def test_handle_response_200_mutual_auth_optional_hard_fail(patched_ctx_fail):
253253
'authorization': b64_negotiate_response,
254254
})
255255

256-
auth = httpx_gssapi.HTTPKerberosAuth(mutual_authentication=OPTIONAL)
256+
auth = httpx_gssapi.HTTPSPNEGOAuth(mutual_authentication=OPTIONAL)
257257
auth.context = {"www.example.org": gssapi.SecurityContext}
258258

259259
flow = auth.handle_response(response_ok)
@@ -266,7 +266,7 @@ def test_handle_response_200_mutual_auth_optional_hard_fail(patched_ctx_fail):
266266
def test_handle_response_200_mutual_auth_optional_soft_failure(patched_ctx):
267267
response_ok = null_response()
268268

269-
auth = httpx_gssapi.HTTPKerberosAuth(mutual_authentication=OPTIONAL)
269+
auth = httpx_gssapi.HTTPSPNEGOAuth(mutual_authentication=OPTIONAL)
270270
auth.context = {"www.example.org": gssapi.SecurityContext}
271271

272272
flow = auth.handle_response(response_ok)
@@ -283,7 +283,7 @@ def test_handle_response_500_mutual_auth_required_failure(patched_ctx_fail):
283283
)
284284
response_500._content = b"CONTENT"
285285

286-
auth = httpx_gssapi.HTTPKerberosAuth(mutual_authentication=REQUIRED)
286+
auth = httpx_gssapi.HTTPSPNEGOAuth(mutual_authentication=REQUIRED)
287287
auth.context = {"www.example.org": "CTX"}
288288

289289
flow = auth.handle_response(response_500)
@@ -305,7 +305,7 @@ def test_handle_response_500_mutual_auth_required_fail_no_san(patched_ctx_fail):
305305
)
306306
response_500._content = b'CONTENT'
307307

308-
auth = httpx_gssapi.HTTPKerberosAuth(
308+
auth = httpx_gssapi.HTTPSPNEGOAuth(
309309
mutual_authentication=REQUIRED,
310310
sanitize_mutual_error_response=False
311311
)
@@ -330,7 +330,7 @@ def test_handle_response_500_mutual_auth_optional_failure(patched_ctx_fail):
330330
)
331331
response_500._content = b'CONTENT'
332332

333-
auth = httpx_gssapi.HTTPKerberosAuth(mutual_authentication=OPTIONAL)
333+
auth = httpx_gssapi.HTTPSPNEGOAuth(mutual_authentication=OPTIONAL)
334334
auth.context = {"www.example.org": "CTX"}
335335

336336
flow = auth.handle_response(response_500)
@@ -346,7 +346,7 @@ def test_handle_response_500_mutual_auth_optional_failure(patched_ctx_fail):
346346

347347

348348
def test_handle_response_401(patched_ctx):
349-
auth = httpx_gssapi.HTTPKerberosAuth()
349+
auth = httpx_gssapi.HTTPSPNEGOAuth()
350350
response_401 = null_response(status=401, headers=neg_token)
351351
flow = auth.handle_response(response_401)
352352
request = next(flow)
@@ -362,7 +362,7 @@ def test_handle_response_401(patched_ctx):
362362
def test_handle_response_401_rejected(patched_ctx):
363363
# Get a 401 from server, authenticate, and get another 401 back.
364364
# Ensure there is no infinite auth loop.
365-
auth = httpx_gssapi.HTTPKerberosAuth()
365+
auth = httpx_gssapi.HTTPSPNEGOAuth()
366366
response_401 = null_response(status=401, headers=neg_token)
367367
flow = auth.handle_response(response_401)
368368

@@ -381,16 +381,8 @@ def test_handle_response_401_rejected(patched_ctx):
381381
fake_resp.assert_called_with(b"token")
382382

383383

384-
def test_generate_request_header_custom_service(patched_ctx):
385-
response = null_response(headers=neg_token)
386-
auth = httpx_gssapi.HTTPKerberosAuth(service="barfoo")
387-
auth.generate_request_header(response.url.host, response),
388-
check_init(name=gssapi_name("[email protected]"))
389-
fake_resp.assert_called_with(b"token")
390-
391-
392384
def test_delegation(patched_ctx):
393-
auth = httpx_gssapi.HTTPKerberosAuth(delegate=True)
385+
auth = httpx_gssapi.HTTPSPNEGOAuth(delegate=True)
394386
response_401 = null_response(status=401, headers=neg_token)
395387
flow = auth.handle_response(response_401)
396388
request = next(flow)
@@ -403,27 +395,6 @@ def test_delegation(patched_ctx):
403395
fake_resp.assert_called_with(b"token")
404396

405397

406-
def test_principal_override(patched_ctx, patched_creds):
407-
response = null_response(headers=neg_token)
408-
auth = httpx_gssapi.HTTPKerberosAuth(principal="user@REALM")
409-
auth.generate_request_header(response.url.host, response)
410-
fake_creds.assert_called_with(
411-
gssapi.creds.Credentials,
412-
usage="initiate",
413-
name=gssapi_name("user@REALM"),
414-
)
415-
check_init(creds=b"fake creds")
416-
417-
418-
def test_realm_override(patched_ctx):
419-
response = null_response(headers=neg_token)
420-
otherhost = "otherhost.otherdomain.org"
421-
auth = httpx_gssapi.HTTPKerberosAuth(hostname_override=otherhost)
422-
auth.generate_request_header(response.url.host, response)
423-
check_init(name=gssapi_name(f"HTTP@{otherhost}"))
424-
fake_resp.assert_called_with(b"token")
425-
426-
427398
def test_opportunistic_auth(patched_ctx):
428399
auth = httpx_gssapi.HTTPSPNEGOAuth(opportunistic_auth=True)
429400

0 commit comments

Comments
 (0)