Esempio n. 1
0
    def run(self, test_id, cinfo, **kw_args):
        if not self.match_profile(test_id):
            logger.info("Test doesn't match the profile")
            return False

        redirs = get_redirect_uris(cinfo)

        self.sh.session_setup(path=test_id)
        _flow = self.flows[test_id]
        _cli = make_client(**kw_args)
        self.conv = Conversation(_flow,
                                 _cli,
                                 msg_factory=kw_args["msg_factory"],
                                 callback_uris=redirs,
                                 trace_cls=Trace)
        _cli.conv = self.conv
        self.conv.sequence = self.sh.session["sequence"]
        self.sh.session["conv"] = self.conv

        # noinspection PyTypeChecker
        try:
            return self.run_flow(test_id, kw_args["conf"])
        except Exception as err:
            exception_trace("", err, logger)
            self.io.dump_log(self.sh.session, test_id)
            return self.io.err_response(self.sh.session, "run", err)
Esempio n. 2
0
    def run(self, test_id, **kw_args):
        self.sh.session_setup(path=test_id)
        _flow = self.flows[test_id]

        _entity = self.make_entity(_flow["idp"], **kw_args)

        self.conv = Conversation(_flow, _entity, kw_args["msg_factory"],
                                 trace_cls=Trace, **kw_args["conv_args"])
        self.conv.entity_id = kw_args["entity_id"]
        _entity.conv = self.conv
        self.conv.sequence = self.sh["sequence"]
        if 'insecure' in kw_args:
            self.conv.interaction.verify_ssl = False

        if self.interactions:
            self.conv.interaction.interactions = self.interactions
        self.sh["conv"] = self.conv

        # noinspection PyTypeChecker
        try:
            return self.run_flow(test_id)
        except Exception as err:
            exception_trace("", err, logger)
            self.webio.print_info(self.sh, test_id)
            return self.webio.err_response("run", err)
Esempio n. 3
0
    def run(self, test_id, **kw_args):
        self.sh.session_setup(path=test_id)
        _flow = self.flows[test_id]
        _cli = self.make_entity(_flow["sp"], **kw_args)
        self.conv = Conversation(_flow, _cli, kw_args["msg_factory"],
                                 trace_cls=Trace, **kw_args["conv_args"])
        self.conv.entity_id = kw_args["entity_id"]
        _cli.conv = self.conv
        self.conv.sequence = self.sh["sequence"]

        self.sh["conv"] = self.conv

        self.com_handler.conv = self.conv
        self.com_handler.auto_close_urls = self.my_endpoints()
        if 'insecure' in kw_args:
            self.com_handler.verify_ssl = False

        # noinspection PyTypeChecker
        try:
            return self.run_flow(test_id)
        except Exception as err:
            exception_trace("", err, logger)
            # TODO: does not exist
            #self.webio.print_info(self.sh, test_id)
            # TODO: self.webio needs to have a session, but never gets one
            # Quickfix:
            self.webio.session = self.sh
            return self.webio.err_response("run", err)
Esempio n. 4
0
    def err_response(self, session, where, err):
        if err:
            exception_trace(where, err, logger)

        try:
            _tid = session["testid"]
            self.dump_log(session, _tid)
        except KeyError:
            pass
Esempio n. 5
0
    def err_response(self, where, err):
        if err:
            exception_trace(where, err, logger)

        try:
            _tid = self.session["testid"]
            self.print_info(_tid)
        except KeyError:
            pass
Esempio n. 6
0
    def err_response(self, session, where, err):
        if err:
            exception_trace(where, err, logger)

        try:
            _tid = session["testid"]
            self.dump_log(session, _tid)
        except KeyError:
            pass
    def _err_response(self, where, err):
        if err:
            exception_trace(where, err, logger)

        try:
            res = Result(self.session, self.profile_handler)
            res.print_info(self.session["testid"])
            res.store_test_info()
        except KeyError:
            pass
    def run(self, test_id, **kw_args):
        if not self.setup(test_id, **kw_args):
            raise ConfigurationError()

        # noinspection PyTypeChecker
        try:
            return self.run_flow(test_id, conf=kw_args['conf'])
        except Exception as err:
            exception_trace("", err, logger)
            return self.inut.err_response("run", err)
Esempio n. 9
0
    def run(self, test_id, cinfo, **kw_args):
        self._setup(test_id, cinfo, **kw_args)

        # noinspection PyTypeChecker
        try:
            return self.run_flow(test_id, kw_args["conf"])
        except Exception as err:
            exception_trace("", err, logger)
            #self.io.dump_log(self.sh.session, test_id)
            return self.io.err_response(self.sh.session, "run", err)
