Make make_metadata ignore things that doesn't concern it
This commit is contained in:
@@ -31,7 +31,7 @@ CONFIG={
|
||||
"key_file" : "pki/mykey.pem",
|
||||
"cert_file" : "pki/mycert.pem",
|
||||
"metadata" : {
|
||||
#"local": ["../sp/sp.xml"],
|
||||
"local": ["../sp/sp.xml"],
|
||||
},
|
||||
"organization": {
|
||||
"display_name": "Rolands Identiteter",
|
||||
|
||||
@@ -27,7 +27,7 @@ CONFIG = {
|
||||
"cert_file" : "pki/mycert.pem",
|
||||
"attribute_map_dir" : "./attributemaps",
|
||||
"metadata" : {
|
||||
#"local": ["../idp/idp.xml"],
|
||||
"local": ["../idp/idp.xml"],
|
||||
},
|
||||
# -- below used by make_metadata --
|
||||
"organization": {
|
||||
|
||||
@@ -113,7 +113,7 @@ class Config(object):
|
||||
else:
|
||||
return object.__getattribute__(self, item)
|
||||
|
||||
def load_special(self, cnf, typ):
|
||||
def load_special(self, cnf, typ, metadata_construction=False):
|
||||
for arg in SPEC[typ]:
|
||||
try:
|
||||
self._attr[typ][arg] = cnf[arg]
|
||||
@@ -121,10 +121,10 @@ class Config(object):
|
||||
pass
|
||||
|
||||
self.context = typ
|
||||
self.load_complex(cnf, typ)
|
||||
self.load_complex(cnf, typ, metadata_construction=metadata_construction)
|
||||
self.context = self.def_context
|
||||
|
||||
def load_complex(self, cnf, typ=""):
|
||||
def load_complex(self, cnf, typ="", metadata_construction=False):
|
||||
_attr_typ = self._attr[typ]
|
||||
try:
|
||||
_attr_typ["policy"] = Policy(cnf["policy"])
|
||||
@@ -140,12 +140,13 @@ class Config(object):
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
try:
|
||||
_attr_typ["metadata"] = self.load_metadata(cnf["metadata"])
|
||||
except KeyError:
|
||||
pass
|
||||
if not metadata_construction:
|
||||
try:
|
||||
_attr_typ["metadata"] = self.load_metadata(cnf["metadata"])
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
def load(self, cnf):
|
||||
def load(self, cnf, metadata_construction=False):
|
||||
|
||||
for arg in COMMON_ARGS:
|
||||
try:
|
||||
@@ -156,24 +157,27 @@ class Config(object):
|
||||
if "service" in cnf:
|
||||
for typ in ["aa", "idp", "sp"]:
|
||||
try:
|
||||
self.load_special(cnf["service"][typ], typ)
|
||||
self.load_special(cnf["service"][typ], typ,
|
||||
metadata_construction=metadata_construction)
|
||||
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
if "xmlsec_binary" not in self._attr[""]:
|
||||
self._attr[""]["xmlsec_binary"] = get_xmlsec_binary()
|
||||
if not metadata_construction:
|
||||
if "xmlsec_binary" not in self._attr[""]:
|
||||
self._attr[""]["xmlsec_binary"] = get_xmlsec_binary()
|
||||
|
||||
self.load_complex(cnf)
|
||||
self.load_complex(cnf, metadata_construction=metadata_construction)
|
||||
self.context = self.def_context
|
||||
|
||||
return self
|
||||
|
||||
def load_file(self, config_file):
|
||||
def load_file(self, config_file, metadata_construction=False):
|
||||
if sys.path[0] != ".":
|
||||
sys.path.insert(0, ".")
|
||||
mod = import_module(config_file)
|
||||
#return self.load(eval(open(config_file).read()))
|
||||
return self.load(mod.CONFIG)
|
||||
return self.load(mod.CONFIG, metadata_construction)
|
||||
|
||||
def load_metadata(self, metadata_conf):
|
||||
""" Loads metadata into an internal structure """
|
||||
|
||||
@@ -27,6 +27,9 @@ SP = {
|
||||
},
|
||||
}
|
||||
},
|
||||
"metadata": {
|
||||
"local": ["foo.xml"],
|
||||
},
|
||||
"attribute_map_dir" : "attributemaps",
|
||||
}
|
||||
|
||||
@@ -50,7 +53,10 @@ IDP = {
|
||||
},
|
||||
"scope": ["example.org"]
|
||||
}
|
||||
}
|
||||
},
|
||||
"metadata": {
|
||||
"local": ["bar.xml"],
|
||||
},
|
||||
}
|
||||
|
||||
def test_org_1():
|
||||
@@ -161,7 +167,7 @@ def test_optional_attributes():
|
||||
assert ras[0].is_required == "false"
|
||||
|
||||
def test_do_sp_sso_descriptor():
|
||||
conf = SPConfig().load(SP)
|
||||
conf = SPConfig().load(SP, metadata_construction=True)
|
||||
spsso = metadata.do_sp_sso_descriptor(conf)
|
||||
|
||||
assert isinstance(spsso, md.SPSSODescriptor)
|
||||
@@ -174,7 +180,7 @@ def test_do_sp_sso_descriptor():
|
||||
|
||||
assert spsso.authn_requests_signed == "false"
|
||||
assert spsso.want_assertions_signed == "true"
|
||||
len (spsso.attribute_consuming_service) == 1
|
||||
assert len (spsso.attribute_consuming_service) == 1
|
||||
acs = spsso.attribute_consuming_service[0]
|
||||
print acs.keyswv()
|
||||
assert _eq(acs.keyswv(), ['requested_attribute', 'service_name',
|
||||
@@ -192,7 +198,7 @@ def test_entity_description():
|
||||
confd = SPConfig().load_file("server_conf")
|
||||
print confd.attribute_converters
|
||||
entd = metadata.entity_descriptor(confd, 1)
|
||||
assert entd != None
|
||||
assert entd is not None
|
||||
print entd.keyswv()
|
||||
assert _eq(entd.keyswv(), ['valid_until', 'entity_id', 'contact_person',
|
||||
'spsso_descriptor', 'organization'])
|
||||
@@ -200,7 +206,7 @@ def test_entity_description():
|
||||
assert entd.entity_id == "urn:mace:example.com:saml:roland:sp"
|
||||
|
||||
def test_do_idp_sso_descriptor():
|
||||
conf = IdPConfig().load(IDP)
|
||||
conf = IdPConfig().load(IDP, metadata_construction=True)
|
||||
idpsso = metadata.do_idp_sso_descriptor(conf)
|
||||
|
||||
assert isinstance(idpsso, md.IDPSSODescriptor)
|
||||
|
||||
@@ -75,7 +75,7 @@ def main(args):
|
||||
sys.path.insert(0, bas)
|
||||
if fil.endswith(".py"):
|
||||
fil = fil[:-3]
|
||||
cnf = Config().load_file(fil)
|
||||
cnf = Config().load_file(fil, metadata_construction=True)
|
||||
eds.append(entity_descriptor(cnf, valid_for))
|
||||
|
||||
secc = SecurityContext(xmlsec, keyfile)
|
||||
|
||||
Reference in New Issue
Block a user