Exemple #1
0
 def test_Saml_get_metadata_IdP(self):
     entity_id = 'https://foo.example.com/sp/metadata'
     # modifying config in this test, make copy so as not to effect
     # following tests.
     tmp_idp_config = copy.deepcopy(idp_config)
     # test with defined private key file
     with self.app.test_request_context('/', method='GET'):
         idp = auth.SamlServer(tmp_idp_config)
         resp = idp.get_metadata()
         self.assertTrue(
             'Content-type: text/xml; charset=utf-8' in str(resp.headers))
         metadata_xml = resp.data
         self.assert_("Signature" in metadata_xml)
         md = MetaData(tmp_idp_config['xmlsec_binary'])
         md.import_metadata(metadata_xml, 'idp_config')
         self.assertEqual(
             idp._config.single_logout_services(entity_id,
                                                BINDING_HTTP_REDIRECT),
             ['https://foo.example.com/sp/slo'])
     # test without defined private key file
     with self.app.test_request_context('/', method='GET'):
         tmp_idp_config['key_file'] = None
         idp = auth.SamlServer(tmp_idp_config)
         resp = idp.get_metadata()
         self.assertTrue(
             'Content-type: text/xml; charset=utf-8' in str(resp.headers))
         metadata_xml = resp.data
         self.assert_(not "Signature" in metadata_xml)
Exemple #2
0
    def __init__(self,
                 user,
                 passwd,
                 sp="",
                 idp=None,
                 metadata_file=None,
                 xmlsec_binary=None,
                 verbose=0,
                 ca_certs="",
                 disable_ssl_certificate_validation=True):
        """
        :param user: user name
        :param passwd: user password
        :param sp: The SP URL
        :param idp: The IdP PAOS endpoint
        :param metadata_file: Where the metadata file is if used
        :param xmlsec_binary: Where the xmlsec1 binary can be found
        :param verbose: Chatty or not
        :param ca_certs: is the path of a file containing root CA certificates
            for SSL server certificate validation.
        :param disable_ssl_certificate_validation: If
            disable_ssl_certificate_validation is true, SSL cert validation
            will not be performed.
        """
        self._idp = idp
        self._sp = sp
        self.user = user
        self.passwd = passwd
        self._verbose = verbose

        if metadata_file:
            self._metadata = MetaData()
            self._metadata.import_metadata(
                open(metadata_file).read(), xmlsec_binary)
            self._debug_info("Loaded metadata from '%s'" % metadata_file)
        else:
            self._metadata = None

        self.cookie_handler = None

        self.done_ecp = False
        self.cookie_jar = cookielib.LWPCookieJar()
        self.http = soap.HTTPClient(self._sp,
                                    cookiejar=self.cookie_jar,
                                    ca_certs=ca_certs,
                                    disable_ssl_certificate_validation=
                                    disable_ssl_certificate_validation)