Ejemplo n.º 1
0
    def test_edit_target_form_post(rf):
        """
        This test imitates a editing a target by using the
        form and doing a request.POST
        """
        target_key = ""
        for target_item in get_brain_targets():
            target_key = target_item["id"]

        post_data = {
            "plugin_name": "Plugin1",
            "location_num": "127.0.0.1",
            "port_num": "8000",
            "optional_char": ""
        }
        url_var = "action/val_edit_target_form/{}/".format(target_key)
        response = post_test(url_var,
                             post_data,
                             val_edit_target_form,
                             rf,
                             target_id=target_key)
        assert response.status_code == 302
        assert response.url == "/"
        response = post_test(url_var, {},
                             val_edit_target_form,
                             rf,
                             target_id=target_key)
        assert response.status_code == 302
Ejemplo n.º 2
0
    def test_job_state2(rf):
        """
        This test imitates saving a job state in W3
        as a second test
        :param rf: request factory
        :return: status code
        """
        url_var = "action/save_state/"
        post_data = {
            "id_map": {
                "1": "9859bfb8-8676-4595-8ce2-176957574875"
            },
            "id_reverse_map": {
                "9859bfb8-8676-4595-8ce2-176957574875": 1
            },
            "jobs": [{
                "plugin": "Plugin1",
                "address": "172.16.5.49",
                "job": {
                    "Output":
                    True,
                    "OptionalInputs": [],
                    "Tooltip":
                    "\nEcho\n\nClient Returns this string "
                    "verbatim\n\nArguments:\n1. String to "
                    "Echo\n\nReturns:\nString\n",
                    "CommandName":
                    "echo",
                    "Inputs": [{
                        "Tooltip": "This string will be echoed back",
                        "Type": "textbox",
                        "Name": "EchoString",
                        "Value": "dd"
                    }],
                    "id":
                    "c8999a01-91fb-43f7-8bc5-7aa8ec789688"
                },
                "status": "None"
            }],
            "sequences": {
                "1": ["1"]
            },
            "active_sequence":
            "1"
        }

        with pytest.raises(json.JSONDecodeError):
            current_state = json.loads(str(post_data))
            response = post_test(url_var, current_state, persist_job_state, rf)
            assert response.status_code == 200
            response = post_test(url_var, {}, persist_job_state, rf)
            assert response.status_code == 200
Ejemplo n.º 3
0
 def test_execute_w3_data_ui_fail(rf):
     """
     This test is replicating when the user clicks on 'Execute Sequence'
     button at the bottom right of w3. With using false data.
     """
     url_var = "/action/get_w3_data/"
     with pytest.raises(json.JSONDecodeError):
         json_data = json.loads(str(SAMPLE_ERROR_JOB))
         response = post_test(url_var, json_data,
                              execute_sequence_controller, rf)
         assert response.status_code == 200
         response = post_test(url_var, {}, execute_sequence_controller, rf)
         assert response.status_code == 200
Ejemplo n.º 4
0
 def test_file_upload(rf):
     """
     This test imitates uploading a file
     :param rf: request factory
     :return: status code
     """
     url_var = "file_upload/"
     response = get_test(url_var, file_upload_list, rf)
     assert response.status_code == 200
     with pytest.raises(json.JSONDecodeError):
         post_data = json.loads(str(SAMPLE_FILE_ID))
         response = post_test(url_var, post_data, file_upload_list, rf)
         assert response.status_code == 200
         response = post_test(url_var, {}, file_upload_list, rf)
         assert response.status_code == 200
Ejemplo n.º 5
0
 def test_add_plugin_ok(rf):
     """
     This test is replicating when the user clicks on
     'Execute Sequence' button at the bottom right of w3.
     """
     url_var = "/update_plugin/NEW/"
     plugin_data = {
         "id": "NEW",
         "Name": "Plugin3",
         "ServiceName": "Plugin3-4243tcp",
         "ServiceID": "cheeto3",
         "State": "Stopped",
         "DesiredState": "",
         "OS": "all",
         "Interface": "1.1.1.1",
         "Environment": [],
         "Environment[]": "",
         "ExternalPorts": ["12/tcp"],
         "ExternalPorts[]": "12/tcp",
         "InternalPorts": ["12/tcp"],
         "InternalPorts[]": "12/tcp",
         "Extra": True,
     }
     RPP.insert({"Interface": "1.1.1.1", "TCPPorts": ["11"]}).run(connect())
     response = post_test(url_var,
                          plugin_data,
                          update_plugin,
                          rf,
                          target_id="NEW")
     assert response.status_code == 200
