Example #1
0
class TestVirtualOrg():
    def setup_class(self):
        conf = config.SPConfig()
        conf.load_file("server_conf")
        self.sp = Saml2Client(conf)

        vo_name = conf.virtual_organization.keys()[0]
        self.vo = VirtualOrg(self.sp, vo_name)
        add_derek_info(self.sp)

    def test_mta(self):
        aas = self.vo.members_to_ask("abcdefgh")
        print aas
        assert len(aas) == 2
        assert 'urn:mace:example.com:saml:aa' in aas
        assert 'urn:mace:example.com:saml:idp' in aas

    def test_unknown_subject(self):
        aas = self.vo.members_to_ask("01234567")
        print aas
        assert len(aas) == 0

    def test_id(self):
        id = self.vo.get_common_identifier("abcdefgh")
        print id
        assert id == "deje0001"

    def test_id_unknown(self):
        id = self.vo.get_common_identifier("01234567")
        assert id is None
Example #2
0
class TestVirtualOrg():
    def setup_class(self):
        conf = config.SPConfig()
        conf.load_file("server_conf")
        self.sp = Saml2Client(conf)

        vo_name = conf.virtual_organization.keys()[0]
        self.vo = VirtualOrg(self.sp, vo_name)
        add_derek_info(self.sp)

    def test_mta(self):
        aas = self.vo.members_to_ask("abcdefgh")
        print aas
        assert len(aas) == 2
        assert 'urn:mace:example.com:saml:aa' in aas
        assert 'urn:mace:example.com:saml:idp' in aas

    def test_unknown_subject(self):
        aas = self.vo.members_to_ask("01234567")
        print aas
        assert len(aas) == 0

    def test_id(self):
        id = self.vo.get_common_identifier("abcdefgh")
        print id
        assert id == "deje0001"

    def test_id_unknown(self):
        id = self.vo.get_common_identifier("01234567")
        assert id is None
Example #3
0
    def setup_class(self):
        conf = config.SPConfig()
        conf.load_file("server_conf")
        self.sp = Saml2Client(conf)

        vo_name = conf.virtual_organization.keys()[0]
        self.vo = VirtualOrg(self.sp, vo_name)
        add_derek_info(self.sp)
Example #4
0
    def setup_class(self):
        conf = config.SPConfig()
        conf.load_file("server_conf")
        self.sp = Saml2Client(conf)

        vo_name = conf.virtual_organization.keys()[0]
        self.vo = VirtualOrg(self.sp, vo_name)
        add_derek_info(self.sp)
Example #5
0
    def __init__(self,
                 config=None,
                 identity_cache=None,
                 state_cache=None,
                 virtual_organization=None,
                 config_file=""):
        """
        :param config: A saml2.config.Config instance
        :param identity_cache: Where the class should store identity information
        :param state_cache: Where the class should keep state information
        :param virtual_organization: Which if any virtual organization this
            SP belongs to
        """

        self.users = Population(identity_cache)

        # for server state storage
        if state_cache is None:
            self.state = {}  # in memory storage
        else:
            self.state = state_cache

        if config:
            self.config = config
        elif config_file:
            self.config = config_factory("sp", config_file)
        else:
            raise Exception("Missing configuration")

        self.metadata = self.config.metadata
        self.config.setup_logger()

        # we copy the config.debug variable in an internal
        # field for convenience and because we may need to
        # change it during the tests
        self.debug = self.config.debug

        self.sec = security_context(self.config)

        if virtual_organization:
            self.vorg = VirtualOrg(self, virtual_organization)
        else:
            self.vorg = None

        if "allow_unsolicited" in self.config:
            self.allow_unsolicited = self.config.allow_unsolicited
        else:
            self.allow_unsolicited = False

        if getattr(self.config, 'authn_requests_signed', 'false') == 'true':
            self.authn_requests_signed_default = True
        else:
            self.authn_requests_signed_default = False

        if getattr(self.config, 'logout_requests_signed', 'false') == 'true':
            self.logout_requests_signed_default = True
        else:
            self.logout_requests_signed_default = False
Example #6
0
    def load(self, cnf, metadata_construction=False):
        """ The base load method, loads the configuration

        :param cnf: The configuration as a dictionary
        :param metadata_construction: Is this only to be able to construct
            metadata. If so some things can be left out.
        :return: The Configuration instance
        """
        _uc = self.unicode_convert
        for arg in COMMON_ARGS:
            if arg == "virtual_organization":
                if "virtual_organization" in cnf:
                    for key, val in cnf["virtual_organization"].items():
                        self.vorg[key] = VirtualOrg(None, key, val)
                continue
            elif arg == "extension_schemas":
                # List of filename of modules representing the schemas
                if "extension_schemas" in cnf:
                    for mod_file in cnf["extension_schemas"]:
                        _mod = self._load(mod_file)
                        self.extension_schema[_mod.NAMESPACE] = _mod

            try:
                setattr(self, arg, _uc(cnf[arg]))
            except KeyError:
                pass
            except TypeError:  # Something that can't be a string
                setattr(self, arg, cnf[arg])

        if self.logging is not None:
            configure_logging_by_dict(self.logging)

        if not self.delete_tmpfiles:
            logger.warning("delete_tmpfiles is set to False; "
                           "temporary files will not be deleted.")

        if "service" in cnf:
            for typ in ["aa", "idp", "sp", "pdp", "aq"]:
                try:
                    self.load_special(
                        cnf["service"][typ],
                        typ,
                        metadata_construction=metadata_construction)
                    self.serves.append(typ)
                except KeyError:
                    pass

        if "extensions" in cnf:
            self.do_extensions(cnf["extensions"])

        self.load_complex(cnf, metadata_construction=metadata_construction)
        self.context = self.def_context

        return self
