Skip to content

Commit b2de746

Browse files
Rename force_preemptive to opportunistic_auth
Signed-off-by: Robbie Harwood <[email protected]>
1 parent c7804fa commit b2de746

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

requests_gssapi/compat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def __init__(self, mutual_authentication=REQUIRED, service="HTTP",
2727
mutual_authentication=mutual_authentication,
2828
service=service,
2929
delegate=delegate,
30-
force_preemptive=force_preemptive,
30+
opportunistic_auth=force_preemptive,
3131
principal=principal,
3232
hostname_override=hostname_override,
3333
sanitize_mutual_error_response=sanitize_mutual_error_response)

requests_gssapi/gssapi_.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ def _negotiate_value(response):
8181
class HTTPSPNEGOAuth(AuthBase):
8282
"""Attaches HTTP GSSAPI Authentication to the given Request object."""
8383
def __init__(self, mutual_authentication=REQUIRED, service="HTTP",
84-
delegate=False, force_preemptive=False, principal=None,
84+
delegate=False, opportunistic_auth=False, principal=None,
8585
hostname_override=None, sanitize_mutual_error_response=True):
8686
self.context = {}
8787
self.mutual_authentication = mutual_authentication
8888
self.delegate = delegate
8989
self.pos = None
9090
self.service = service
91-
self.force_preemptive = force_preemptive
91+
self.opportunistic_auth = opportunistic_auth
9292
self.principal = principal
9393
self.hostname_override = hostname_override
9494
self.sanitize_mutual_error_response = sanitize_mutual_error_response
@@ -283,7 +283,7 @@ def deregister(self, response):
283283
response.request.deregister_hook('response', self.handle_response)
284284

285285
def __call__(self, request):
286-
if self.force_preemptive:
286+
if self.opportunistic_auth:
287287
# add Authorization header before we receive a 401
288288
# by the 401 handler
289289
host = urlparse(request.url).hostname

test_requests_gssapi.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,19 @@ def test_realm_override(self):
560560
usage="initiate", flags=gssflags, creds=None)
561561
fake_resp.assert_called_with("token")
562562

563+
def test_opportunistic_auth(self):
564+
with patch.multiple("gssapi.SecurityContext", __init__=fake_init,
565+
step=fake_resp):
566+
auth = requests_gssapi.HTTPSPNEGOAuth(opportunistic_auth=True)
567+
568+
request = requests.Request(url="http://www.example.org")
569+
570+
auth.__call__(request)
571+
572+
self.assertTrue('Authorization' in request.headers)
573+
self.assertEqual(request.headers.get('Authorization'),
574+
'Negotiate GSSRESPONSE')
575+
563576

564577
if __name__ == '__main__':
565578
unittest.main()

0 commit comments

Comments
 (0)