Exemplo n.º 1
0
 def setUpClass(cls):
     generate_certificate(fname='idp', path=DATA_DIR)
     generate_certificate(fname='sp', path=DATA_DIR)
     example_metadata = os.path.join(DATA_DIR, 'sp-metadata.xml.example')
     sp_cert = os.path.join(DATA_DIR, 'sp.crt')
     tmp_metadata = os.path.join(DATA_DIR, 'sp-metadata.xml')
     shutil.copyfile(example_metadata, tmp_metadata)
     xml = ET.parse(tmp_metadata)
     with open(sp_cert, 'r') as f:
         cert_value = ''.join(f.readlines()[1:-1])
         for cert in xml.findall(
                 '//{http://www.w3.org/2000/09/xmldsig#}X509Certificate'):
             cert.text = cert_value
     xml.write(tmp_metadata)
     app = flask.Flask(spid_testenv.__name__, static_url_path='/static')
     config.load('testenv/tests/data/config.yaml')
     spmetadata.build_metadata_registry()
     cls.idp_server = spid_testenv.IdpServer(app=app)
     cls.idp_server.app.testing = True
     cls.test_client = cls.idp_server.app.test_client()
Exemplo n.º 2
0
logging.basicConfig(level=logging.INFO)
logger = log.logger

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('-c',
                        dest='config',
                        help='Path to configuration file.',
                        default='./conf/config.yaml')
    parser.add_argument('-ct',
                        dest='configuration_type',
                        help='Configuration type [yaml|json]',
                        default='yaml')
    args = parser.parse_args()
    try:
        config.load(args.config, args.configuration_type)
    except BadConfiguration as e:
        logger.error(e)
    else:
        try:
            spmetadata.build_metadata_registry()
        except (ValidationError, DeserializationError) as e:
            for err in e.details:
                logger.error(err)
        os.environ['FLASK_ENV'] = 'development'
        app = Flask(__name__, static_url_path='/static')
        if config.params.behind_reverse_proxy:
            app.wsgi_app = ProxyFix(app.wsgi_app)
        server = IdpServer(app=app)
        server.start()