Esempio n. 10
0
    def run(self, test_id, cinfo, **kw_args):
        self._setup(test_id, cinfo, **kw_args)

        # noinspection PyTypeChecker
        try:
            return self.run_flow(test_id, kw_args["conf"])
        except Exception as err:
            exception_trace("", err, logger)
            #self.io.dump_log(self.sh.session, test_id)
            return self.io.err_response(self.sh.session, "run", err)
Esempio n. 11
0
    def run(self, test_id, **kw_args):
        if not self.setup(test_id, **kw_args):
            raise ConfigurationError()

        # noinspection PyTypeChecker
        try:
            return self.run_flow(test_id)
        except Exception as err:
            exception_trace("", err, logger)
            res = Result(self.sh, None)
            res.print_info(self.sh, test_id)
            return self.webio.err_response("run", err)
Esempio n. 12
0
    def err_response(self, session, where, err):
        if err:
            exception_trace(where, err, logger)

        self.log_fault(session, err, where)

        try:
            _tid = session["testid"]
            self.dump_log(session, _tid)
            self.store_test_info(session)
        except KeyError:
            pass

        return self.flow_list(session)
Esempio n. 13
0
    def err_response(self, session, where, err):
        if err:
            exception_trace(where, err, logger)

        self.log_fault(session, err, where)

        try:
            _tid = session["testid"]
            self.dump_log(session, _tid)
            self.store_test_info(session)
        except KeyError:
            pass

        return self.flow_list(session)
Esempio n. 14
0
 def display_test_list(self):
     try:
         if self.sh.session_init():
             return self.io.flow_list(self.sh.session)
         else:
             try:
                 resp = Redirect("%sopresult#%s" % (
                     self.io.conf.BASE, self.sh.session["testid"][0]))
             except KeyError:
                 return self.io.flow_list(self.sh.session)
             else:
                 return resp(self.io.environ, self.io.start_response)
     except Exception as err:
         exception_trace("display_test_list", err)
         return self.io.err_response(self.sh.session, "session_setup", err)
Esempio n. 15
0
 def display_test_list(self):
     try:
         if self.sh.session_init():
             return self.io.flow_list(self.sh.session)
         else:
             try:
                 resp = Redirect(
                     "%sopresult#%s" %
                     (self.io.conf.BASE, self.sh.session["testid"][0]))
             except KeyError:
                 return self.io.flow_list(self.sh.session)
             else:
                 return resp(self.io.environ, self.io.start_response)
     except Exception as err:
         exception_trace("display_test_list", err)
         return self.io.err_response(self.sh.session, "session_setup", err)
Esempio n. 16
0
 def display_test_list(self):
     try:
         if self.sh.session_init():
             return self.webio.flow_list(self.sh, tt_entityid=self.webio.kwargs['entity_id'])
         else:
             if 'testid' in self.sh:
                 p = self.sh["testid"].split('-')
                 resp = Redirect("%sopresult#%s" % (self.webio.conf.BASE, p[1]))
                 return resp(self.webio.environ, self.webio.start_response)
             else:
                 rendered = self.webio.flow_list(self.sh,
                                                 tt_entityid=self.webio.kwargs['entity_id'])
                 return rendered
     except Exception as err:
         exception_trace("display_test_list", err)
         return self.webio.err_response("session_setup", err)
Esempio n. 17
0
    def cont(self, environ, ENV):
        query = parse_qs(environ["QUERY_STRING"])
        path = query["path"][0]
        index = int(query["index"][0])

        try:
            index = self.sh.session["index"]
        except KeyError:  # Cookie delete broke session
            self._setup(path, **ENV)
        except Exception as err:
            return self.io.err_response(self.sh.session, "session_setup", err)
        else:
            self.conv = self.sh.session["conv"]

        index += 1

        try:
            return self.run_flow(path, ENV["conf"], index)
        except Exception as err:
            exception_trace("", err, logger)
            self.io.dump_log(self.sh.session, path)
            return self.io.err_response(self.sh.session, "run", err)
