except FatalError, 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, 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 >> sys.stdout, json.dumps(tsum) if tsum["status"] > 1 or self.args.debug or err: self.output_log(memoryhandler, streamhandler) def setup(self):
class Client(object): def __init__(self, operations, check_factory): self.operations = operations self.tests = None self.check_factory = check_factory self._parser = argparse.ArgumentParser() self._parser.add_argument("-c", dest="config", default="config", help="Configuration file for the IdP") self._parser.add_argument( '-C', dest="ca_certs", help=("CA certs to use to verify HTTPS server certificates, ", "if HTTPS is used and no server CA certs are defined then ", "no cert verification will be done")) self._parser.add_argument('-d', dest='debug', action='store_true', help="Print debug information") self._parser.add_argument("-H", dest="pretty", action='store_true', help="Output summary on stdout as pretty " "printed python dict instead of JSON") self._parser.add_argument("-i", dest="insecure", action='store_true', help="Do not verify SSL certificate") self._parser.add_argument("-I", dest="keysdir", default="keys", help="Directory for invalid IDP keys") self._parser.add_argument('-J', dest="json_config_file", help="Test target configuration") self._parser.add_argument( '-k', dest='content_log', action='store_true', help="Log HTTP content in spearate files in directory " "<operation>/, which defaults to the path in -L") self._parser.add_argument( "-l", dest="list", action="store_true", help="List all the test flows as a JSON object") self._parser.add_argument("-L", dest="logpath", default=".", help="Path to the logfile directory") self._parser.add_argument('-m', dest="metadata", action='store_true', help="Return the IdP metadata") self._parser.add_argument( "-P", dest="configpath", default=".", help="Path to the configuration file for the IdP") self._parser.add_argument("-t", dest="testpackage", help="Module describing tests") #self._parser.add_argument('-v', dest='verbose', action='store_true', # help="Print runtime information") # unsused self._parser.add_argument("-Y", dest="pysamllog", action='store_true', help="Print PySAML2 logs") self._parser.add_argument("oper", nargs="?", help="Which test to run") self.interactions = None self.entity_id = None self.constraints = {} self.args = None self.idp = None self.idp_config = None def json_config_file(self): if self.args.json_config_file == "-": return json.loads(sys.stdin.read()) else: return json.loads(open(self.args.json_config_file).read()) def idp_configure(self, metadata_construction=False): sys.path.insert(0, self.args.configpath) mod = import_module(self.args.config) self.idp_config = IdPConfig().load(mod.CONFIG, metadata_construction) if not self.args.insecure: self.idp_config.verify_ssl_cert = False else: if self.args.ca_certs: self.idp_config.ca_certs = self.args.ca_certs else: self.idp_config.ca_certs = "../keys/cacert.pem" # hack to change idp cert without config change. TODO: find interface to # change IDP cert after __init__ if self.args.oper == 'sp-04': self.idp_config.cert_file = os.path.join(self.args.keysdir, "non_md_cert.pem") self.idp_config.key_file = os.path.join(self.args.keysdir, "non_md_key.pem") for f in [self.idp_config.cert_file, self.idp_config.key_file]: if not os.path.isfile(f): print "File not found: %s" % os.path.abspath(f) raise self.idp = Server(config=self.idp_config) def test_summation(self, sid): status = 0 for item in self.test_log: if item["status"] > status: status = item["status"] if status == 0: status = 1 info = {"id": sid, "status": status, "tests": self.test_log} if status == 5: info["url"] = self.test_log[-1]["url"] info["htmlbody"] = self.test_log[-1]["message"] return info def output_log(self, memhndlr, hndlr2): """ """ print >> sys.stderr, 80 * ":" hndlr2.setFormatter(formatter_2) memhndlr.setTarget(hndlr2) memhndlr.flush() memhndlr.close() 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 >> sys.stderr, "Undefined testcase " + self.args.oper return else: print >> sys.stderr, "Undefined testcase " + self.args.oper 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, err: self.test_log = conv.test_output tsum = self.test_summation(self.args.oper) except FatalError, 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)
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)
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.operations: path, name = os.path.split(self.args.operations) self.operations = get_mod(name, [path]) else: self.operations = __import__("idp_test.saml2base", fromlist=["idp_test"]) 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('"') try: self.setup() except (AttributeError, ToOld) as err: print("Configuration Error: %s" % err, file=sys.stderr) self.client = Saml2Client(self.sp_config) conv = None if self.args.pretty: pp = pprint.PrettyPrinter(indent=4) else: pp = None try: try: oper = self.operations.OPERATIONS[self.args.oper] except KeyError: if self.tests: try: oper = self.tests.OPERATIONS[self.args.oper] except ValueError: logger.error("Undefined testcase") return else: logger.error("Undefined testcase") return logger.info("Starting conversation") conv = Conversation(self.client, self.sp_config, self.interactions, check_factory=self.check_factory, entity_id=self.entity_id, constraints=self.constraints) conv.do_sequence(oper) #testres, trace = do_sequence(oper, 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: 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) 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)
tsum = self.test_summation(self.args.oper) err = None except CheckError, err: self.test_log = conv.test_output tsum = self.test_summation(self.args.oper) except FatalError, 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, 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) if pp: pp.pprint(tsum) else: print >> sys.stdout, json.dumps(tsum, **JSON_DUMPS_ARGS) if tsum["status"] > 1 or self.args.debug or err: self.output_log(memoryhandler, streamhandler) def setup(self): self.json_config = self.json_config_file()
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)