Beispiel #1
0
def test_session_init():
    factories = {'': operation.factory}
    cnf = parse_json_conf('flows.json', factories, func.factory)
    kwargs = {'profile': None, 'flows': cnf['Flows'], 'order': cnf['Order']}
    sh = SessionHandler(session={}, **kwargs)
    session = sh.init_session(sh.session, profile=kwargs['profile'])

    assert session['flow_names'] == ['AA-Dummy-Default-1', 'AA-Dummy-B',
                                     'AA-Dummy-A']
    assert len(session['tests']) == 3
Beispiel #2
0
def run_test(test_id):
    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)

    flask.session["events"] = tester.conv.events
    flask.session["trace"] = tester.conv.trace

    print("TRACE", tester.conv.trace)
    return tester.run(test_id, **app_args)
Beispiel #3
0
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
Beispiel #4
0
def test_store_test_state():
    factories = {'': operation.factory}
    cnf = parse_yaml_conf('flows.yaml', factories, func.factory)
    kwargs = {'profile': None, 'flows': cnf['Flows'], 'order': cnf['Order']}
    sh = SessionHandler(session={}, **kwargs)
    session = sh.init_session(sh.session, profile=kwargs['profile'])
Beispiel #5
0
    def application(self, environ, start_response):
        logger.info("Connection from: %s" % environ["REMOTE_ADDR"])
        session = environ['beaker.session']

        path = environ.get('PATH_INFO', '').lstrip('/')
        logger.info("path: %s" % path)
        self.events.store(EV_REQUEST, path)

        try:
            sh = session['session_info']
        except KeyError:
            sh = SessionHandler(**self.kwargs)
            sh.session_init()
            session['session_info'] = sh

        webio = WebIO(session=sh, **self.kwargs)
        webio.environ = environ
        webio.start_response = start_response

        tester = WebTester(webio, sh, **self.kwargs)

        if path == "robots.txt":
            return static("static/robots.txt", environ, start_response)
        elif path.startswith("static/"):
            return static(path, environ, start_response)
        elif path == 'test_info':
            resp = Response(self.events.to_html())
            return resp(environ, start_response)
        elif path == "" or path == "/":  # list
            return tester.display_test_list()
        elif path in self.kwargs['flows'].keys():  # Run flow
            resp = tester.run(path, **self.kwargs)
            if resp is True or resp is False:
                return tester.display_test_list()
            else:
                return resp(environ, start_response)
        elif path == 'display':
            return webio.flow_list()
        elif path == "opresult":
            resp = SeeOther(
                "/display#{}".format(self.pick_grp(sh['conv'].test_id)))
            return resp(environ, start_response)
        elif path.startswith("test_info"):
            p = path.split("/")
            try:
                return webio.test_info(p[1])
            except KeyError:
                return webio.not_found()
        elif path == 'all':
            for test_id in sh['flow_names']:
                resp = tester.run(test_id, **self.kwargs)
                if resp is True or resp is False:
                    continue
                elif resp:
                    return resp(environ, start_response)
                else:
                    resp = ServiceError('Unkown service error')
                    return resp(environ, start_response)
            return tester.display_test_list()

        for endpoint, (service, binding) in self.endpoints:
            if path == endpoint:
                logger.info("service: {}, binding: {}".format(service, binding))
                try:
                    resp = self.handle(environ, tester, service, binding)
                    return resp(environ, start_response)
                except Exception as err:
                    print("%s" % err)
                    message = traceback.format_exception(*sys.exc_info())
                    print(message)
                    logger.exception("%s" % err)
                    resp = ServiceError("%s" % err)
                    return resp(environ)

        logger.debug("unknown side: %s" % path)
        resp = NotFound("Couldn't find the side you asked for!")
        return resp(environ, start_response)
Beispiel #6
0
    if test_id:
        res = Result(sh, kwargs['profile_handler'])
        if test_id not in kwargs['flows']:
            print(
                "The test id ({}) does not appear in the test definitions".format(
                    test_id))
            exit()

        webio = ClIO(**kwargs)
        tester = ClTester(webio, sh, **kwargs)
        if tester.run(test_id, **kwargs):
            res.print_info(sh, test_id)
    else:
        for tid in sh["flow_names"]:
            # New fresh session handler for every test
            _sh = SessionHandler({}, **kwargs)
            _sh.init_session(profile=kwargs['profile'])
            res = Result(_sh, kwargs['profile_handler'])

            webio = ClIO(**kwargs)
            tester = ClTester(webio, _sh, **kwargs)
            if tester.run(tid, **kwargs):
                if 'debug' in opargs and opargs['debug']:
                    res.print_info(tid)
                elif 'dump' in opargs and opargs['dump']:
                    res.print_info(tid)
                else:
                    res.result()
            else:
                res.print_info(tid)