Esempio n. 18
0
    def cont(self, environ, ENV):
        query = parse_qs(environ["QUERY_STRING"])
        path = query["path"][0]
        index = int(query["index"][0])

        try:
            index = self.sh.session["index"]
        except KeyError:  # Cookie delete broke session
            self._setup(path, **ENV)
        except Exception as err:
            return self.io.err_response(self.sh.session, "session_setup", err)
        else:
            self.conv = self.sh.session["conv"]

        index += 1

        try:
            return self.run_flow(path, ENV["conf"], index)
        except Exception as err:
            exception_trace("", err, logger)
            self.io.dump_log(self.sh.session, path)
            return self.io.err_response(self.sh.session, "run", err)
Esempio n. 19
0
    def do_check(self, test, **kwargs):
        logger.debug("do_check({}, {})".format(test, kwargs))
        if isinstance(test, str):
            try:
                chk = self.check_factory(test)(**kwargs)
            except TypeError:
                raise MissingTest(test)
        else:
            chk = test(**kwargs)

        if chk.__class__.__name__ not in self.ignore_check:
            self.conv.trace.info("Assert {}".format(chk.__class__.__name__))
            try:
                stat = chk(self.conv)
            except Exception as err:
                exception_trace('do_check', err, logger)
                raise
            else:
                if self.cls_name:
                    stat.context = self.cls_name
                self.conv.events.store('condition', stat)
                self.check_severity(stat)
Esempio n. 20
0
    def run(self, test_id, cinfo, **kw_args):
        if not self.match_profile(test_id):
            logger.info("Test doesn't match the profile")
            return False

        redirs = get_redirect_uris(cinfo)

        self.sh.session_setup(path=test_id)
        _flow = self.flows[test_id]
        _cli = make_client(**kw_args)
        self.conv = Conversation(_flow, _cli,
                                 msg_factory=kw_args["msg_factory"],
                                 callback_uris=redirs, trace_cls=Trace)
        _cli.conv = self.conv
        self.conv.sequence = self.sh.session["sequence"]
        self.sh.session["conv"] = self.conv

        # noinspection PyTypeChecker
        try:
            return self.run_flow(test_id, kw_args["conf"])
        except Exception as err:
            exception_trace("", err, logger)
            self.io.dump_log(self.sh.session, test_id)
            return self.io.err_response(self.sh.session, "run", err)
Esempio n. 21
0
    def run_flow(self, test_id, index=0, profiles=None):
        logger.info("<=<=<=<=< %s >=>=>=>=>" % test_id)
        _ss = self.sh.session
        try:
            _ss["node"].complete = False
        except KeyError:
            pass

        self.conv.test_id = test_id

        if index >= len(self.conv.sequence):
            return None

        _oper = None
        for item in self.conv.sequence[index:]:
            if isinstance(item, tuple):
                cls, funcs = item
            else:
                cls = item
                funcs = {}

            logger.info("<--<-- {} --- {} -->-->".format(index, cls))
            self.conv.events.store('operation', cls)
            try:
                _oper = cls(conv=self.conv, io=self.io, sh=self.sh,
                            profile=self.profile, test_id=test_id,
                            funcs=funcs, check_factory=self.chk_factory,
                            cache=self.cache)
                # self.conv.operation = _oper
                if profiles:
                    profile_map = profiles.PROFILEMAP
                else:
                    profile_map = None
                _oper.setup(profile_map)
                resp = _oper()
            except Exception as err:
                exception_trace('run_flow', err)
                self.sh.session["index"] = index
                return self.io.err_response(self.sh.session, "run_sequence",
                                            err)
            else:
                resp = self.com_handler(resp)
                if resp:
                    resp = _oper.handle_response(resp.response)
                    if resp:
                        return self.io.respond(resp)

            index += 1

        try:
            if self.conv.flow["assert"]:
                _ver = Verify(self.chk_factory, self.conv.msg_factory,
                              self.conv)
                _ver.test_sequence(self.conv.flow["assert"])
        except KeyError:
            pass
        except Exception as err:
            logger.error(err)
            raise

        if isinstance(_oper, Done):
            self.conv.events.store('condition', State('done', OK))
        return True
