Fixed some tests.

This commit is contained in:
Roland Hedberg
2014-03-09 17:53:38 +01:00
parent 19a608ccc0
commit 2ff66de237
3 changed files with 25 additions and 20 deletions

View File

@@ -200,7 +200,7 @@ class MetaData(object):
def load(self): def load(self):
self.parse(self.metadata) self.parse(self.metadata)
def _service(self, entity_id, typ, service, binding=None): def service(self, entity_id, typ, service, binding=None):
""" Get me all services with a specified """ Get me all services with a specified
entity ID and type, that supports the specified version of binding. entity ID and type, that supports the specified version of binding.
@@ -212,7 +212,7 @@ class MetaData(object):
Or if no binding was specified a list of 2-tuples (binding, srv) Or if no binding was specified a list of 2-tuples (binding, srv)
""" """
logger.debug("_service(%s, %s, %s, %s)" % (entity_id, typ, service, logger.debug("service(%s, %s, %s, %s)" % (entity_id, typ, service,
binding)) binding))
try: try:
srvs = [] srvs = []
@@ -239,7 +239,7 @@ class MetaData(object):
res[srv["binding"]].append(srv) res[srv["binding"]].append(srv)
except KeyError: except KeyError:
res[srv["binding"]] = [srv] res[srv["binding"]] = [srv]
logger.debug("_service => %s" % res) logger.debug("service => %s" % res)
return res return res
def ext_service(self, entity_id, typ, service, binding): def ext_service(self, entity_id, typ, service, binding):
@@ -272,7 +272,7 @@ class MetaData(object):
""" """
res = {} res = {}
for ent in self.keys(): for ent in self.keys():
bind = self._service(ent, typ, service, binding) bind = self.service(ent, typ, service, binding)
if bind: if bind:
res[ent] = bind res[ent] = bind
@@ -287,7 +287,7 @@ class MetaData(object):
:return: :return:
""" """
return self._service(entity_id, typ, service) return self.service(entity_id, typ, service)
def attribute_requirement(self, entity_id, index=0): def attribute_requirement(self, entity_id, index=0):
""" Returns what attributes the SP requires and which are optional """ Returns what attributes the SP requires and which are optional
@@ -553,10 +553,10 @@ class MetadataStore(object):
else: else:
self.load(key, val) self.load(key, val)
def _service(self, entity_id, typ, service, binding=None): def service(self, entity_id, typ, service, binding=None):
known_principal = False known_principal = False
for key, _md in self.metadata.items(): for key, _md in self.metadata.items():
srvs = _md._service(entity_id, typ, service, binding) srvs = _md.service(entity_id, typ, service, binding)
if srvs: if srvs:
return srvs return srvs
elif srvs is None: elif srvs is None:
@@ -592,14 +592,14 @@ class MetadataStore(object):
if binding is None: if binding is None:
binding = BINDING_HTTP_REDIRECT binding = BINDING_HTTP_REDIRECT
return self._service(entity_id, "idpsso_descriptor", return self.service(entity_id, "idpsso_descriptor",
"single_sign_on_service", binding) "single_sign_on_service", binding)
def name_id_mapping_service(self, entity_id, binding=None, typ="idpsso"): def name_id_mapping_service(self, entity_id, binding=None, typ="idpsso"):
# IDP # IDP
if binding is None: if binding is None:
binding = BINDING_HTTP_REDIRECT binding = BINDING_HTTP_REDIRECT
return self._service(entity_id, "idpsso_descriptor", return self.service(entity_id, "idpsso_descriptor",
"name_id_mapping_service", binding) "name_id_mapping_service", binding)
def authn_query_service(self, entity_id, binding=None, def authn_query_service(self, entity_id, binding=None,
@@ -607,7 +607,7 @@ class MetadataStore(object):
# AuthnAuthority # AuthnAuthority
if binding is None: if binding is None:
binding = BINDING_SOAP binding = BINDING_SOAP
return self._service(entity_id, "authn_authority_descriptor", return self.service(entity_id, "authn_authority_descriptor",
"authn_query_service", binding) "authn_query_service", binding)
def attribute_service(self, entity_id, binding=None, def attribute_service(self, entity_id, binding=None,
@@ -615,14 +615,14 @@ class MetadataStore(object):
# AttributeAuthority # AttributeAuthority
if binding is None: if binding is None:
binding = BINDING_HTTP_REDIRECT binding = BINDING_HTTP_REDIRECT
return self._service(entity_id, "attribute_authority_descriptor", return self.service(entity_id, "attribute_authority_descriptor",
"attribute_service", binding) "attribute_service", binding)
def authz_service(self, entity_id, binding=None, typ="pdp"): def authz_service(self, entity_id, binding=None, typ="pdp"):
# PDP # PDP
if binding is None: if binding is None:
binding = BINDING_SOAP binding = BINDING_SOAP
return self._service(entity_id, "pdp_descriptor", return self.service(entity_id, "pdp_descriptor",
"authz_service", binding) "authz_service", binding)
def assertion_id_request_service(self, entity_id, binding=None, typ=None): def assertion_id_request_service(self, entity_id, binding=None, typ=None):
@@ -631,7 +631,7 @@ class MetadataStore(object):
raise AttributeError("Missing type specification") raise AttributeError("Missing type specification")
if binding is None: if binding is None:
binding = BINDING_SOAP binding = BINDING_SOAP
return self._service(entity_id, "%s_descriptor" % typ, return self.service(entity_id, "%s_descriptor" % typ,
"assertion_id_request_service", binding) "assertion_id_request_service", binding)
def single_logout_service(self, entity_id, binding=None, typ=None): def single_logout_service(self, entity_id, binding=None, typ=None):
@@ -640,35 +640,35 @@ class MetadataStore(object):
raise AttributeError("Missing type specification") raise AttributeError("Missing type specification")
if binding is None: if binding is None:
binding = BINDING_HTTP_REDIRECT binding = BINDING_HTTP_REDIRECT
return self._service(entity_id, "%s_descriptor" % typ, return self.service(entity_id, "%s_descriptor" % typ,
"single_logout_service", binding) "single_logout_service", binding)
def manage_name_id_service(self, entity_id, binding=None, typ=None): def manage_name_id_service(self, entity_id, binding=None, typ=None):
# IDP + SP # IDP + SP
if binding is None: if binding is None:
binding = BINDING_HTTP_REDIRECT binding = BINDING_HTTP_REDIRECT
return self._service(entity_id, "%s_descriptor" % typ, return self.service(entity_id, "%s_descriptor" % typ,
"manage_name_id_service", binding) "manage_name_id_service", binding)
def artifact_resolution_service(self, entity_id, binding=None, typ=None): def artifact_resolution_service(self, entity_id, binding=None, typ=None):
# IDP + SP # IDP + SP
if binding is None: if binding is None:
binding = BINDING_HTTP_REDIRECT binding = BINDING_HTTP_REDIRECT
return self._service(entity_id, "%s_descriptor" % typ, return self.service(entity_id, "%s_descriptor" % typ,
"artifact_resolution_service", binding) "artifact_resolution_service", binding)
def assertion_consumer_service(self, entity_id, binding=None, _="spsso"): def assertion_consumer_service(self, entity_id, binding=None, _="spsso"):
# SP # SP
if binding is None: if binding is None:
binding = BINDING_HTTP_POST binding = BINDING_HTTP_POST
return self._service(entity_id, "spsso_descriptor", return self.service(entity_id, "spsso_descriptor",
"assertion_consumer_service", binding) "assertion_consumer_service", binding)
def attribute_consuming_service(self, entity_id, binding=None, _="spsso"): def attribute_consuming_service(self, entity_id, binding=None, _="spsso"):
# SP # SP
if binding is None: if binding is None:
binding = BINDING_HTTP_REDIRECT binding = BINDING_HTTP_REDIRECT
return self._service(entity_id, "spsso_descriptor", return self.service(entity_id, "spsso_descriptor",
"attribute_consuming_service", binding) "attribute_consuming_service", binding)
def discovery_response(self, entity_id, binding=None, _="spsso"): def discovery_response(self, entity_id, binding=None, _="spsso"):

View File

@@ -213,3 +213,7 @@ def test_xmlsec_cryptobackend():
t = TestPKCS11() t = TestPKCS11()
t.setup_class() t.setup_class()
t.test_SAML_sign_with_pkcs11() t.test_SAML_sign_with_pkcs11()
if __name__ == "__main__":
test_xmlsec_cryptobackend()

View File

@@ -30,8 +30,9 @@ class TestGenerateCertificates(unittest.TestCase):
osw = OpenSSLWrapper() osw = OpenSSLWrapper()
ca_cert, ca_key = osw.create_certificate(cert_info_ca, request=False, write_to_file=True, ca_cert, ca_key = osw.create_certificate(cert_info_ca, request=False,
cert_dir="/Users/haho0032/Develop/openSSL/pki") write_to_file=True,
cert_dir="pki")
req_cert_str, req_key_str = osw.create_certificate(cert_info, request=True) req_cert_str, req_key_str = osw.create_certificate(cert_info, request=True)