Exemplo n.º 1
0
def get_file(request):
    """
    Reads a case file and returns it's contents in JSOn format
    """

    try:
            file_path = request.GET.get('path')
            if file_path == "false":
                file_path = TEMPLATE
            vcf_obj = VerifyTestWrapperFile(TEMPLATE, file_path)
            output, data = vcf_obj.verify_file()
            if output["status"]:

                da_obj = GetDriversActions(navigator.get_warrior_dir()[:-1])
                if file_path == TEMPLATE:
                    output["filepath"] = read_json_data(CONFIG_FILE)["testwrapper"]
                else:
                    output["filepath"] = get_parent_dir_path(file_path)
                output["filename"] = os.path.splitext(get_dir_from_path(file_path))[0]
                output["drivers"] = da_obj.get_all_actions()
                output["html_data"] = render_to_string('testwrapper/display_case.html', {"data": data,
                                                                                   "defaults": DROPDOWN_DEFAULTS,
                                                                                   "drivers": output["drivers"]})
                return JsonResponse(output)
            else:
                JsonResponse({"status": output["status"], "message": output["message"]})
    except Exception as e:
        return JsonResponse({"status": 0,"message":"Exception opening the file"})
Exemplo n.º 2
0
def get_list_of_suites(request):
    """
    Returns a list of suites
    """
    config = read_json_data(CONFIG_FILE)
    return JsonResponse(
        {"data": navigator.get_dir_tree_json(config["testsuitedir"])})
Exemplo n.º 3
0
    def ready(self):
        """
        The ready function is trigger only on events like server start up and server reload
        """
        # print "***************You are in Core Katana App Config Class***************"
        nav_obj = Navigator()

        base_directory = nav_obj.get_katana_dir()
        warrior_dir = nav_obj.get_warrior_dir()
        config_file_name = "wf_config.json"
        config_json_file = join_path(base_directory, "config.json")
        settings_file_path = get_abs_path(join_path("wui", "settings.py"), base_directory)
        core_index_obj = CoreIndex(base_directory, settings_file_path=settings_file_path)

        available_apps = core_index_obj.get_available_apps()
        settings_apps = core_index_obj.get_apps_from_settings_file()

        AppInformation.information = Apps()

        AppInformation.information.set_apps({'base_directory': base_directory,
                                             'config_file_name': config_file_name,
                                             'available_apps': available_apps,
                                             'settings_apps': settings_apps})

        ordered_json = validate_config_json(read_json_data(config_json_file), warrior_dir)
        with open(config_json_file, "w") as f:
            f.write(json.dumps(ordered_json, indent=4))
Exemplo n.º 4
0
def read_config_file(request):
    nav_obj = Navigator()
    config_file_path = join_path(nav_obj.get_katana_dir(), "config.json")
    data = read_json_data(config_file_path)
    if data is None:
        data = False
    return JsonResponse(data)
Exemplo n.º 5
0
    def __edit_urls_py(self):
        checker = "RedirectView.as_view(url='/katana/')"
        data = read_json_data(self.wf_config_file)

        if data["app"]["url"].startswith("/"):
            app_url = data["app"]["url"][1:]
        else:
            app_url = data["app"]["url"]
        self.urls_inclusions.append("url(r'^" + app_url + "', include('" +
                                    data["app"]["include"] + "')),")

        data = readlines_from_file(self.urls_file)
        self.urls_backup = data
        index = -1
        for i in range(0, len(data)):
            if checker in data[i]:
                index = i + 1
                break
        white_space = data[index].split("url")
        for i in range(0, len(self.urls_inclusions)):
            self.urls_inclusions[
                i] = white_space[0] + self.urls_inclusions[i] + "\n"

        u_data = data[:index]
        u_data.extend(self.urls_inclusions)
        u_data.extend(data[index:])

        urls_data = ""
        for line in u_data:
            urls_data += line
        output = write_to_file(self.urls_file, urls_data)
        return output
