Make make_metadata ignore things that doesn't concern it

This commit is contained in:
Roland Hedberg
2011-04-07 12:25:51 +02:00
parent 6b51ed7a08
commit a5e2362c29
5 changed files with 32 additions and 22 deletions

View File

@@ -31,7 +31,7 @@ CONFIG={
"key_file" : "pki/mykey.pem", "key_file" : "pki/mykey.pem",
"cert_file" : "pki/mycert.pem", "cert_file" : "pki/mycert.pem",
"metadata" : { "metadata" : {
#"local": ["../sp/sp.xml"], "local": ["../sp/sp.xml"],
}, },
"organization": { "organization": {
"display_name": "Rolands Identiteter", "display_name": "Rolands Identiteter",

View File

@@ -27,7 +27,7 @@ CONFIG = {
"cert_file" : "pki/mycert.pem", "cert_file" : "pki/mycert.pem",
"attribute_map_dir" : "./attributemaps", "attribute_map_dir" : "./attributemaps",
"metadata" : { "metadata" : {
#"local": ["../idp/idp.xml"], "local": ["../idp/idp.xml"],
}, },
# -- below used by make_metadata -- # -- below used by make_metadata --
"organization": { "organization": {

View File

@@ -113,7 +113,7 @@ class Config(object):
else: else:
return object.__getattribute__(self, item) 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]: for arg in SPEC[typ]:
try: try:
self._attr[typ][arg] = cnf[arg] self._attr[typ][arg] = cnf[arg]
@@ -121,10 +121,10 @@ class Config(object):
pass pass
self.context = typ self.context = typ
self.load_complex(cnf, typ) self.load_complex(cnf, typ, metadata_construction=metadata_construction)
self.context = self.def_context 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] _attr_typ = self._attr[typ]
try: try:
_attr_typ["policy"] = Policy(cnf["policy"]) _attr_typ["policy"] = Policy(cnf["policy"])
@@ -140,12 +140,13 @@ class Config(object):
except KeyError: except KeyError:
pass pass
try: if not metadata_construction:
_attr_typ["metadata"] = self.load_metadata(cnf["metadata"]) try:
except KeyError: _attr_typ["metadata"] = self.load_metadata(cnf["metadata"])
pass except KeyError:
pass
def load(self, cnf): def load(self, cnf, metadata_construction=False):
for arg in COMMON_ARGS: for arg in COMMON_ARGS:
try: try:
@@ -156,24 +157,27 @@ class Config(object):
if "service" in cnf: if "service" in cnf:
for typ in ["aa", "idp", "sp"]: for typ in ["aa", "idp", "sp"]:
try: try:
self.load_special(cnf["service"][typ], typ) self.load_special(cnf["service"][typ], typ,
metadata_construction=metadata_construction)
except KeyError: except KeyError:
pass pass
if "xmlsec_binary" not in self._attr[""]: if not metadata_construction:
self._attr[""]["xmlsec_binary"] = get_xmlsec_binary() 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 self.context = self.def_context
return self return self
def load_file(self, config_file): def load_file(self, config_file, metadata_construction=False):
if sys.path[0] != ".": if sys.path[0] != ".":
sys.path.insert(0, ".") sys.path.insert(0, ".")
mod = import_module(config_file) mod = import_module(config_file)
#return self.load(eval(open(config_file).read())) #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): def load_metadata(self, metadata_conf):
""" Loads metadata into an internal structure """ """ Loads metadata into an internal structure """

View File

@@ -27,6 +27,9 @@ SP = {
}, },
} }
}, },
"metadata": {
"local": ["foo.xml"],
},
"attribute_map_dir" : "attributemaps", "attribute_map_dir" : "attributemaps",
} }
@@ -50,7 +53,10 @@ IDP = {
}, },
"scope": ["example.org"] "scope": ["example.org"]
} }
} },
"metadata": {
"local": ["bar.xml"],
},
} }
def test_org_1(): def test_org_1():
@@ -161,7 +167,7 @@ def test_optional_attributes():
assert ras[0].is_required == "false" assert ras[0].is_required == "false"
def test_do_sp_sso_descriptor(): def test_do_sp_sso_descriptor():
conf = SPConfig().load(SP) conf = SPConfig().load(SP, metadata_construction=True)
spsso = metadata.do_sp_sso_descriptor(conf) spsso = metadata.do_sp_sso_descriptor(conf)
assert isinstance(spsso, md.SPSSODescriptor) assert isinstance(spsso, md.SPSSODescriptor)
@@ -174,7 +180,7 @@ def test_do_sp_sso_descriptor():
assert spsso.authn_requests_signed == "false" assert spsso.authn_requests_signed == "false"
assert spsso.want_assertions_signed == "true" 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] acs = spsso.attribute_consuming_service[0]
print acs.keyswv() print acs.keyswv()
assert _eq(acs.keyswv(), ['requested_attribute', 'service_name', assert _eq(acs.keyswv(), ['requested_attribute', 'service_name',
@@ -192,7 +198,7 @@ def test_entity_description():
confd = SPConfig().load_file("server_conf") confd = SPConfig().load_file("server_conf")
print confd.attribute_converters print confd.attribute_converters
entd = metadata.entity_descriptor(confd, 1) entd = metadata.entity_descriptor(confd, 1)
assert entd != None assert entd is not None
print entd.keyswv() print entd.keyswv()
assert _eq(entd.keyswv(), ['valid_until', 'entity_id', 'contact_person', assert _eq(entd.keyswv(), ['valid_until', 'entity_id', 'contact_person',
'spsso_descriptor', 'organization']) 'spsso_descriptor', 'organization'])
@@ -200,7 +206,7 @@ def test_entity_description():
assert entd.entity_id == "urn:mace:example.com:saml:roland:sp" assert entd.entity_id == "urn:mace:example.com:saml:roland:sp"
def test_do_idp_sso_descriptor(): def test_do_idp_sso_descriptor():
conf = IdPConfig().load(IDP) conf = IdPConfig().load(IDP, metadata_construction=True)
idpsso = metadata.do_idp_sso_descriptor(conf) idpsso = metadata.do_idp_sso_descriptor(conf)
assert isinstance(idpsso, md.IDPSSODescriptor) assert isinstance(idpsso, md.IDPSSODescriptor)

View File

@@ -75,7 +75,7 @@ def main(args):
sys.path.insert(0, bas) sys.path.insert(0, bas)
if fil.endswith(".py"): if fil.endswith(".py"):
fil = fil[:-3] fil = fil[:-3]
cnf = Config().load_file(fil) cnf = Config().load_file(fil, metadata_construction=True)
eds.append(entity_descriptor(cnf, valid_for)) eds.append(entity_descriptor(cnf, valid_for))
secc = SecurityContext(xmlsec, keyfile) secc = SecurityContext(xmlsec, keyfile)