def setup_tester(): test_id, app_args = setup('wb') events = flask.session["events"] if not test_id: test_id = events.get('test_id')[0].data io = SamlClIO(**app_args) sh = SessionHandler(session={}, **app_args) sh.init_session({}, profile=app_args['profile']) tester = Tester(io, sh, **app_args) tester.setup(test_id, **app_args) tester.conv.events = flask.session["events"] tester.conv.trace = flask.session['trace'] tester.conv.base_url = app_args["base_url"] tester.conv.test_id = test_id return tester, app_args
def urlhandler_swconf(self, environ, local_webenv, session, start_response, webio): """ switch config by user request url param: ?github=<name of the github repo>&email=<user email>&branch=<repobranch> """ formdata = parse_qs(environ['QUERY_STRING']) resp = dict([(k, v[0]) for k, v in formdata.items()]) try: ac_file_name = local_webenv['conf'].ACCESS_CONTROL_FILE except Exception as e: ac_file_name = None if ac_file_name: try: ac_file = WebUserAccessControlFile(local_webenv['conf'].ACCESS_CONTROL_FILE) except Exception as e: return webio.sorry_response(local_webenv['base_url'], e, context='reading ' + local_webenv['conf'].ACCESS_CONTROL_FILE) has_access = ac_file.test(resp['github'], resp['email']) if not has_access: return webio.sorry_response(local_webenv['base_url'], 'permission denied', context="access checking: email does not match repo user.") # reading from github should set readjson, but to be sure ... setup_cargs=type('setupcarg', (object,), {'github': True, 'configdir': resp['github'], 'readjson': True })() if 'branch' in resp: setattr(setup_cargs, 'repobranch', resp['branch']) else: setattr(setup_cargs, 'repobranch', None) try: user_cargs, user_kwargs, user_CONF = setup('wb', setup_cargs) except FileNotFoundError as e: return webio.sorry_response(local_webenv['base_url'], e, context="Configuration Setup via URL parameter - trying to read generated/config.json") except ConfigError as e: errstr = e.error_details_as_string() print('Error: {}'.format(errstr)) return webio.sorry_response(local_webenv['base_url'], errstr, context="configuration setup", exception=traceback.format_exc()) except Exception as e: return webio.sorry_response(local_webenv['base_url'], e, context="Configuration Setup", exception=traceback.format_exc()) """ picking the config stuff that the user is allowed to override """ local_webenv['conf'] = user_CONF local_webenv['flows'] = user_kwargs['flows'] """ Todo: having this not cluttered would be nicer In other words: refactoring of setup.py """ local_webenv['entity_id'] = local_webenv['conf'].ENTITY_ID local_webenv["insecure"] = local_webenv['conf'].DO_NOT_VALIDATE_TLS local_webenv["profile"] = local_webenv['conf'].FLOWS_PROFILES import copy from saml2test import metadata spconf = copy.deepcopy(user_CONF.CONFIG) acnf = list(spconf.values())[0] mds = metadata.load(True, acnf, user_CONF.METADATA, 'sp') local_webenv["metadata"] = mds # new webenv into session session['webenv'] = local_webenv sh = SessionHandler(**local_webenv) sh.session_init() session['session_info'] = sh webio = WebIO(session=sh, **local_webenv) webio.environ = environ webio.start_response = start_response tester = Tester(webio, sh, **local_webenv) return tester.display_test_list()
try: return webio.test_info(p[1]) except KeyError: return webio.not_found() else: resp = BadRequest() return resp(environ, start_response) if __name__ == '__main__': from beaker.middleware import SessionMiddleware from cherrypy import wsgiserver from mako.lookup import TemplateLookup logging.info(__file__ + ' V' + __version__) try: cargs, kwargs, CONF = setup('wb') except ConfigError as e: str = e.error_details_as_string() print('Error: {}'.format(e)) if (str): print (str) os.sys.exit(-1) if CONF.config_infos: print ('Please notice these infos:') for info in CONF.config_infos: print (info) if cargs.metadata: generate_metadata_xml(cargs, kwargs) exit(0)
tester.conv.events = flask.session["events"] tester.conv.trace = flask.session['trace'] tester.conv.base_url = app_args["base_url"] tester.conv.test_id = test_id return tester, app_args def entcat_test(tinfo): for prof in tinfo['profiles']: if prof == 'entcat' or prof.startswith('entcat:'): return True return False test_id, app_args = setup('wb') app = Flask('saml2test') app.config.update(dict( TESTS=app_args["flows"], DISCOVERY_SERVICE=app_args.get("discovery_service", None), SECRET_KEY=app_args.get("secret_key", rndstr()), RESULT_DB='result_db' )) session_opts = { # TODO can't be server-side due to pyff redirecting to disco endpoint twice "session.type": "memory", "session.validate_key": app.config["SECRET_KEY"] }
logger = logging.getLogger("") def safe_path(entity_id, test_id): s = quote(entity_id) s = s.replace('/', '%2F') if not os.path.isdir('log/{}'.format(s)): os.makedirs('log/{}'.format(s)) return 'log/{}/{}'.format(s, test_id) if __name__ == "__main__": cargs, kwargs = setup() if cargs.testid: if cargs.testid not in kwargs['flows']: print( "The test id ({}) does not appear in the test definitions".format( cargs.testid)) exit() webio = ClIO(**kwargs) sh = SessionHandler(session={}, **kwargs) sh.init_session(profile=kwargs['profile']) tester = ClTester(webio, sh, **kwargs) tester.run(cargs.testid, **kwargs) webio.result() """
pass elif path == "disco": pass elif path == "slo": pass else: resp = BadRequest() return resp(environ, start_response) if __name__ == '__main__': from beaker.middleware import SessionMiddleware from cherrypy import wsgiserver from mako.lookup import TemplateLookup cargs, kwargs = setup('wb') session_opts = { 'session.type': 'memory', 'session.cookie_expires': True, 'session.auto': True, 'session.timeout': 900 } LOOKUP = TemplateLookup(directories=['./' + 'templates', './' + 'htdocs'], module_directory='./' + 'modules', input_encoding='utf-8', output_encoding='utf-8') kwargs['lookup'] = LOOKUP _conf = kwargs['conf']