Ejemplo n.º 1
0
def is_empty(multi_parameters, http_request_method):
  if settings.VERBOSITY_LEVEL >= 1:
    info_msg = "Checking for empty values in provided data."  
    print(settings.print_info_msg(info_msg))
  provided_value = []
  multi_params = [s for s in multi_parameters]
  if settings.IS_JSON:
    multi_params = ','.join(multi_params)
    json_data = json.loads(multi_params, object_pairs_hook=OrderedDict)
    multi_params = flatten(json_data)
  for empty in multi_params:
    try:
      if settings.IS_JSON:
        if len(str(multi_params[empty])) == 0:
          provided_value.append(empty)
      elif settings.IS_XML:
        if re.findall(r'>(.*)<', empty)[0] == "" or \
           re.findall(r'>(.*)<', empty)[0] == " ":
          provided_value.append(re.findall(r'</(.*)>', empty)[0])  
      elif len(empty.split("=")[1]) == 0:
        provided_value.append(empty.split("=")[0])
    except IndexError:
      if not settings.IS_XML:
        err_msg = "No parameter(s) found for testing in the provided data."
        print(settings.print_critical_msg(err_msg))
        raise SystemExit() 
  provided_value = ", ".join(provided_value)
  if len(provided_value) > 0:
    if menu.options.skip_empty and len(multi_parameters) > 1:
      skip_empty(provided_value, http_request_method)
    else:
      warn_msg = "The provided value"+ "s"[len(provided_value.split(",")) == 1:][::-1]
      warn_msg += " for " + http_request_method 
      warn_msg += ('', ' (JSON)')[settings.IS_JSON] + ('', ' (SOAP/XML)')[settings.IS_XML] 
      warn_msg += " parameter" + "s"[len(provided_value.split(",")) == 1:][::-1]
      warn_msg += " '" + provided_value + "'"
      warn_msg += (' are ', ' is ')[len(provided_value.split(",")) == 1] + "empty. "
      warn_msg += "Use valid "
      warn_msg += "values to run properly."
      print(settings.print_warning_msg(warn_msg))
      return True
Ejemplo n.º 2
0
def check_similarities(all_params):
  if settings.IS_JSON:
    all_params = ','.join(all_params)
    json_data = json.loads(all_params, object_pairs_hook=OrderedDict)
    all_params = flatten(json_data)
    for param in all_params:
      if param == all_params[param]:
        parameter_name = param
        all_params[param] = param + settings.RANDOM_TAG
    all_params = [x.replace(" ", "") for x in json.dumps(all_params).split(", ")]
  else:
    for param in range(0, len(all_params)):
      if settings.IS_XML:
        if re.findall(r'</(.*)>', all_params[param]) == re.findall(r'>(.*)</', all_params[param]):
          parameter_name = re.findall(r'>(.*)</', all_params[param])
          parameter_name = ''.join(parameter_name)
          all_params[param] = "<" + parameter_name + ">" + parameter_name + settings.RANDOM_TAG + "</" + parameter_name + ">"
      else:
        if re.findall(r'(.*)=', all_params[param]) == re.findall(r'=(.*)', all_params[param]):
          parameter_name = re.findall(r'=(.*)', all_params[param])
          parameter_name = ''.join(parameter_name)
          all_params[param] = parameter_name + "=" + parameter_name + settings.RANDOM_TAG
  return all_params