diff --git a/src/saml2/config.py b/src/saml2/config.py index 2626143..13e0eb6 100644 --- a/src/saml2/config.py +++ b/src/saml2/config.py @@ -56,6 +56,17 @@ class Config(object): def serves(self): return [t for t in ["sp", "idp", "aa"] if self._attr[t]] + + def copy_into(self, typ=""): + if typ == "sp": + copy = SPConfig() + elif typ in ["idp", "aa"]: + copy = IdPConfig() + else: + copy = Config() + copy.context = typ + copy._attr = self._attr.copy() + return copy def __getattribute__(self, item): if item == "context": diff --git a/tests/test_31_config.py b/tests/test_31_config.py index 213cddb..7a77412 100644 --- a/tests/test_31_config.py +++ b/tests/test_31_config.py @@ -217,4 +217,17 @@ def test_sp(): BINDING_HTTP_POST) == ["http://localhost:8088/slo"] assert cnf.endpoint("assertion_consumer_service") == \ "http://lingon.catalogix.se:8087/" - assert len(cnf.idps()) == 1 \ No newline at end of file + assert len(cnf.idps()) == 1 + +def test_dual(): + cnf = Config().load_file("idp_sp_conf") + cnf.serves() == ["sp", "idp"] + + spcnf = cnf.copy_into("sp") + assert isinstance(spcnf, SPConfig) + assert spcnf.context == "sp" + + idpcnf = cnf.copy_into("idp") + assert isinstance(idpcnf, IdPConfig) + assert idpcnf.context == "idp" +