|
1 | 1 | #!/usr/bin/env python
|
2 | 2 | # -*- coding: utf-8 -*-
|
3 | 3 |
|
4 |
| -import base64 |
| 4 | +from base64 import encodebytes as b64encode |
5 | 5 | import uuid
|
6 | 6 | import six
|
7 | 7 | from six.moves.urllib import parse
|
|
51 | 51 | "authn_auth": "http://www.example.com/login"
|
52 | 52 | }
|
53 | 53 |
|
54 |
| -encode_fn = getattr(base64, 'encodebytes', base64.encodestring) |
55 |
| - |
56 | 54 |
|
57 | 55 | def generate_cert():
|
58 | 56 | sn = uuid.uuid4().urn
|
@@ -449,7 +447,7 @@ def test_response_1(self):
|
449 | 447 |
|
450 | 448 | resp_str = "%s" % resp
|
451 | 449 |
|
452 |
| - resp_str = encode_fn(resp_str.encode()) |
| 450 | + resp_str = b64encode(resp_str.encode()) |
453 | 451 |
|
454 | 452 | authn_response = self.client.parse_authn_request_response(
|
455 | 453 | resp_str, BINDING_HTTP_POST,
|
@@ -491,7 +489,7 @@ def test_response_1(self):
|
491 | 489 |
|
492 | 490 | authn=AUTHN)
|
493 | 491 |
|
494 |
| - resp_str = encode_fn(resp_str.encode()) |
| 492 | + resp_str = b64encode(resp_str.encode()) |
495 | 493 |
|
496 | 494 | self.client.parse_authn_request_response(
|
497 | 495 | resp_str, BINDING_HTTP_POST,
|
@@ -540,7 +538,7 @@ def test_response_2(self):
|
540 | 538 |
|
541 | 539 | resp_str = "%s" % resp
|
542 | 540 |
|
543 |
| - resp_str = encode_fn(resp_str.encode()) |
| 541 | + resp_str = b64encode(resp_str.encode()) |
544 | 542 |
|
545 | 543 | authn_response = _client.parse_authn_request_response(
|
546 | 544 | resp_str, BINDING_HTTP_POST,
|
@@ -575,7 +573,7 @@ def test_response_3(self):
|
575 | 573 |
|
576 | 574 | resp_str = "%s" % resp
|
577 | 575 |
|
578 |
| - resp_str = encode_fn(resp_str.encode()) |
| 576 | + resp_str = b64encode(resp_str.encode()) |
579 | 577 |
|
580 | 578 | authn_response = _client.parse_authn_request_response(
|
581 | 579 | resp_str, BINDING_HTTP_POST,
|
@@ -610,7 +608,7 @@ def test_response_4(self):
|
610 | 608 |
|
611 | 609 | resp_str = "%s" % resp
|
612 | 610 |
|
613 |
| - resp_str = encode_fn(resp_str.encode()) |
| 611 | + resp_str = b64encode(resp_str.encode()) |
614 | 612 |
|
615 | 613 | authn_response = _client.parse_authn_request_response(
|
616 | 614 | resp_str, BINDING_HTTP_POST,
|
@@ -654,7 +652,7 @@ def test_response_5(self):
|
654 | 652 |
|
655 | 653 | resp_str = "%s" % resp
|
656 | 654 |
|
657 |
| - resp_str = encode_fn(resp_str.encode()) |
| 655 | + resp_str = b64encode(resp_str.encode()) |
658 | 656 |
|
659 | 657 | authn_response = _client.parse_authn_request_response(
|
660 | 658 | resp_str, BINDING_HTTP_POST,
|
@@ -707,7 +705,7 @@ def test_response_6(self):
|
707 | 705 |
|
708 | 706 | resp_str = "%s" % resp
|
709 | 707 |
|
710 |
| - resp_str = encode_fn(resp_str.encode()) |
| 708 | + resp_str = b64encode(resp_str.encode()) |
711 | 709 |
|
712 | 710 | authn_response = _client.parse_authn_request_response(
|
713 | 711 | resp_str, BINDING_HTTP_POST,
|
@@ -743,7 +741,7 @@ def test_response_7(self):
|
743 | 741 |
|
744 | 742 | resp_str = "%s" % resp
|
745 | 743 |
|
746 |
| - resp_str = encode_fn(resp_str.encode()) |
| 744 | + resp_str = b64encode(resp_str.encode()) |
747 | 745 |
|
748 | 746 | authn_response = _client.parse_authn_request_response(
|
749 | 747 | resp_str, BINDING_HTTP_POST,
|
@@ -786,7 +784,7 @@ def test_response_8(self):
|
786 | 784 |
|
787 | 785 | resp_str = "%s" % resp
|
788 | 786 |
|
789 |
| - resp_str = encode_fn(resp_str.encode()) |
| 787 | + resp_str = b64encode(resp_str.encode()) |
790 | 788 |
|
791 | 789 | authn_response = _client.parse_authn_request_response(
|
792 | 790 | resp_str, BINDING_HTTP_POST,
|
@@ -837,7 +835,7 @@ def test_response_no_name_id(self):
|
837 | 835 |
|
838 | 836 | # Cast the response to a string and encode it to mock up the payload
|
839 | 837 | # 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()) |
841 | 839 |
|
842 | 840 | # We do not need the client to verify a signature for this test.
|
843 | 841 | client.want_assertions_signed = False
|
@@ -1014,7 +1012,7 @@ def test_sign_then_encrypt_assertion2(self):
|
1014 | 1012 |
|
1015 | 1013 | # seresp = samlp.response_from_string(enctext)
|
1016 | 1014 |
|
1017 |
| - resp_str = encode_fn(enctext.encode()) |
| 1015 | + resp_str = b64encode(enctext.encode()) |
1018 | 1016 | # Now over to the client side
|
1019 | 1017 | # Explicitely allow unsigned responses for this and the following 2 tests
|
1020 | 1018 | self.client.want_response_signed = False
|
@@ -1117,7 +1115,7 @@ def test_sign_then_encrypt_assertion_advice_1(self):
|
1117 | 1115 |
|
1118 | 1116 | # seresp = samlp.response_from_string(enctext)
|
1119 | 1117 |
|
1120 |
| - resp_str = encode_fn(enctext.encode()) |
| 1118 | + resp_str = b64encode(enctext.encode()) |
1121 | 1119 | # Now over to the client side
|
1122 | 1120 | resp = self.client.parse_authn_request_response(
|
1123 | 1121 | resp_str, BINDING_HTTP_POST,
|
@@ -1402,7 +1400,7 @@ def test_sign_then_encrypt_assertion_advice_2(self):
|
1402 | 1400 |
|
1403 | 1401 | # seresp = samlp.response_from_string(enctext)
|
1404 | 1402 |
|
1405 |
| - resp_str = encode_fn(str(response).encode()) |
| 1403 | + resp_str = b64encode(str(response).encode()) |
1406 | 1404 | # Now over to the client side
|
1407 | 1405 | resp = self.client.parse_authn_request_response(
|
1408 | 1406 | resp_str, BINDING_HTTP_POST,
|
@@ -1566,7 +1564,7 @@ def test_signature_wants(self):
|
1566 | 1564 | outstanding = {"id1": "http://foo.example.com/service"}
|
1567 | 1565 |
|
1568 | 1566 | def create_authn_response(**kwargs):
|
1569 |
| - return encode_fn( |
| 1567 | + return b64encode( |
1570 | 1568 | str(self.server.create_authn_response(**kwargs)).encode())
|
1571 | 1569 |
|
1572 | 1570 | def parse_authn_response(response):
|
@@ -1955,7 +1953,7 @@ def test_response_1(self):
|
1955 | 1953 |
|
1956 | 1954 | resp_str = "%s" % resp
|
1957 | 1955 |
|
1958 |
| - resp_str = encode_fn(resp_str.encode('utf-8')) |
| 1956 | + resp_str = b64encode(resp_str.encode('utf-8')) |
1959 | 1957 |
|
1960 | 1958 | authn_response = self.client.parse_authn_request_response(
|
1961 | 1959 | resp_str, BINDING_HTTP_POST,
|
@@ -1995,7 +1993,7 @@ def test_response_1(self):
|
1995 | 1993 |
|
1996 | 1994 | authn=AUTHN)
|
1997 | 1995 |
|
1998 |
| - resp_str = encode_fn(resp_str.encode()) |
| 1996 | + resp_str = b64encode(resp_str.encode()) |
1999 | 1997 |
|
2000 | 1998 | self.client.parse_authn_request_response(
|
2001 | 1999 | resp_str, BINDING_HTTP_POST,
|
@@ -2044,7 +2042,7 @@ def test_response_2(self):
|
2044 | 2042 |
|
2045 | 2043 | resp_str = "%s" % resp
|
2046 | 2044 |
|
2047 |
| - resp_str = encode_fn(resp_str.encode()) |
| 2045 | + resp_str = b64encode(resp_str.encode()) |
2048 | 2046 |
|
2049 | 2047 | authn_response = _client.parse_authn_request_response(
|
2050 | 2048 | resp_str, BINDING_HTTP_POST,
|
@@ -2079,7 +2077,7 @@ def test_response_3(self):
|
2079 | 2077 |
|
2080 | 2078 | resp_str = "%s" % resp
|
2081 | 2079 |
|
2082 |
| - resp_str = encode_fn(resp_str.encode()) |
| 2080 | + resp_str = b64encode(resp_str.encode()) |
2083 | 2081 |
|
2084 | 2082 | authn_response = _client.parse_authn_request_response(
|
2085 | 2083 | resp_str, BINDING_HTTP_POST,
|
@@ -2114,7 +2112,7 @@ def test_response_4(self):
|
2114 | 2112 |
|
2115 | 2113 | resp_str = "%s" % resp
|
2116 | 2114 |
|
2117 |
| - resp_str = encode_fn(resp_str.encode()) |
| 2115 | + resp_str = b64encode(resp_str.encode()) |
2118 | 2116 |
|
2119 | 2117 | authn_response = _client.parse_authn_request_response(
|
2120 | 2118 | resp_str, BINDING_HTTP_POST,
|
@@ -2158,7 +2156,7 @@ def test_response_5(self):
|
2158 | 2156 |
|
2159 | 2157 | resp_str = "%s" % resp
|
2160 | 2158 |
|
2161 |
| - resp_str = encode_fn(resp_str.encode()) |
| 2159 | + resp_str = b64encode(resp_str.encode()) |
2162 | 2160 |
|
2163 | 2161 | authn_response = _client.parse_authn_request_response(
|
2164 | 2162 | resp_str, BINDING_HTTP_POST,
|
@@ -2211,7 +2209,7 @@ def test_response_6(self):
|
2211 | 2209 |
|
2212 | 2210 | resp_str = "%s" % resp
|
2213 | 2211 |
|
2214 |
| - resp_str = encode_fn(resp_str.encode()) |
| 2212 | + resp_str = b64encode(resp_str.encode()) |
2215 | 2213 |
|
2216 | 2214 | authn_response = _client.parse_authn_request_response(
|
2217 | 2215 | resp_str, BINDING_HTTP_POST,
|
@@ -2247,7 +2245,7 @@ def test_response_7(self):
|
2247 | 2245 |
|
2248 | 2246 | resp_str = "%s" % resp
|
2249 | 2247 |
|
2250 |
| - resp_str = encode_fn(resp_str.encode()) |
| 2248 | + resp_str = b64encode(resp_str.encode()) |
2251 | 2249 |
|
2252 | 2250 | authn_response = _client.parse_authn_request_response(
|
2253 | 2251 | resp_str, BINDING_HTTP_POST,
|
@@ -2290,7 +2288,7 @@ def test_response_8(self):
|
2290 | 2288 |
|
2291 | 2289 | resp_str = "%s" % resp
|
2292 | 2290 |
|
2293 |
| - resp_str = encode_fn(resp_str.encode()) |
| 2291 | + resp_str = b64encode(resp_str.encode()) |
2294 | 2292 |
|
2295 | 2293 | authn_response = _client.parse_authn_request_response(
|
2296 | 2294 | resp_str, BINDING_HTTP_POST,
|
@@ -2347,9 +2345,9 @@ def test_response_no_name_id(self):
|
2347 | 2345 | # Cast the response to a string and encode it to mock up the payload
|
2348 | 2346 | # the SP client is expected to receive via HTTP POST binding.
|
2349 | 2347 | if six.PY2:
|
2350 |
| - resp_str = encode_fn(str(resp)) |
| 2348 | + resp_str = b64encode(str(resp)) |
2351 | 2349 | else:
|
2352 |
| - resp_str = encode_fn(bytes(str(resp), 'utf-8')) |
| 2350 | + resp_str = b64encode(bytes(str(resp), 'utf-8')) |
2353 | 2351 |
|
2354 | 2352 |
|
2355 | 2353 | # We do not need the client to verify a signature for this test.
|
@@ -2381,9 +2379,9 @@ def test_response_error_status(self):
|
2381 | 2379 | # Cast the response to a string and encode it to mock up the payload
|
2382 | 2380 | # the SP client is expected to receive via HTTP POST binding.
|
2383 | 2381 | if six.PY2:
|
2384 |
| - resp_str = encode_fn(str(resp)) |
| 2382 | + resp_str = b64encode(str(resp)) |
2385 | 2383 | else:
|
2386 |
| - resp_str = encode_fn(bytes(str(resp), 'utf-8')) |
| 2384 | + resp_str = b64encode(bytes(str(resp), 'utf-8')) |
2387 | 2385 |
|
2388 | 2386 | # We do not need the client to verify a signature for this test.
|
2389 | 2387 | client.want_assertions_signed = False
|
@@ -2412,9 +2410,9 @@ def test_response_error_status_non_standard_status_code(self):
|
2412 | 2410 | # Cast the response to a string and encode it to mock up the payload
|
2413 | 2411 | # the SP client is expected to receive via HTTP POST binding.
|
2414 | 2412 | if six.PY2:
|
2415 |
| - resp_str = encode_fn(str(resp)) |
| 2413 | + resp_str = b64encode(str(resp)) |
2416 | 2414 | else:
|
2417 |
| - resp_str = encode_fn(bytes(str(resp), 'utf-8')) |
| 2415 | + resp_str = b64encode(bytes(str(resp), 'utf-8')) |
2418 | 2416 |
|
2419 | 2417 | # We do not need the client to verify a signature for this test.
|
2420 | 2418 | client.want_assertions_signed = False
|
@@ -2589,7 +2587,7 @@ def test_sign_then_encrypt_assertion2(self):
|
2589 | 2587 |
|
2590 | 2588 | # seresp = samlp.response_from_string(enctext)
|
2591 | 2589 |
|
2592 |
| - resp_str = encode_fn(enctext.encode()) |
| 2590 | + resp_str = b64encode(enctext.encode()) |
2593 | 2591 | # Now over to the client side
|
2594 | 2592 | # Explicitely allow unsigned responses for this and the following 2 tests
|
2595 | 2593 | self.client.want_response_signed = False
|
@@ -2693,9 +2691,9 @@ def test_sign_then_encrypt_assertion_advice_1(self):
|
2693 | 2691 | # seresp = samlp.response_from_string(enctext)
|
2694 | 2692 |
|
2695 | 2693 | if six.PY2:
|
2696 |
| - resp_str = encode_fn(enctext.encode('utf-8')) |
| 2694 | + resp_str = b64encode(enctext.encode('utf-8')) |
2697 | 2695 | else:
|
2698 |
| - resp_str = encode_fn(bytes(enctext, 'utf-8')) |
| 2696 | + resp_str = b64encode(bytes(enctext, 'utf-8')) |
2699 | 2697 |
|
2700 | 2698 | # Now over to the client side
|
2701 | 2699 | resp = self.client.parse_authn_request_response(
|
@@ -2978,7 +2976,7 @@ def test_sign_then_encrypt_assertion_advice_2(self):
|
2978 | 2976 |
|
2979 | 2977 | # seresp = samlp.response_from_string(enctext)
|
2980 | 2978 |
|
2981 |
| - resp_str = encode_fn(response.to_string()) |
| 2979 | + resp_str = b64encode(response.to_string()) |
2982 | 2980 |
|
2983 | 2981 | # Now over to the client side
|
2984 | 2982 | resp = self.client.parse_authn_request_response(
|
|
0 commit comments