Merge branch 'master' of github.com:rohe/pysaml2

This commit is contained in:
Roland Hedberg
2014-09-12 15:14:55 +02:00
2 changed files with 19 additions and 12 deletions

View File

@@ -106,6 +106,11 @@ class CertificateError(SigverError):
pass
def read_file(*args, **kwargs):
with open(*args, **kwargs) as handler:
return handler.read()
def rm_xmltag(statement):
try:
_t = statement.startswith(XMLTAG)
@@ -540,7 +545,7 @@ def pem_format(key):
def import_rsa_key_from_file(filename):
return RSA.importKey(open(filename, 'r').read())
return RSA.importKey(read_file(filename, 'r'))
def parse_xmlsec_output(output):
@@ -648,11 +653,13 @@ def read_cert_from_file(cert_file, cert_type):
:param cert_type: The certificate type
:return: A base64 encoded certificate as a string or the empty string
"""
if not cert_file:
return ""
if cert_type == "pem":
line = open(cert_file).read().split("\n")
line = read_file(cert_file).split("\n")
if line[0] == "-----BEGIN CERTIFICATE-----":
line = line[1:]
elif line[0] == "-----BEGIN PUBLIC KEY-----":
@@ -672,7 +679,7 @@ def read_cert_from_file(cert_file, cert_type):
return "".join(line)
if cert_type in ["der", "cer", "crt"]:
data = open(cert_file).read()
data = read_file(cert_file)
return base64.b64encode(str(data))

View File

@@ -15,16 +15,16 @@ from py.test import raises
from pathutils import full_path
SUCCESS_STATUS = """<?xml version=\'1.0\' encoding=\'UTF-8\'?>
<ns0:Status xmlns:ns0="urn:oasis:names:tc:SAML:2.0:protocol"><ns0:StatusCode
Value="urn:oasis:names:tc:SAML:2.0:status:Success" /></ns0:Status>"""
SUCCESS_STATUS = ('<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n'
'<ns0:Status xmlns:ns0="urn:oasis:names:tc:SAML:2.0:protocol"><ns0:StatusCode '
'Value="urn:oasis:names:tc:SAML:2.0:status:Success" /></ns0:Status>')
ERROR_STATUS = """<?xml version='1.0' encoding='UTF-8'?>
<ns0:Status xmlns:ns0="urn:oasis:names:tc:SAML:2.0:protocol"><ns0:StatusCode
Value="urn:oasis:names:tc:SAML:2.0:status:Responder"><ns0:StatusCode
Value="urn:oasis:names:tc:SAML:2.0:status:UnknownPrincipal"
/></ns0:StatusCode><ns0:StatusMessage>Error resolving
principal</ns0:StatusMessage></ns0:Status>"""
ERROR_STATUS = ('<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n'
'<ns0:Status xmlns:ns0="urn:oasis:names:tc:SAML:2.0:protocol"><ns0:StatusCode '
'Value="urn:oasis:names:tc:SAML:2.0:status:Responder"><ns0:StatusCode '
'Value="urn:oasis:names:tc:SAML:2.0:status:UnknownPrincipal" '
'/></ns0:StatusCode><ns0:StatusMessage>Error resolving '
'principal</ns0:StatusMessage></ns0:Status>')
def _eq(l1, l2):