def test(name, protocol=None): url = ''.join([protocol + "://" if protocol else "", name]) sprotocol, shost, sport, sname = split_product_url(url) self.assertEqual(sprotocol, expected_protocol(protocol, None)) self.assertEqual(shost, "localhost") self.assertEqual(sport, expected_port(protocol, None)) self.assertEqual(sname, name)
def test(host, port, name, protocol=None): url = ''.join([protocol + "://" if protocol else "", host, ":", str(port), "/", name]) sprotocol, shost, sport, sname = split_product_url(url) self.assertEqual(sprotocol, expected_protocol(protocol, port)) self.assertEqual(shost, host) self.assertEqual(sport, expected_port(protocol, port)) self.assertEqual(sname, name)
def testBadProductNames(self): """ Parser throws on bad product URLs? """ with self.assertRaises(ValueError): split_product_url("123notaproductname") with self.assertRaises(ValueError): split_product_url("localhost//containsExtraChar") with self.assertRaises(ValueError): split_product_url("in:valid:format/product") with self.assertRaises(ValueError): split_product_url("localhost:12PortIsANumber34/Foo") with self.assertRaises(ValueError): split_product_url("codechecker://codecheker.com/Baz") with self.assertRaises(ValueError): # Make sure we don't understand "https://foobar.baz:1234" as # HTTPS, localhost, 443, and "foobar.baz:1234" product name. split_product_url("https://foobar.bar:1234")
def main(args): """ Store the defect results in the specified input list as bug reports in the database. """ logger.setup_logger(args.verbose if 'verbose' in args else None) if not host_check.check_zlib(): raise Exception("zlib is not available on the system!") # To ensure the help message prints the default folder properly, # the 'default' for 'args.input' is a string, not a list. # But we need lists for the foreach here to work. if isinstance(args.input, str): args.input = [args.input] if 'name' not in args: LOG.debug("Generating name for analysis...") generated = __get_run_name(args.input) if generated: setattr(args, 'name', generated) else: LOG.error("No suitable name was found in the inputs for the " "analysis run. Please specify one by passing argument " "--name run_name in the invocation.") sys.exit(2) # argparse returns error code 2 for bad invocations. LOG.info("Storing analysis results for run '" + args.name + "'") if 'force' in args: LOG.info("argument --force was specified: the run with name '" + args.name + "' will be deleted.") protocol, host, port, product_name = split_product_url(args.product_url) # Before any transmission happens, check if we have the PRODUCT_STORE # permission to prevent a possibly long ZIP operation only to get an # error later on. product_client = libclient.setup_product_client(protocol, host, port, product_name) product_id = product_client.getCurrentProduct().id auth_client, _ = libclient.setup_auth_client(protocol, host, port) has_perm = libclient.check_permission( auth_client, Permission.PRODUCT_STORE, {'productID': product_id}) if not has_perm: LOG.error("You are not authorised to store analysis results in " "product '%s'", product_name) sys.exit(1) # Setup connection to the remote server. client = libclient.setup_client(args.product_url, product_client=False) LOG.debug("Initializing client connecting to %s:%d/%s done.", host, port, product_name) _, zip_file = tempfile.mkstemp('.zip') LOG.debug("Will write mass store ZIP to '%s'...", zip_file) try: assemble_zip(args.input, zip_file, client) if os.stat(zip_file).st_size > MAX_UPLOAD_SIZE: LOG.error("The result list to upload is too big (max: %s).", sizeof_fmt(MAX_UPLOAD_SIZE)) sys.exit(1) with open(zip_file, 'rb') as zf: b64zip = base64.b64encode(zf.read()) context = webserver_context.get_context() trim_path_prefixes = args.trim_path_prefix if \ 'trim_path_prefix' in args else None client.massStoreRun(args.name, args.tag if 'tag' in args else None, str(context.version), b64zip, 'force' in args, trim_path_prefixes) # Storing analysis statistics if the server allows them. if client.allowsStoringAnalysisStatistics(): storing_analysis_statistics(client, args.input, args.name) LOG.info("Storage finished successfully.") except RequestFailed as reqfail: if reqfail.errorCode == ErrorCode.SOURCE_FILE: header = ['File', 'Line', 'Checker name'] table = twodim_to_str('table', header, [c.split('|') for c in reqfail.extraInfo]) LOG.warning("Setting the review statuses for some reports failed " "because of non valid source code comments: " "%s\n %s", reqfail.message, table) sys.exit(1) except Exception as ex: LOG.info("Storage failed: %s", str(ex)) sys.exit(1) finally: os.remove(zip_file)