Exemplo n.º 6
0
def get_jstree_dir(request):
    """
        Prepare the json for jstree to use
    """
    config = read_json_data(JSON_CONFIG)
    data = Navigator().get_dir_tree_json(config["idfdir"])
    data["text"] = config["idfdir"]
    # print json.dumps(data, indent=4)
    return JsonResponse(data)
 def get_engineer_name(self):
     """
     This function returns the full name (if given in the user_profile.json) of the user.
     :return:
     """
     user_profile = join_path(self.get_katana_dir(), "user_profile.json")
     profile_data = read_json_data(user_profile)
     name = ""
     if profile_data is not None:
         name = (profile_data["firstName"] + " " +
                 profile_data["lastName"]).strip()
     return name
 def set_apps(self, data):
     """ call this to build Apps array and make app objects """
     self.get_config_paths(data)
     for url in self.paths:
         json_data = read_json_data(url)
         if json_data is not None:
             app_path = get_parent_directory(url)
             app = App(json_data, app_path, data["base_directory"])
             js_urls = get_paths_of_subfiles(
                 join_path(app_path, app.static_file_dir, "js"),
                 extension=compile_regex("^\.js$"))
             for i in range(0, len(js_urls)):
                 js_urls[i] = get_relative_path(js_urls[i], app_path)
             app.data["js_urls"] = js_urls
             self.apps.append(app)
     return self.apps
Exemplo n.º 9
0
def index(request):
    """
        Read an xml file and return the editor page with xml content in it
    """
    config = read_json_data(JSON_CONFIG)
    wdfdir = config["idfdir"]

    # Check to open new/existing file
    if request.method == "POST":
        data = request.POST
        if os.path.isfile(data["path"]):
            xml_data = xmltodict.parse(open(data["path"]).read())

            # Generate the filepath to use on webpage
            filepath = data["path"]
            filepath = filepath.replace(wdfdir, "")
            filepath = filepath[1:] if filepath.startswith(
                os.sep) else filepath

            # xml should only has 1 root
            root = list(xml_data.keys())[0]

            data, ref_dict = process_xml(xml_data)
            return render(
                request, 'wdf_edit/index.html', {
                    "data": xml_data[root],
                    "data_read": ref_dict,
                    "filepath": filepath,
                    "desc": xml_data[root].get("description", "")
                })
        else:
            return render(request, 'wdf_edit/failure.html')
    else:
        sample_data = {
            "system": [{
                "@name": "Example system",
                "Example key": "Example value"
            }]
        }
        ref_dict = copy.deepcopy(sample_data)
        return render(request, 'wdf_edit/index.html', {
            "data": sample_data,
            "data_read": ref_dict,
            "filepath": ""
        })
Exemplo n.º 10
0
    def is_valid(self):
        output = {"status": True, "message": ""}
        if os.path.exists(self.wf_config_file):
            data = read_json_data(self.wf_config_file)
            if data is not None:
                for field in self.mandatory_fields:
                    if output["status"] and field not in data:
                        output["status"] = False
                        output[
                            "message"] = "wf_config.json is not in the correct format."
                        print("-- An Error Occurred -- {0}".format(
                            output["message"]))

                if output["status"]:
                    output = self.__verify_app_details(data["app"])

                # validate version compatibility
                if output["status"]:
                    output = self.__is_compatible(data)

                # validate databases if any
                if output["status"] and "database" in data:
                    if isinstance(data["database"], list):
                        for db_details in data["database"]:
                            if output["status"]:
                                output = self.__verify_db_details(db_details)
                    else:
                        output = self.__verify_db_details(data["database"])
            else:
                output["status"] = False
                output[
                    "message"] = "wf_config.json is not in the correct format."
                print("-- An Error Occurred -- {0}".format(output["message"]))

            if output["status"]:
                output = self.__validate_static_directory()
        else:
            output["status"] = False
            output["message"] = "wf_config.json does not exist."
            print("-- An Error Occurred -- {0}".format(output["message"]))
        return output
