Skip to content

Commit ba26a7b

Browse files
author
Roland Hedberg
committed
Merge branch 'master' of github.com:rohe/pysaml2
2 parents 7c2fe90 + 5840047 commit ba26a7b

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

src/saml2/sigver.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ class CertificateError(SigverError):
106106
pass
107107

108108

109+
def read_file(*args, **kwargs):
110+
with open(*args, **kwargs) as handler:
111+
return handler.read()
112+
113+
109114
def rm_xmltag(statement):
110115
try:
111116
_t = statement.startswith(XMLTAG)
@@ -540,7 +545,7 @@ def pem_format(key):
540545

541546

542547
def import_rsa_key_from_file(filename):
543-
return RSA.importKey(open(filename, 'r').read())
548+
return RSA.importKey(read_file(filename, 'r'))
544549

545550

546551
def parse_xmlsec_output(output):
@@ -648,11 +653,13 @@ def read_cert_from_file(cert_file, cert_type):
648653
:param cert_type: The certificate type
649654
:return: A base64 encoded certificate as a string or the empty string
650655
"""
656+
657+
651658
if not cert_file:
652659
return ""
653660

654661
if cert_type == "pem":
655-
line = open(cert_file).read().split("\n")
662+
line = read_file(cert_file).split("\n")
656663
if line[0] == "-----BEGIN CERTIFICATE-----":
657664
line = line[1:]
658665
elif line[0] == "-----BEGIN PUBLIC KEY-----":
@@ -672,7 +679,7 @@ def read_cert_from_file(cert_file, cert_type):
672679
return "".join(line)
673680

674681
if cert_type in ["der", "cer", "crt"]:
675-
data = open(cert_file).read()
682+
data = read_file(cert_file)
676683
return base64.b64encode(str(data))
677684

678685

tests/test_12_s_utils.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@
1515

1616
from pathutils import full_path
1717

18-
SUCCESS_STATUS = """<?xml version=\'1.0\' encoding=\'UTF-8\'?>
19-
<ns0:Status xmlns:ns0="urn:oasis:names:tc:SAML:2.0:protocol"><ns0:StatusCode
20-
Value="urn:oasis:names:tc:SAML:2.0:status:Success" /></ns0:Status>"""
21-
22-
ERROR_STATUS = """<?xml version='1.0' encoding='UTF-8'?>
23-
<ns0:Status xmlns:ns0="urn:oasis:names:tc:SAML:2.0:protocol"><ns0:StatusCode
24-
Value="urn:oasis:names:tc:SAML:2.0:status:Responder"><ns0:StatusCode
25-
Value="urn:oasis:names:tc:SAML:2.0:status:UnknownPrincipal"
26-
/></ns0:StatusCode><ns0:StatusMessage>Error resolving
27-
principal</ns0:StatusMessage></ns0:Status>"""
18+
SUCCESS_STATUS = ('<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n'
19+
'<ns0:Status xmlns:ns0="urn:oasis:names:tc:SAML:2.0:protocol"><ns0:StatusCode '
20+
'Value="urn:oasis:names:tc:SAML:2.0:status:Success" /></ns0:Status>')
21+
22+
ERROR_STATUS = ('<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n'
23+
'<ns0:Status xmlns:ns0="urn:oasis:names:tc:SAML:2.0:protocol"><ns0:StatusCode '
24+
'Value="urn:oasis:names:tc:SAML:2.0:status:Responder"><ns0:StatusCode '
25+
'Value="urn:oasis:names:tc:SAML:2.0:status:UnknownPrincipal" '
26+
'/></ns0:StatusCode><ns0:StatusMessage>Error resolving '
27+
'principal</ns0:StatusMessage></ns0:Status>')
2828

2929

3030
def _eq(l1, l2):

0 commit comments

Comments
 (0)