Esempio n. 22
0
    def run_flow(self, test_id, index=0, profiles=None, **kwargs):
        logger.info("<=<=<=<=< %s >=>=>=>=>" % test_id)
        _ss = self.sh
        try:
            _ss["node"].complete = False
        except KeyError:
            pass

        self.conv.test_id = test_id
        res = Result(self.sh, self.kwargs['profile_handler'])

        if index >= len(self.conv.sequence):
            return None

        _oper = None
        for item in self.conv.sequence[index:]:
            if isinstance(item, tuple):
                cls, funcs = item
            else:
                cls = item
                funcs = {}

            logger.info("<--<-- {} --- {} -->-->".format(index, cls))
            self.conv.events.store('operation', cls, sender='run_flow')
            try:
                _oper = cls(conv=self.conv, webio=self.webio, sh=self.sh,
                            profile=self.profile, test_id=test_id,
                            funcs=funcs, check_factory=self.chk_factory,
                            cache=self.cache)
                # self.conv.operation = _oper
                if profiles:
                    profile_map = profiles.PROFILEMAP
                else:
                    profile_map = None
                _oper.setup(profile_map)
                oper_response = _oper()
            except ConditionError:
                store_test_state(self.sh, self.conv.events)
                res.store_test_info()
                res.print_info(test_id, self.fname(test_id))
                return False
            except Exception as err:
                exception_trace('run_flow', err)
                self.conv.events.store(EV_FAULT, err)
                # self.sh["index"] = index
                store_test_state(self.sh, self.conv.events)
                res.store_test_info()
                res.print_info(test_id, self.fname(test_id))
                return False
            else:
                # *?*
                #if isinstance(oper_response, self.response_cls):
                #    return oper_response

                if oper_response:
                    if False:
                        return oper_response

                    if self.com_handler:

                        self.com_handler.conv = self.conv
                        #self.com_handler.auto_close_urls = self.my_endpoints()
                        self.com_handler.verify_ssl = True
                        if self.kwargs['conf'].DO_NOT_VALIDATE_TLS:
                            self.com_handler.verify_ssl = False
                        com_handler_response = self.com_handler(oper_response)

                        if com_handler_response.status == HandlerResponse.STATUS_NOT_TRIGGERED:
                            return oper_response

                        if com_handler_response.status == HandlerResponse.STATUS_NO_INTERACTION_FOUND:
                            response = self.webio.respond(com_handler_response)
                            return response

                        if com_handler_response.status == HandlerResponse.STATUS_ERROR:
                            msg = 'Com handler failed to process interaction'
                            self.conv.events.store(EV_CONDITION, State('Assertion Error', ERROR, message=msg),
                                                    sender='wb_tool')
                            store_test_state(self.sh, self.conv.events)
                            res.store_test_info()
                            res.print_info(test_id, self.fname(test_id))
                            return False


                    """
                    Guesswork about what was intended to happen here.
                    Cases:
                    1. If it is an saml2.httputil.Redirect, it should be handle by the browser.
                    Are there other cases?
                    """

                    if isinstance(oper_response, Redirect):
                        # saml2.httputil.Redirect
                        return oper_response




                    if False:
                        """
                        Basically, now clear idea what this code whas expected to do ?
                        Was this just a draft? Really working with all test flavours?
                        """

                        if com_handler_response.content_processed:
                            oper_response = _oper.handle_response(self.get_response(oper_response))

                            if oper_response:
                                return self.webio.respond(oper_response)

                        else:
                            return oper_response



            # should be done as late as possible, so all processing has been
            # done
            try:
                _oper.post_tests()
            except ConditionError:
                store_test_state(self.sh, self.conv.events)
                res.store_test_info()
                res.print_info(test_id, self.fname(test_id))
                return False

            index += 1

        _ss['index'] = self.conv.index = index

        try:
            if self.conv.flow["assert"]:
                _ver = Verify(self.chk_factory, self.conv)
                _ver.test_sequence(self.conv.flow["assert"])
        except KeyError:
            pass
        except Exception as err:
            logger.error(err)
            raise

        if isinstance(_oper, Done):
            self.conv.events.store(EV_CONDITION, State('Done', OK),
                                   sender='run_flow')
            store_test_state(self.sh, self.conv.events)
            res.store_test_info()
            res.print_info(test_id, self.fname(test_id))
        else:
            store_test_state(self.sh, self.conv.events)
            res.store_test_info()

        return True
    def run_flow(self, test_id, index=0, profiles=None, **kwargs):
        logger.info("<=<=<=<=< %s >=>=>=>=>" % test_id)
        _ss = self.sh
        try:
            _ss["node"].complete = False
        except KeyError:
            pass

        self.conv.test_id = test_id
        res = Result(self.sh, self.kwargs['profile_handler'])

        if index >= len(self.conv.sequence):
            return None

        _oper = None
        for item in self.conv.sequence[index:]:
            if isinstance(item, tuple):
                cls, funcs = item
            else:
                cls = item
                funcs = {}

            logger.info("<--<-- {} --- {} -->-->".format(index, cls))
            self.conv.events.store('operation', cls, sender='run_flow')
            try:
                _oper = cls(conv=self.conv, inut=self.inut, sh=self.sh,
                            profile=self.profile, test_id=test_id,
                            funcs=funcs, check_factory=self.chk_factory,
                            cache=self.cache)
                # self.conv.operation = _oper
                if profiles:
                    profile_map = profiles.PROFILEMAP
                else:
                    profile_map = None
                _oper.setup(profile_map)
                resp = _oper()
            except ConditionError:
                store_test_state(self.sh, self.conv.events)
                res.store_test_info()
                res.print_info(test_id, self.fname(test_id))
                return False
            except Exception as err:
                exception_trace('run_flow', err)
                self.sh["index"] = index
                return self.inut.err_response("run_sequence", err)
            else:
                if isinstance(resp, self.response_cls):
                    return resp

                if resp:
                    if self.com_handler:
                        resp = self.com_handler(resp)

                    resp = _oper.handle_response(self.get_response(resp))

                    if resp:
                        return self.inut.respond(resp)

            # should be done as late as possible, so all processing has been
            # done
            try:
                _oper.post_tests()
            except ConditionError:
                store_test_state(self.sh, self.conv.events)
                res.store_test_info()
                res.print_info(test_id, self.fname(test_id))
                return False

            index += 1

        _ss['index'] = self.conv.index = index

        try:
            if self.conv.flow["assert"]:
                _ver = Verify(self.chk_factory, self.conv)
                _ver.test_sequence(self.conv.flow["assert"])
        except KeyError:
            pass
        except Exception as err:
            logger.error(err)
            raise

        if isinstance(_oper, Done):
            self.conv.events.store(EV_CONDITION, State('Done', OK),
                                   sender='run_flow')
            store_test_state(self.sh, self.conv.events)
            res.store_test_info()
            res.print_info(test_id, self.fname(test_id))
        else:
            store_test_state(self.sh, self.conv.events)
            res.store_test_info()

        return True