Example #7
0
    def load(self, cnf, metadata_construction=False):
        """ The base load method, loads the configuration

        :param cnf: The configuration as a dictionary
        :param metadata_construction: Is this only to be able to construct
            metadata. If so some things can be left out.
        :return: The Configuration instance
        """
        for arg in COMMON_ARGS:
            if arg == "virtual_organization":
                if "virtual_organization" in cnf:
                    for key, val in cnf["virtual_organization"].items():
                        self.vorg[key] = VirtualOrg(None, key, val)
                continue

            try:
                setattr(self, arg, cnf[arg])
            except KeyError:
                pass

        if "service" in cnf:
            for typ in ["aa", "idp", "sp", "pdp"]:
                try:
                    self.load_special(
                        cnf["service"][typ],
                        typ,
                        metadata_construction=metadata_construction)
                    self.serves.append(typ)
                except KeyError:
                    pass

        if not metadata_construction:
            if not self.xmlsec_binary:
                self.xmlsec_binary = get_xmlsec_binary()

            # verify that xmlsec is where it's supposed to be
            if not os.path.exists(self.xmlsec_binary):
                #if not os.access(, os.F_OK):
                raise Exception("xmlsec binary not in '%s' !" %
                                (self.xmlsec_binary))

        self.load_complex(cnf, metadata_construction=metadata_construction)
        self.context = self.def_context

        return self
Example #8
0
    def load(self, cnf, metadata_construction=False):
        """ The base load method, loads the configuration

        :param cnf: The configuration as a dictionary
        :param metadata_construction: Is this only to be able to construct
            metadata. If so some things can be left out.
        :return: The Configuration instance
        """
        _uc = self.unicode_convert
        for arg in COMMON_ARGS:
            if arg == "virtual_organization":
                if "virtual_organization" in cnf:
                    for key, val in cnf["virtual_organization"].items():
                        self.vorg[key] = VirtualOrg(None, key, val)
                continue

            try:
                setattr(self, arg, _uc(cnf[arg]))
            except KeyError:
                pass
            except TypeError:  # Something that can't be a string
                setattr(self, arg, cnf[arg])

        if "service" in cnf:
            for typ in ["aa", "idp", "sp", "pdp", "aq"]:
                try:
                    self.load_special(
                        cnf["service"][typ],
                        typ,
                        metadata_construction=metadata_construction)
                    self.serves.append(typ)
                except KeyError:
                    pass

        self.load_complex(cnf, metadata_construction=metadata_construction)
        self.context = self.def_context

        return self
Example #9
0
    def load(self, cnf, metadata_construction=None):
        """ The base load method, loads the configuration

        :param cnf: The configuration as a dictionary
        :return: The Configuration instance
        """

        if metadata_construction is not None:
            warn_msg = (
                "The metadata_construction parameter for saml2.config.Config.load "
                "is deprecated and ignored; "
                "instead, initialize the Policy object setting the mds param.")
            logger.warning(warn_msg)
            _warn(warn_msg, DeprecationWarning)

        for arg in COMMON_ARGS:
            if arg == "virtual_organization":
                if "virtual_organization" in cnf:
                    for key, val in cnf["virtual_organization"].items():
                        self.vorg[key] = VirtualOrg(None, key, val)
                continue
            elif arg == "extension_schemas":
                # List of filename of modules representing the schemas
                if "extension_schemas" in cnf:
                    for mod_file in cnf["extension_schemas"]:
                        _mod = self._load(mod_file)
                        self.extension_schema[_mod.NAMESPACE] = _mod

            try:
                setattr(self, arg, cnf[arg])
            except KeyError:
                pass
            except TypeError:  # Something that can't be a string
                setattr(self, arg, cnf[arg])

        if self.logging is not None:
            configure_logging_by_dict(self.logging)

        if not self.delete_tmpfiles:
            warn_msg = (
                "Configuration option `delete_tmpfiles` is set to False; "
                "consider setting this to True to have temporary files deleted."
            )
            logger.warning(warn_msg)
            _warn(warn_msg)

        if "service" in cnf:
            for typ in ["aa", "idp", "sp", "pdp", "aq"]:
                try:
                    self.load_special(cnf["service"][typ], typ)
                    self.serves.append(typ)
                except KeyError:
                    pass

        if "extensions" in cnf:
            self.do_extensions(cnf["extensions"])

        self.load_complex(cnf)
        self.context = self.def_context

        return self