Beispiel #7
0
    def application(self, environ, start_response):
        LOGGER.info("Connection from: %s" % environ["REMOTE_ADDR"])
        session = environ['beaker.session']

        path = environ.get('PATH_INFO', '').lstrip('/')
        LOGGER.info("path: %s" % path)

        try:
            sh = session['session_info']
        except KeyError:
            sh = SessionHandler(**self.webenv)
            sh.session_init()
            session['session_info'] = sh

        webio = WebIO(session=sh, **self.webenv)
        webio.environ = environ
        webio.start_response = start_response

        tester = Tester(webio, sh, **self.webenv)

        if path == "robots.txt":
            return webio.static("static/robots.txt")
        elif path == "favicon.ico":
            return webio.static("static/favicon.ico")
        elif path.startswith('acs/site/static'):
            path = path[4:]
            return webio.static(path)
        elif path.startswith("site/static/") or path.startswith('static/'):
            return webio.static(path)
        elif path.startswith("export/"):
            return webio.static(path)

        if path == "" or path == "/":  # list
            return tester.display_test_list()
        elif "flow_names" not in sh:
            sh.session_init()

        if path == "logs":
            return webio.display_log("log", issuer="", profile="", testid="")
        elif path.startswith("log"):
            if path == "log" or path == "log/":
                _cc = webio.conf.CLIENT
                try:
                    _iss = _cc["srv_discovery_url"]
                except KeyError:
                    _iss = _cc["provider_info"]["issuer"]
                parts = [quote_plus(_iss)]
            else:
                parts = []
                while path != "log":
                    head, tail = os.path.split(path)
                    # tail = tail.replace(":", "%3A")
                    # if tail.endswith("%2F"):
                    #     tail = tail[:-3]
                    parts.insert(0, tail)
                    path = head

            return webio.display_log("log", *parts)
        elif path.startswith("tar"):
            path = path.replace(":", "%3A")
            return webio.static(path)

        elif path.startswith("test_info"):
            p = path.split("/")
            try:
                return webio.test_info(p[1])
            except KeyError:
                return webio.not_found()
        elif path == "continue":
            return tester.cont(environ, self.webenv)
        elif path == 'reset':
            for param in ['flow', 'flow_names', 'index', 'node', 'profile',
                          'sequence', 'test_info', 'test_id', 'tests']:
                del sh[param]
            return tester.display_test_list()
        elif path == "opresult":
            if tester.conv is None:
                return webio.sorry_response("", "No result to report")

            return webio.opresult(tester.conv, sh)
        # expected path format: /<testid>[/<endpoint>]
        elif path in sh["flow_names"]:
            resp = tester.run(path, **self.webenv)
            store_test_state(sh, sh['conv'].events)
            filename = self.webenv['profile_handler'](sh).log_path(path)
            if isinstance(resp, Response):
                res = Result(sh, self.webenv['profile_handler'])
                res.store_test_info()
                res.print_info(path, tester.fname(path))
                return webio.respond(resp)
            else:
                return webio.flow_list(filename)
        elif path == "acs/post":
            qs = get_post(environ).decode('utf8')
            resp = dict([(k, v[0]) for k, v in parse_qs(qs).items()])
            filename = self.webenv['profile_handler'](sh).log_path(tester.conv.test_id)

            return do_next(tester, resp, sh, webio, filename, path)
        elif path == "acs/redirect":
            qs = environ['QUERY_STRING']
            resp = dict([(k, v[0]) for k, v in parse_qs(qs).items()])
            filename = self.webenv['profile_handler'](sh).log_path(tester.conv.test_id)

            return do_next(tester, resp, sh, webio, filename, path)
        elif path == "acs/artifact":
            pass
        elif path == "ecp":
            pass
        elif path == "disco":
            pass
        elif path == "slo":
            pass
        else:
            resp = BadRequest()
            return resp(environ, start_response)