Esempio n. 24
0
    def run(self):
        self.args = self._parser.parse_args()

        if self.args.pysamllog:
            root_logger.addHandler(memoryhandler)
            root_logger.setLevel(logging.DEBUG)

        if self.args.metadata:
            return self.make_meta()
        elif self.args.list:
            return self.list_operations()
        elif self.args.oper == "check":
            return self.verify_metadata()
        else:
            if not self.args.oper:
                raise Exception("Missing test case specification")
            self.args.oper = self.args.oper.strip("'")
            self.args.oper = self.args.oper.strip('"')

        self.setup()

        try:
            oper = self.operations.OPERATIONS[self.args.oper]
        except KeyError:
            if self.tests:
                try:
                    oper = self.tests.OPERATIONS[self.args.oper]
                except ValueError:
                    print("Undefined testcase " + self.args.oper,
                          file=sys.stderr)
                    return
            else:
                print("Undefined testcase " + self.args.oper, file=sys.stderr)
                return

        if self.args.pretty:
            pp = pprint.PrettyPrinter(indent=4)
        else:
            pp = None

        logger.info("Starting conversation")
        conv = Conversation(self.idp, self.idp_config,
                            self.interactions, self.json_config,
                            check_factory=self.check_factory,
                            entity_id=self.entity_id,
                            constraints=self.constraints,
                            commandlineargs=self.args)
        try:
            conv.do_sequence_and_tests(oper["sequence"], oper["tests"])
            self.test_log = conv.test_output
            tsum = self.test_summation(self.args.oper)
            err = None
        except CheckError as err:
            self.test_log = conv.test_output
            tsum = self.test_summation(self.args.oper)
        except FatalError as err:
            if conv:
                self.test_log = conv.test_output
                self.test_log.append(exception_trace("RUN", err))
            else:
                self.test_log = exception_trace("RUN", err)
            tsum = self.test_summation(self.args.oper)
        except Exception as err:
            if conv:
                conv.test_output.append({"status": CRITICAL,
                                         "name": "test driver error",
                                         "id": "critial exception"})
                self.test_log = conv.test_output
                self.test_log.append(exception_trace("RUN", err))
            else:
                self.test_log = exception_trace("RUN", err)
            tsum = self.test_summation(self.args.oper)
            logger.error("Unexpected exception in test driver %s" %
                         traceback.format_exception(*sys.exc_info()))

        if pp:
            pp.pprint(tsum)
        else:
            print(json.dumps(tsum), file=sys.stdout)

        if tsum["status"] > 1 or self.args.debug or err:
            self.output_log(memoryhandler, streamhandler)