Skip to content

Commit 234f09c

Browse files
committed
Fixing str vs. bytes py3 issues in client tests
Various things now return bytes or require bytes. This fixes some of the test failures in python3 for test_51_client.
1 parent 56ec94e commit 234f09c

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

src/saml2/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ def get_xml_string_with_self_contained_assertion_within_encrypted_assertion(self
616616

617617
self.set_prefixes(tree.find(self.encrypted_assertion._to_element_tree().tag).find(assertion_tag), prefix_map)
618618

619-
return ElementTree.tostring(tree, encoding="UTF-8")
619+
return ElementTree.tostring(tree, encoding="UTF-8").decode('utf-8')
620620

621621
def set_prefixes(self, elem, prefix_map):
622622

src/saml2/sigver.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,15 +313,15 @@ def signed_instance_factory(instance, seccont, elements_to_sign=None):
313313
:return: A class instance if not signed otherwise a string
314314
"""
315315
if elements_to_sign:
316-
signed_xml = str(instance).encode('utf-8')
316+
signed_xml = str(instance)
317317
for (node_name, nodeid) in elements_to_sign:
318318
signed_xml = seccont.sign_statement(
319319
signed_xml, node_name=node_name, node_id=nodeid)
320320

321321
#print("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
322322
#print("%s" % signed_xml)
323323
#print("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
324-
return signed_xml.decode('utf-8')
324+
return signed_xml
325325
else:
326326
return instance
327327

@@ -809,7 +809,7 @@ def encrypt_assertion(self, statement, enc_key, template,
809809
if not output:
810810
raise EncryptError(_stderr)
811811

812-
return output
812+
return output.decode('utf-8')
813813

814814
def decrypt(self, enctext, key_file):
815815
"""
@@ -861,7 +861,7 @@ def sign_statement(self, statement, node_name, key_file, node_id,
861861
# this doesn't work if --store-signatures are used
862862
if stdout == "":
863863
if signed_statement:
864-
return signed_statement
864+
return signed_statement.decode('utf-8')
865865
logger.error(
866866
"Signing operation failed :\nstdout : %s\nstderr : %s" % (
867867
stdout, stderr))
@@ -1336,7 +1336,9 @@ def decrypt_keys(self, enctext, keys=None):
13361336
return _enctext
13371337
for _key in keys:
13381338
if _key is not None and len(_key.strip()) > 0:
1339-
_, key_file = make_temp("%s" % _key, decode=False)
1339+
if not isinstance(_key, six.binary_type):
1340+
_key = str(_key).encode('ascii')
1341+
_, key_file = make_temp(_key, decode=False)
13401342
_enctext = self.crypto.decrypt(enctext, key_file)
13411343
if _enctext is not None and len(_enctext) > 0:
13421344
return _enctext

tests/test_51_client.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def test_create_attribute_query1(self):
160160
"E8042FB4-4D5B-48C3-8E14-8EDD852790DD",
161161
format=saml.NAMEID_FORMAT_PERSISTENT,
162162
message_id="id1")
163-
reqstr = "%s" % req.to_string()
163+
reqstr = "%s" % req.to_string().decode('utf-8')
164164

165165
assert req.destination == "https://idp.example.com/idp/"
166166
assert req.id == "id1"
@@ -335,7 +335,7 @@ def test_response_1(self):
335335

336336
resp_str = "%s" % resp
337337

338-
resp_str = base64.encodestring(resp_str)
338+
resp_str = base64.encodestring(resp_str.encode('utf-8'))
339339

340340
authn_response = self.client.parse_authn_request_response(
341341
resp_str, BINDING_HTTP_POST,
@@ -377,7 +377,7 @@ def test_response_1(self):
377377
378378
authn=AUTHN)
379379

380-
resp_str = base64.encodestring(resp_str)
380+
resp_str = base64.encodestring(resp_str.encode('utf-8'))
381381

382382
self.client.parse_authn_request_response(
383383
resp_str, BINDING_HTTP_POST,
@@ -427,7 +427,7 @@ def test_response_2(self):
427427

428428
resp_str = "%s" % resp
429429

430-
resp_str = base64.encodestring(resp_str)
430+
resp_str = base64.encodestring(resp_str.encode('utf-8'))
431431

432432
authn_response = _client.parse_authn_request_response(
433433
resp_str, BINDING_HTTP_POST,
@@ -462,7 +462,7 @@ def test_response_3(self):
462462

463463
resp_str = "%s" % resp
464464

465-
resp_str = base64.encodestring(resp_str)
465+
resp_str = base64.encodestring(resp_str.encode('utf-8'))
466466

467467
authn_response = _client.parse_authn_request_response(
468468
resp_str, BINDING_HTTP_POST,
@@ -497,7 +497,7 @@ def test_response_4(self):
497497

498498
resp_str = "%s" % resp
499499

500-
resp_str = base64.encodestring(resp_str)
500+
resp_str = base64.encodestring(resp_str.encode('utf-8'))
501501

502502
authn_response = _client.parse_authn_request_response(
503503
resp_str, BINDING_HTTP_POST,
@@ -541,7 +541,7 @@ def test_response_5(self):
541541

542542
resp_str = "%s" % resp
543543

544-
resp_str = base64.encodestring(resp_str)
544+
resp_str = base64.encodestring(resp_str.encode('utf-8'))
545545

546546
authn_response = _client.parse_authn_request_response(
547547
resp_str, BINDING_HTTP_POST,
@@ -594,7 +594,7 @@ def test_response_6(self):
594594

595595
resp_str = "%s" % resp
596596

597-
resp_str = base64.encodestring(resp_str)
597+
resp_str = base64.encodestring(resp_str.encode('utf-8'))
598598

599599
authn_response = _client.parse_authn_request_response(
600600
resp_str, BINDING_HTTP_POST,
@@ -629,7 +629,7 @@ def test_response_7(self):
629629

630630
resp_str = "%s" % resp
631631

632-
resp_str = base64.encodestring(resp_str)
632+
resp_str = base64.encodestring(resp_str.encode('utf-8'))
633633

634634
authn_response = _client.parse_authn_request_response(
635635
resp_str, BINDING_HTTP_POST,
@@ -672,7 +672,7 @@ def test_response_8(self):
672672

673673
resp_str = "%s" % resp
674674

675-
resp_str = base64.encodestring(resp_str)
675+
resp_str = base64.encodestring(resp_str.encode('utf-8'))
676676

677677
authn_response = _client.parse_authn_request_response(
678678
resp_str, BINDING_HTTP_POST,
@@ -904,7 +904,7 @@ def test_sign_then_encrypt_assertion_advice_1(self):
904904

905905
#seresp = samlp.response_from_string(enctext)
906906

907-
resp_str = base64.encodestring(enctext)
907+
resp_str = base64.encodestring(enctext.encode('utf-8'))
908908
# Now over to the client side
909909
resp = self.client.parse_authn_request_response(
910910
resp_str, BINDING_HTTP_POST,
@@ -1138,7 +1138,7 @@ def test_sign_then_encrypt_assertion_advice_2(self):
11381138

11391139
#seresp = samlp.response_from_string(enctext)
11401140

1141-
resp_str = base64.encodestring("%s" % response)
1141+
resp_str = base64.encodestring(str(response).encode('utf-8'))
11421142
# Now over to the client side
11431143
resp = self.client.parse_authn_request_response(
11441144
resp_str, BINDING_HTTP_POST,

0 commit comments

Comments
 (0)