Skip to content

Commit a0fd030

Browse files
committed
Use encodebytes in place of encodestring
Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent e0d0ccb commit a0fd030

File tree

1 file changed

+34
-36
lines changed

1 file changed

+34
-36
lines changed

tests/test_51_client.py

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33

4-
import base64
4+
from base64 import encodebytes as b64encode
55
import uuid
66
import six
77
from six.moves.urllib import parse
@@ -51,8 +51,6 @@
5151
"authn_auth": "http://www.example.com/login"
5252
}
5353

54-
encode_fn = getattr(base64, 'encodebytes', base64.encodestring)
55-
5654

5755
def generate_cert():
5856
sn = uuid.uuid4().urn
@@ -449,7 +447,7 @@ def test_response_1(self):
449447

450448
resp_str = "%s" % resp
451449

452-
resp_str = encode_fn(resp_str.encode())
450+
resp_str = b64encode(resp_str.encode())
453451

454452
authn_response = self.client.parse_authn_request_response(
455453
resp_str, BINDING_HTTP_POST,
@@ -491,7 +489,7 @@ def test_response_1(self):
491489
492490
authn=AUTHN)
493491

494-
resp_str = encode_fn(resp_str.encode())
492+
resp_str = b64encode(resp_str.encode())
495493

496494
self.client.parse_authn_request_response(
497495
resp_str, BINDING_HTTP_POST,
@@ -540,7 +538,7 @@ def test_response_2(self):
540538

541539
resp_str = "%s" % resp
542540

543-
resp_str = encode_fn(resp_str.encode())
541+
resp_str = b64encode(resp_str.encode())
544542

545543
authn_response = _client.parse_authn_request_response(
546544
resp_str, BINDING_HTTP_POST,
@@ -575,7 +573,7 @@ def test_response_3(self):
575573

576574
resp_str = "%s" % resp
577575

578-
resp_str = encode_fn(resp_str.encode())
576+
resp_str = b64encode(resp_str.encode())
579577

580578
authn_response = _client.parse_authn_request_response(
581579
resp_str, BINDING_HTTP_POST,
@@ -610,7 +608,7 @@ def test_response_4(self):
610608

611609
resp_str = "%s" % resp
612610

613-
resp_str = encode_fn(resp_str.encode())
611+
resp_str = b64encode(resp_str.encode())
614612

615613
authn_response = _client.parse_authn_request_response(
616614
resp_str, BINDING_HTTP_POST,
@@ -654,7 +652,7 @@ def test_response_5(self):
654652

655653
resp_str = "%s" % resp
656654

657-
resp_str = encode_fn(resp_str.encode())
655+
resp_str = b64encode(resp_str.encode())
658656

659657
authn_response = _client.parse_authn_request_response(
660658
resp_str, BINDING_HTTP_POST,
@@ -707,7 +705,7 @@ def test_response_6(self):
707705

708706
resp_str = "%s" % resp
709707

710-
resp_str = encode_fn(resp_str.encode())
708+
resp_str = b64encode(resp_str.encode())
711709

712710
authn_response = _client.parse_authn_request_response(
713711
resp_str, BINDING_HTTP_POST,
@@ -743,7 +741,7 @@ def test_response_7(self):
743741

744742
resp_str = "%s" % resp
745743

746-
resp_str = encode_fn(resp_str.encode())
744+
resp_str = b64encode(resp_str.encode())
747745

748746
authn_response = _client.parse_authn_request_response(
749747
resp_str, BINDING_HTTP_POST,
@@ -786,7 +784,7 @@ def test_response_8(self):
786784

787785
resp_str = "%s" % resp
788786

789-
resp_str = encode_fn(resp_str.encode())
787+
resp_str = b64encode(resp_str.encode())
790788

791789
authn_response = _client.parse_authn_request_response(
792790
resp_str, BINDING_HTTP_POST,
@@ -837,7 +835,7 @@ def test_response_no_name_id(self):
837835

838836
# Cast the response to a string and encode it to mock up the payload
839837
# the SP client is expected to receive via HTTP POST binding.
840-
resp_str = encode_fn(str(resp).encode())
838+
resp_str = b64encode(str(resp).encode())
841839

842840
# We do not need the client to verify a signature for this test.
843841
client.want_assertions_signed = False
@@ -1014,7 +1012,7 @@ def test_sign_then_encrypt_assertion2(self):
10141012

10151013
# seresp = samlp.response_from_string(enctext)
10161014

1017-
resp_str = encode_fn(enctext.encode())
1015+
resp_str = b64encode(enctext.encode())
10181016
# Now over to the client side
10191017
# Explicitely allow unsigned responses for this and the following 2 tests
10201018
self.client.want_response_signed = False
@@ -1117,7 +1115,7 @@ def test_sign_then_encrypt_assertion_advice_1(self):
11171115

11181116
# seresp = samlp.response_from_string(enctext)
11191117

1120-
resp_str = encode_fn(enctext.encode())
1118+
resp_str = b64encode(enctext.encode())
11211119
# Now over to the client side
11221120
resp = self.client.parse_authn_request_response(
11231121
resp_str, BINDING_HTTP_POST,
@@ -1402,7 +1400,7 @@ def test_sign_then_encrypt_assertion_advice_2(self):
14021400

14031401
# seresp = samlp.response_from_string(enctext)
14041402

1405-
resp_str = encode_fn(str(response).encode())
1403+
resp_str = b64encode(str(response).encode())
14061404
# Now over to the client side
14071405
resp = self.client.parse_authn_request_response(
14081406
resp_str, BINDING_HTTP_POST,
@@ -1566,7 +1564,7 @@ def test_signature_wants(self):
15661564
outstanding = {"id1": "http://foo.example.com/service"}
15671565

15681566
def create_authn_response(**kwargs):
1569-
return encode_fn(
1567+
return b64encode(
15701568
str(self.server.create_authn_response(**kwargs)).encode())
15711569

15721570
def parse_authn_response(response):
@@ -1955,7 +1953,7 @@ def test_response_1(self):
19551953

19561954
resp_str = "%s" % resp
19571955

1958-
resp_str = encode_fn(resp_str.encode('utf-8'))
1956+
resp_str = b64encode(resp_str.encode('utf-8'))
19591957

19601958
authn_response = self.client.parse_authn_request_response(
19611959
resp_str, BINDING_HTTP_POST,
@@ -1995,7 +1993,7 @@ def test_response_1(self):
19951993
19961994
authn=AUTHN)
19971995

1998-
resp_str = encode_fn(resp_str.encode())
1996+
resp_str = b64encode(resp_str.encode())
19991997

20001998
self.client.parse_authn_request_response(
20011999
resp_str, BINDING_HTTP_POST,
@@ -2044,7 +2042,7 @@ def test_response_2(self):
20442042

20452043
resp_str = "%s" % resp
20462044

2047-
resp_str = encode_fn(resp_str.encode())
2045+
resp_str = b64encode(resp_str.encode())
20482046

20492047
authn_response = _client.parse_authn_request_response(
20502048
resp_str, BINDING_HTTP_POST,
@@ -2079,7 +2077,7 @@ def test_response_3(self):
20792077

20802078
resp_str = "%s" % resp
20812079

2082-
resp_str = encode_fn(resp_str.encode())
2080+
resp_str = b64encode(resp_str.encode())
20832081

20842082
authn_response = _client.parse_authn_request_response(
20852083
resp_str, BINDING_HTTP_POST,
@@ -2114,7 +2112,7 @@ def test_response_4(self):
21142112

21152113
resp_str = "%s" % resp
21162114

2117-
resp_str = encode_fn(resp_str.encode())
2115+
resp_str = b64encode(resp_str.encode())
21182116

21192117
authn_response = _client.parse_authn_request_response(
21202118
resp_str, BINDING_HTTP_POST,
@@ -2158,7 +2156,7 @@ def test_response_5(self):
21582156

21592157
resp_str = "%s" % resp
21602158

2161-
resp_str = encode_fn(resp_str.encode())
2159+
resp_str = b64encode(resp_str.encode())
21622160

21632161
authn_response = _client.parse_authn_request_response(
21642162
resp_str, BINDING_HTTP_POST,
@@ -2211,7 +2209,7 @@ def test_response_6(self):
22112209

22122210
resp_str = "%s" % resp
22132211

2214-
resp_str = encode_fn(resp_str.encode())
2212+
resp_str = b64encode(resp_str.encode())
22152213

22162214
authn_response = _client.parse_authn_request_response(
22172215
resp_str, BINDING_HTTP_POST,
@@ -2247,7 +2245,7 @@ def test_response_7(self):
22472245

22482246
resp_str = "%s" % resp
22492247

2250-
resp_str = encode_fn(resp_str.encode())
2248+
resp_str = b64encode(resp_str.encode())
22512249

22522250
authn_response = _client.parse_authn_request_response(
22532251
resp_str, BINDING_HTTP_POST,
@@ -2290,7 +2288,7 @@ def test_response_8(self):
22902288

22912289
resp_str = "%s" % resp
22922290

2293-
resp_str = encode_fn(resp_str.encode())
2291+
resp_str = b64encode(resp_str.encode())
22942292

22952293
authn_response = _client.parse_authn_request_response(
22962294
resp_str, BINDING_HTTP_POST,
@@ -2347,9 +2345,9 @@ def test_response_no_name_id(self):
23472345
# Cast the response to a string and encode it to mock up the payload
23482346
# the SP client is expected to receive via HTTP POST binding.
23492347
if six.PY2:
2350-
resp_str = encode_fn(str(resp))
2348+
resp_str = b64encode(str(resp))
23512349
else:
2352-
resp_str = encode_fn(bytes(str(resp), 'utf-8'))
2350+
resp_str = b64encode(bytes(str(resp), 'utf-8'))
23532351

23542352

23552353
# We do not need the client to verify a signature for this test.
@@ -2381,9 +2379,9 @@ def test_response_error_status(self):
23812379
# Cast the response to a string and encode it to mock up the payload
23822380
# the SP client is expected to receive via HTTP POST binding.
23832381
if six.PY2:
2384-
resp_str = encode_fn(str(resp))
2382+
resp_str = b64encode(str(resp))
23852383
else:
2386-
resp_str = encode_fn(bytes(str(resp), 'utf-8'))
2384+
resp_str = b64encode(bytes(str(resp), 'utf-8'))
23872385

23882386
# We do not need the client to verify a signature for this test.
23892387
client.want_assertions_signed = False
@@ -2412,9 +2410,9 @@ def test_response_error_status_non_standard_status_code(self):
24122410
# Cast the response to a string and encode it to mock up the payload
24132411
# the SP client is expected to receive via HTTP POST binding.
24142412
if six.PY2:
2415-
resp_str = encode_fn(str(resp))
2413+
resp_str = b64encode(str(resp))
24162414
else:
2417-
resp_str = encode_fn(bytes(str(resp), 'utf-8'))
2415+
resp_str = b64encode(bytes(str(resp), 'utf-8'))
24182416

24192417
# We do not need the client to verify a signature for this test.
24202418
client.want_assertions_signed = False
@@ -2589,7 +2587,7 @@ def test_sign_then_encrypt_assertion2(self):
25892587

25902588
# seresp = samlp.response_from_string(enctext)
25912589

2592-
resp_str = encode_fn(enctext.encode())
2590+
resp_str = b64encode(enctext.encode())
25932591
# Now over to the client side
25942592
# Explicitely allow unsigned responses for this and the following 2 tests
25952593
self.client.want_response_signed = False
@@ -2693,9 +2691,9 @@ def test_sign_then_encrypt_assertion_advice_1(self):
26932691
# seresp = samlp.response_from_string(enctext)
26942692

26952693
if six.PY2:
2696-
resp_str = encode_fn(enctext.encode('utf-8'))
2694+
resp_str = b64encode(enctext.encode('utf-8'))
26972695
else:
2698-
resp_str = encode_fn(bytes(enctext, 'utf-8'))
2696+
resp_str = b64encode(bytes(enctext, 'utf-8'))
26992697

27002698
# Now over to the client side
27012699
resp = self.client.parse_authn_request_response(
@@ -2978,7 +2976,7 @@ def test_sign_then_encrypt_assertion_advice_2(self):
29782976

29792977
# seresp = samlp.response_from_string(enctext)
29802978

2981-
resp_str = encode_fn(response.to_string())
2979+
resp_str = b64encode(response.to_string())
29822980

29832981
# Now over to the client side
29842982
resp = self.client.parse_authn_request_response(

0 commit comments

Comments
 (0)