Exemplo n.º 11
0
 def __init__(self, base_directory, app_path, app_type):
     self.app_name = get_dir_from_path(app_path)
     self.base_directory = base_directory
     self.plugin_dir = join_path(self.base_directory, "warrior", "plugins")
     self.app_dir = join_path(self.base_directory, "katana", app_type)
     self.settings_file = join_path(self.base_directory, "katana", "wui",
                                    "settings.py")
     self.urls_file = join_path(self.base_directory, "katana", "wui",
                                "urls.py")
     self.app_path = get_abs_path(self.app_name, self.app_dir)
     self.app_type = app_type
     self.config_file = join_path(self.app_path, "wf_config.json")
     self.config_file_data = read_json_data(self.config_file)
     self.related_plugins = self.__extract_plugin_names()
     self.pkg_in_settings = self.__get_setting_file_info()
     self.include_urls = self.__get_urls_info()
     self.valid_app_types = {"wapps"}
     self.cache_dir = create_dir(
         join_path(self.base_directory, "katana", ".data", self.app_name))
     self.settings_backup = []
     self.urls_backup = []
Exemplo n.º 12
0
def get_file(request):
    """
    Reads a file, validates it, computes the HTML and returns it as a JSON response
    """
    try:

        file_path = request.GET.get('path', )
        if file_path == "false":
            file_path = TEMPLATE
        vcf_obj = VerifySuiteFile(TEMPLATE, file_path)
        output, data = vcf_obj.verify_file()
        if output["status"]:
            mid_req = (len(data["TestSuite"]["Requirements"]["Requirement"]) +
                       1) / 2
            if file_path == TEMPLATE:
                output["filepath"] = read_json_data(
                    CONFIG_FILE)["testsuitedir"]
            else:
                output["filepath"] = get_parent_dir_path(file_path)
            output["filename"] = os.path.splitext(
                get_dir_from_path(file_path))[0]
            output["html_data"] = render_to_string(
                'suites/display_suite.html', {
                    "data": data,
                    "mid_req": mid_req,
                    "defaults": DROPDOWN_DEFAULTS
                })
            return JsonResponse(output)
        else:
            JsonResponse({
                "status": output["status"],
                "message": output["message"]
            })
    except Exception as e:
        return JsonResponse({
            "status": 0,
            "message": "Exception opening the file"
        })
Exemplo n.º 13
0
def on_post(request):
    """
        Main function that handles a post request with edited xml data
    """
    data = json.loads(request.body.decode("utf-8"))
    filepath = data.get("filepath", None)
    desc = data.get("description", "")
    systems = build_xml_dict(data["systems"])
    result = {"credentials": OrderedDict()}
    if desc:
        result["credentials"]["description"] = desc
    result["credentials"]["system"] = systems

    from xml.dom.minidom import parseString as miniparse
    print(miniparse(xmltodict.unparse(result)).toprettyxml())

    config = read_json_data(JSON_CONFIG)
    wdfdir = config["idfdir"]
    filepath = os.path.join(wdfdir, filepath)
    print("Filepath:", filepath)
    f = open(filepath, "w")
    f.write(miniparse(xmltodict.unparse(result)).toprettyxml())
    return render(request, 'wdf_edit/file_list.html')
Exemplo n.º 14
0
from django.shortcuts import render
from django.template.loader import render_to_string
from django.views import View
from utils.directory_traversal_utils import join_path, get_dir_from_path, get_parent_dir_path
from utils.json_utils import read_json_data
from utils.navigator_util import Navigator
from wapps.testwrapper.testwrapper_utils.defaults import impacts, on_errors, runmodes, iteration_types, contexts
from wapps.testwrapper.testwrapper_utils.get_drivers import GetDriversActions
from wapps.testwrapper.testwrapper_utils.verify_testwrapper_file import VerifyTestWrapperFile

navigator = Navigator()
CONFIG_FILE = join_path(navigator.get_katana_dir(), "config.json")
APP_DIR = join_path(navigator.get_katana_dir(), "wapps", "testwrapper")
STATIC_DIR = join_path(APP_DIR, "static", "testwrapper")
TEMPLATE = join_path(STATIC_DIR, "base_templates", "Untitled.xml")
DROPDOWN_DEFAULTS = read_json_data(join_path(STATIC_DIR, "base_templates", "dropdowns_data.json"))


clas TestWrapperView(View):

    def get(self, request):
        """
        Get Request Method
        """
        return render(request, 'testwrapper/cases.html')


def get_list_of_testwrappers(request):
    """
    Returns a list of cases
    """