def run(self): self.args = self._parser.parse_args() if self.args.list: return self.operations() else: if not self.args.flow: raise Exception("Missing flow specification") self.args.flow = self.args.flow.strip("'") self.args.flow = self.args.flow.strip('"') flow_spec = self.operations_mod.FLOWS[self.args.flow] try: block = flow_spec["block"] except KeyError: block = {} self.parse_args() _spec = self.make_sequence() interact = self.get_interactions() try: self.do_features(interact, _spec["sequence"], block) except Exception, exc: exception_trace("do_features", exc) return #tests = self.get_test() self.client.state = "STATE0" try: expect_exception = flow_spec["expect_exception"] except KeyError: expect_exception = False conv = None try: if self.pinfo: self.client.provider_info = self.pinfo if self.args.verbose: print >> sys.stderr, "Set up done, running sequence" conv = self.conversation_cls(self.client, self.cconf, self.trace, interact, msg_factory=self.msg_factory, check_factory=self.chk_factory, expect_exception=expect_exception) conv.do_sequence(_spec) #testres, trace = do_sequence(oper, self.test_log = conv.test_output tsum = self.test_summation(self.args.flow) print >>sys.stdout, json.dumps(tsum) if tsum["status"] > 1 or self.args.debug: print >> sys.stderr, self.trace except FatalError, err: self.test_log = conv.test_output tsum = self.test_summation(self.args.flow) print >>sys.stdout, json.dumps(tsum) print >> sys.stderr, self.trace
# try: # print >> sys.stderr, err.trace # except AttributeError: # pass # print err #exception_trace("RUN", err) except PyoidcError, err: if err.message: self.trace.info("Protocol message: %s" % err.message) print >> sys.stderr, self.trace print err exception_trace("RUN", err) except Exception, err: print >> sys.stderr, self.trace print err exception_trace("RUN", err) #if self._pop is not None: # self._pop.terminate() if "keyprovider" in self.environ and self.environ["keyprovider"]: # os.kill(self.environ["keyprovider"].pid, signal.SIGTERM) self.environ["keyprovider"].terminate() def operations(self): lista = [] for key, val in self.operations_mod.FLOWS.items(): item = {"id": key, "name": val["name"]} try: _desc = val["descr"] if isinstance(_desc, basestring): item["descr"] = _desc
def run(self): self.args = self._parser.parse_args() if self.args.list: return self.operations() else: if not self.args.flow: raise Exception("Missing flow specification") self.args.flow = self.args.flow.strip("'") self.args.flow = self.args.flow.strip('"') flow_spec = self.operations_mod.FLOWS[self.args.flow] try: block = flow_spec["block"] except KeyError: block = {} self.parse_args() _spec = self.make_sequence() _spec["flow"] = flow_spec["sequence"] interact = self.get_interactions() try: self.do_features(interact, _spec, block) except Exception, exc: exception_trace("do_features", exc) return try: expect_exception = flow_spec["expect_exception"] except KeyError: expect_exception = False conv = None try: if self.pinfo: self.client.provider_info = self.pinfo if self.args.verbose: print >> sys.stderr, "Set up done, running sequence" args = {"break": self.args.bailout} for arg in ["cookie_imp", "cookie_exp"]: try: val = getattr(self.args, arg) except AttributeError: continue else: args[arg] = val cf = self.get_login_cookies() if cf: args["login_cookies"] = cf for arg in ["extra_args", "kwargs_mod"]: try: args[arg] = self.json_config[arg] except KeyError: args[arg] = {} self.trace.info( "client preferences: %s" % self.client.client_prefs) conv = self.conversation_cls(self.client, self.cconf, self.trace, interact, msg_factory=self.msg_factory, check_factory=self.chk_factory, expect_exception=expect_exception, **args) try: conv.ignore_check = self.json_config["ignore_check"] except KeyError: pass if self.args.restart: conv.restore_state(self.args.restart) conv.do_sequence(_spec) #testres, trace = do_sequence(oper, self.test_log = conv.test_output tsum = self.test_summation(self.args.flow) if tsum["status"] > 1 or self.args.debug: print >> sys.stdout, json.dumps(tsum) print >> sys.stderr, self.trace except (FatalError, UnSupported), err: self.test_log = conv.test_output tsum = self.test_summation(self.args.flow) print >> sys.stdout, json.dumps(tsum) print >> sys.stderr, self.trace
'session.auto': True, 'session.timeout': 900 } sys.path.insert(0, ".") CONF = importlib.import_module(args.config) setup_logging("rp_%s.log" % CONF.PORT, LOGGER) try: if args.testflows: TEST_FLOWS = importlib.import_module(args.testflows) else: TEST_FLOWS = importlib.import_module("tests") except ImportError as ex: exception_trace("importing_test_flows", ex, LOGGER) raise if args.profile: TEST_PROFILE = args.profile else: TEST_PROFILE = "C.T.T.ns" if args.profiles: PROFILES = importlib.import_module(args.profiles) else: PROFILES = importlib.import_module("profiles") if args.testclass: TEST_CLASS = importlib.import_module(args.testclass) else:
def run(self): self.args = self._parser.parse_args() if self.args.list: return self.operations() else: if not self.args.flow: raise Exception("Missing flow specification") self.args.flow = self.args.flow.strip("'") self.args.flow = self.args.flow.strip('"') flow_spec = self.operations_mod.FLOWS[self.args.flow] try: block = flow_spec["block"] except KeyError: block = {} self.parse_args() _spec = self.make_sequence() interact = self.get_interactions() try: self.do_features(interact, _spec["sequence"], block) except Exception, exc: exception_trace("do_features", exc) return #tests = self.get_test() for role in ROLES: self.client[role].state = "STATE0" try: expect_exception = flow_spec["expect_exception"] except KeyError: expect_exception = False conv = None try: # for role in ROLES: # for key, val in self.pinfo[role].items(): # self.client[role][key].provider_info = {"": val} if self.args.verbose: print >> sys.stderr, "Set up done, running sequence" args = {} for arg in ["extra_args", "kwargs_mod"]: try: args[arg] = self.json_config[arg] except KeyError: args[arg] = {} conv = self.conversation_cls( self.client, self.cconf, self.trace, interact, resource_owner=self.json_config["RS"]["resource_owner"], requester=self.json_config["C"]["requester"], msg_factory=self.msg_factory, check_factory=self.chk_factory, expect_exception=expect_exception, **args) try: conv.ignore_check = self.json_config["ignore_check"] except KeyError: pass conv.do_sequence(_spec) #testres, trace = do_sequence(oper, self.test_log = conv.test_output tsum = self.test_summation(self.args.flow) if tsum["status"] > 1 or self.args.debug: print >> sys.stdout, json.dumps(tsum) print >> sys.stderr, self.trace except (FatalError, UnSupported), err: self.test_log = conv.test_output tsum = self.test_summation(self.args.flow) print >> sys.stdout, json.dumps(tsum) print >> sys.stderr, self.trace
class UMACombo(object): client_args = ["client_id", "redirect_uris", "password", "client_secret"] def __init__(self, operations_mod, combo, msg_factory, chk_factory, conversation_cls): self.operations_mod = operations_mod self.uma = combo self.roles = combo.keys() self.entity = {} self.cconf = {} self.pinfo = {} self.trace = Trace() self.msg_factory = msg_factory self.chk_factory = chk_factory self.conversation_cls = conversation_cls self._parser = argparse.ArgumentParser() #self._parser.add_argument('-v', dest='verbose', action='store_true') self._parser.add_argument('-d', dest='debug', action='store_true', help="Print debug information") self._parser.add_argument('-v', dest='verbose', action='store_true', help="Print runtime information") 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 is done")) self._parser.add_argument('-J', dest="json_config_file", help="Script configuration") self._parser.add_argument( '-I', dest="interactions", help=("Extra interactions not defined in the script ", "configuration file")) self._parser.add_argument( "-l", dest="list", action="store_true", help="List all the test flows as a JSON object") self._parser.add_argument( "-H", dest="host", help=( "Which host the script is running on, used to construct the ", "key export URL")) self._parser.add_argument("-x", dest="not_verify_ssl", action="store_true", help="Don't verify SSL certificates") self._parser.add_argument("flow", nargs="?", help="Which test flow to run") self._parser.add_argument( '-e', dest="external_server", action='store_true', help="A external web server are used to handle key export") self.args = None self.sequences = [] self.function_args = {} self.signing_key = None self.encryption_key = None self.test_log = [] self.environ = {} self._pop = None self.json_config = None self.features = {} self.keysrv_running = False def parse_args(self): self.json_config = self.json_config_file() for role in self.roles: try: self.features[role] = self.json_config[role]["features"] except KeyError: self.features[role] = {} self.pinfo[role] = self.provider_info(role) self.cconf[role] = self.entity_conf(role, self.client_args) 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 provider_info(self, role): res = {} try: _jc = self.json_config[role]["provider"] except KeyError: pass else: # Backward compatible if "endpoints" in _jc: try: for endp, url in _jc["endpoints"].items(): res[endp] = url except KeyError: pass return res 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: for log in reversed(self.test_log): if log["status"] == 5: info["url"] = log["url"] info["htmlbody"] = log["message"] break return info def run(self): self.args = self._parser.parse_args() if self.args.list: return self.operations() else: if not self.args.flow: raise Exception("Missing flow specification") self.args.flow = self.args.flow.strip("'") self.args.flow = self.args.flow.strip('"') flow_spec = self.operations_mod.FLOWS[self.args.flow] try: block = flow_spec["block"] except KeyError: block = {} self.parse_args() _spec = self.make_sequence() interact = self.get_interactions() try: self.do_features(interact, _spec["sequence"], block) except Exception, exc: exception_trace("do_features", exc) return #tests = self.get_test() for role in self.roles: self.entity[role].state = "STATE0" try: expect_exception = flow_spec["expect_exception"] except KeyError: expect_exception = False conv = None try: # for role in self.roles: # for key, val in self.pinfo[role].items(): # self.entity[role][key].provider_info = {"": val} if self.args.verbose: print >> sys.stderr, "Set up done, running sequence" args = {} for arg in ["extra_args", "kwargs_mod"]: try: args[arg] = self.json_config[arg] except KeyError: args[arg] = {} conv = self.conversation_cls( self.entity, self.cconf, self.trace, interact, resource_owner=self.json_config["RS"]["resource_owner"], requester=self.json_config["C"]["requester"], msg_factory=self.msg_factory, check_factory=self.chk_factory, expect_exception=expect_exception, **args) try: conv.ignore_check = self.json_config["ignore_check"] except KeyError: pass conv.do_sequence(_spec) #testres, trace = do_sequence(oper, self.test_log = conv.test_output tsum = self.test_summation(self.args.flow) if tsum["status"] > 1 or self.args.debug: print >> sys.stdout, json.dumps(tsum) print >> sys.stderr, self.trace except (FatalError, UnSupported), err: self.test_log = conv.test_output tsum = self.test_summation(self.args.flow) print >> sys.stdout, json.dumps(tsum) print >> sys.stderr, self.trace # try: # print >> sys.stderr, err.trace # except AttributeError: # pass # print err #exception_trace("RUN", err) except Exception, err: print >> sys.stderr, self.trace print err exception_trace("RUN", err)
def run(self): self.args = self._parser.parse_args() if self.args.list: return self.operations() else: if not self.args.flow: raise Exception("Missing flow specification") self.args.flow = self.args.flow.strip("'") self.args.flow = self.args.flow.strip('"') flow_spec = self.operations_mod.FLOWS[self.args.flow] try: block = flow_spec["block"] except KeyError: block = {} self.parse_args() _spec = self.make_sequence() interact = self.get_interactions() try: self.do_features(interact, _spec["sequence"], block) except Exception, exc: exception_trace("do_features", exc) return #tests = self.get_test() for role in self.roles: self.entity[role].state = "STATE0" try: expect_exception = flow_spec["expect_exception"] except KeyError: expect_exception = False conv = None try: # for role in self.roles: # for key, val in self.pinfo[role].items(): # self.entity[role][key].provider_info = {"": val} if self.args.verbose: print >> sys.stderr, "Set up done, running sequence" args = {} for arg in ["extra_args", "kwargs_mod"]: try: args[arg] = self.json_config[arg] except KeyError: args[arg] = {} conv = self.conversation_cls( self.entity, self.cconf, self.trace, interact, resource_owner=self.json_config["RS"]["resource_owner"], requester=self.json_config["C"]["requester"], msg_factory=self.msg_factory, check_factory=self.chk_factory, expect_exception=expect_exception, **args) try: conv.ignore_check = self.json_config["ignore_check"] except KeyError: pass conv.do_sequence(_spec) #testres, trace = do_sequence(oper, self.test_log = conv.test_output tsum = self.test_summation(self.args.flow) if tsum["status"] > 1 or self.args.debug: print >> sys.stdout, json.dumps(tsum) print >> sys.stderr, self.trace except (FatalError, UnSupported), err: self.test_log = conv.test_output tsum = self.test_summation(self.args.flow) print >> sys.stdout, json.dumps(tsum) print >> sys.stderr, self.trace
class OAuth2(object): client_args = ["client_id", "redirect_uris", "password", "client_secret"] def __init__(self, operations_mod, client_class, msg_factory, chk_factory, conversation_cls): self.operations_mod = operations_mod self.client_class = client_class self.client = None self.trace = Trace() self.msg_factory = msg_factory self.chk_factory = chk_factory self.conversation_cls = conversation_cls self._parser = argparse.ArgumentParser() #self._parser.add_argument('-v', dest='verbose', action='store_true') self._parser.add_argument('-d', dest='debug', action='store_true', help="Print debug information") self._parser.add_argument('-v', dest='verbose', action='store_true', help="Print runtime information") 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 is done") self._parser.add_argument('-J', dest="json_config_file", help="Script configuration") self._parser.add_argument( '-I', dest="interactions", help="Extra interactions not defined in the script " "configuration file") self._parser.add_argument( "-l", dest="list", action="store_true", help="List all the test flows as a JSON object") self._parser.add_argument( "-H", dest="host", help="Which host the script is running on, used to construct the " "key export URL") self._parser.add_argument("-x", dest="not_verify_ssl", action="store_true", help="Don't verify SSL certificates") self._parser.add_argument( '-B', dest="bailout", help="When user interaction is needed but not supported: break and" "dump state to file") self._parser.add_argument( '-Ki', dest="cookie_imp", help="File from which to import authentication/authz cookies") self._parser.add_argument( '-Ke', dest="cookie_exp", help="File to export authentication/authz cookies to") self._parser.add_argument( '-R', dest="restart", help="Restart test flow, resetting state to what's in the file") self._parser.add_argument("flow", nargs="?", help="Which test flow to run") self.args = None self.pinfo = None self.sequences = [] self.function_args = {} self.signing_key = None self.encryption_key = None self.test_log = [] self.environ = {} self._pop = None self.json_config = None self.features = {} def parse_args(self): self.json_config = self.json_config_file() try: self.features = self.json_config["features"] except KeyError: pass self.pinfo = self.provider_info() self.client_conf(self.client_args) 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 provider_info(self): # Should provide a Metadata class res = {} _jc = self.json_config["provider"] # Backward compatible if "endpoints" in _jc: try: for endp, url in _jc["endpoints"].items(): res[endp] = url except KeyError: pass return res 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: for log in reversed(self.test_log): if log["status"] == 5: info["url"] = log["url"] info["htmlbody"] = log["message"] break return info def run(self): self.args = self._parser.parse_args() if self.args.list: return self.operations() else: if not self.args.flow: raise Exception("Missing flow specification") self.args.flow = self.args.flow.strip("'") self.args.flow = self.args.flow.strip('"') flow_spec = self.operations_mod.FLOWS[self.args.flow] try: block = flow_spec["block"] except KeyError: block = {} self.parse_args() _spec = self.make_sequence() _spec["flow"] = flow_spec["sequence"] interact = self.get_interactions() try: self.do_features(interact, _spec, block) except Exception, exc: exception_trace("do_features", exc) return try: expect_exception = flow_spec["expect_exception"] except KeyError: expect_exception = False conv = None try: if self.pinfo: self.client.provider_info = self.pinfo if self.args.verbose: print >> sys.stderr, "Set up done, running sequence" args = {"break": self.args.bailout} for arg in ["cookie_imp", "cookie_exp"]: try: val = getattr(self.args, arg) except AttributeError: continue else: args[arg] = val cf = self.get_login_cookies() if cf: args["login_cookies"] = cf for arg in ["extra_args", "kwargs_mod"]: try: args[arg] = self.json_config[arg] except KeyError: args[arg] = {} self.trace.info("client preferences: %s" % self.client.client_prefs) conv = self.conversation_cls(self.client, self.cconf, self.trace, interact, msg_factory=self.msg_factory, check_factory=self.chk_factory, expect_exception=expect_exception, **args) try: conv.ignore_check = self.json_config["ignore_check"] except KeyError: pass if self.args.restart: conv.restore_state(self.args.restart) conv.do_sequence(_spec) #testres, trace = do_sequence(oper, self.test_log = conv.test_output tsum = self.test_summation(self.args.flow) if tsum["status"] > 1 or self.args.debug: print >> sys.stdout, json.dumps(tsum) print >> sys.stderr, self.trace except (FatalError, UnSupported), err: self.test_log = conv.test_output tsum = self.test_summation(self.args.flow) print >> sys.stdout, json.dumps(tsum) print >> sys.stderr, self.trace # try: # print >> sys.stderr, err.trace # except AttributeError: # pass # print err #exception_trace("RUN", err) except PyoidcError, err: if err.message: self.trace.info("Protocol message: %s" % err.message) print >> sys.stderr, self.trace print err exception_trace("RUN", err)
def run(self): self.args = self._parser.parse_args() if self.args.list: return self.operations() else: if not self.args.flow: raise Exception("Missing flow specification") self.args.flow = self.args.flow.strip("'") self.args.flow = self.args.flow.strip('"') flow_spec = self.operations_mod.FLOWS[self.args.flow] try: block = flow_spec["block"] except KeyError: block = {} self.parse_args() _spec = self.make_sequence() _spec["flow"] = flow_spec["sequence"] interact = self.get_interactions() try: self.do_features(interact, _spec, block) except Exception, exc: exception_trace("do_features", exc) return try: expect_exception = flow_spec["expect_exception"] except KeyError: expect_exception = False conv = None try: if self.pinfo: self.client.provider_info = self.pinfo if self.args.verbose: print >> sys.stderr, "Set up done, running sequence" args = {"break": self.args.bailout} for arg in ["cookie_imp", "cookie_exp"]: try: val = getattr(self.args, arg) except AttributeError: continue else: args[arg] = val cf = self.get_login_cookies() if cf: args["login_cookies"] = cf for arg in ["extra_args", "kwargs_mod"]: try: args[arg] = self.json_config[arg] except KeyError: args[arg] = {} self.trace.info("client preferences: %s" % self.client.client_prefs) conv = self.conversation_cls(self.client, self.cconf, self.trace, interact, msg_factory=self.msg_factory, check_factory=self.chk_factory, expect_exception=expect_exception, **args) try: conv.ignore_check = self.json_config["ignore_check"] except KeyError: pass if self.args.restart: conv.restore_state(self.args.restart) conv.do_sequence(_spec) #testres, trace = do_sequence(oper, self.test_log = conv.test_output tsum = self.test_summation(self.args.flow) if tsum["status"] > 1 or self.args.debug: print >> sys.stdout, json.dumps(tsum) print >> sys.stderr, self.trace except (FatalError, UnSupported), err: self.test_log = conv.test_output tsum = self.test_summation(self.args.flow) print >> sys.stdout, json.dumps(tsum) print >> sys.stderr, self.trace