Ejemplo n.º 6
0
 def test_post_saved_command(rf):
     post_data = {
         "PluginName": "Plugin1",
         "Name": "sample",
         "Command_js": "{}",
     }
     url_var = "action/put_saved_command/"
     response = post_test(url_var, post_data, put_saved_command, rf)
     assert response.status_code == 200
Ejemplo n.º 7
0
    def test_job_state(rf):
        """
        This test imitates saving a job state in W3
        :param rf: request factory
        :return: status code
        """
        url_var = "action/save_state/"
        post_data = {
            "replaced": 1,
            "inserted": 0,
            "deleted": 0,
            "errors": 0,
            "unchanged": 0,
            "skipped": 0
        }

        with pytest.raises(json.JSONDecodeError):
            current_state = json.loads(str(post_data))
            response = post_test(url_var, current_state, persist_job_state, rf)
            assert response.status_code == 200
            response = post_test(url_var, {}, persist_job_state, rf)
            assert response.status_code == 200
Ejemplo n.º 8
0
    def test_target_form_post(rf):
        """Test posting a target

        Sends POST to the val_target_form method
        to ensure it processes POST requests.

        Arguments:
            rf {RequestFactory} -- used for mocking
            requests.
        """
        post_data = {
            "plugin_name": "Plugin1",
            "location_num": "127.0.0.1",
            "port_num": "8000",
            "optional_char": ""
        }
        url_var = "/action/val_target_form"
        response = post_test(url_var, post_data, val_target_form, rf)
        assert response.status_code == 302
        assert response.url == "/"
        response = post_test(url_var, {}, val_target_form, rf)
        assert response.status_code == 200
Ejemplo n.º 9
0
 def test_execute_w3_data_ui(self, rf):
     """
     This test is replicating when the user clicks on
     'Execute Sequence' button at the bottom right of w3.
     """
     url_var = "/action/get_w3_data/"
     # with pytest.raises(json.JSONDecodeError):
     my_job = deepcopy(SAMPLE_JOB)
     del my_job["id"]
     jobs_json = json.dumps([my_job])
     json_data = {"jobs": jobs_json}
     response = post_test(url_var, json_data, execute_sequence_controller,
                          rf)
     assert response.status_code == 200
Ejemplo n.º 10
0
 def test_execute_w3_data_two(self, rf):
     """
     This test is replicating when the user clicks on
     'Execute Sequence' button at the bottom right of w3 but
     the command has two arguments.
     """
     job_url = "/action/get_w3_data/"
     with pytest.raises(json.JSONDecodeError):
         status_obj = self.status_code_test2(
             url_str=job_url,
             post_data=SAMPLE_JOB,
             function_obj=execute_sequence_controller,
             rf=rf)
         assert "inserted" in str(status_obj.content)
         status_obj = post_test(job_url, {}, execute_sequence_controller,
                                rf)
         assert status_obj.status_code == 200
Ejemplo n.º 11
0
 def test_stop_job(rf):
     """
     This test is replicating the data displayed in W4 when a user clicks
     on 'Execute Sequence' button at the bottom right of w3. With correct data.
     """
     first_url = "/action/get_w3_data/"
     with pytest.raises(json.JSONDecodeError):
         json_data = json.loads(str(SAMPLE_JOB))
         response = post_test(first_url, json_data,
                              execute_sequence_controller, rf)
         assert "inserted" in str(response.content)
         assert response.status_code == 200
         job_id = json.loads(
             response.getvalue().decode())['generated_keys'][0]
         sleep(2)
         second_url = "/stop_job/{}/".format(job_id)
         assert stop_job(rf.get(second_url, HTTP_USER_AGENT='Mozilla/5.0'),
                         job_id).status_code == 200