예제 #1
0
    def test_integration_get_file_id_from_alert_id(self):
        log = logging.getLogger("Test")
        test_conn = Connection()
        test_action = GetFileIdFromAlertId()

        test_conn.logger = log
        test_action.logger = log

        try:
            with open("../tests/get_file_id_from_alert_id.json") as file:
                test_json = json.loads(file.read()).get("body")
                connection_params = test_json.get("connection")
                action_params = test_json.get("input")
        except Exception as e:
            message = """
            Could not find or read sample tests from /tests directory
            
            An exception here likely means you didn't fill out your samples correctly in the /tests directory 
            Please use 'icon-plugin generate samples', and fill out the resulting test files in the /tests directory
            """
            self.fail(message)

        test_conn.connect(connection_params)
        test_action.connection = test_conn
        results = test_action.run(action_params)

        # TODO: The following assert should be updated to look for data from your action
        # For example: self.assertEquals({"success": True}, results)
        self.assertTrue("file_list" in results.keys())
예제 #2
0
    def test_integration_get_alerts(self, mockSend):
        log = logging.getLogger("Test")

        try:
            with open("../tests/get_alerts.json") as f:
                data = json.load(f)
                connection_params = data.get("body").get("connection")
                trigger_params = data.get("body").get("input")
        except Exception as e:
            message = """
            Could not find or read sample tests from /tests directory
            
            An exception here likely means you didn't fill out your samples correctly in the /tests directory 
            Please use 'icon-plugin generate samples', and fill out the resulting test files in the /tests directory
            """
            self.fail(message)

        test_connection = Connection()
        test_connection.logger = log
        test_connection.connect(connection_params)

        test_email_received = GetAlerts()
        test_email_received.connection = test_connection
        test_email_received.logger = log

        test_email_received.run(trigger_params)

        self.fail()  # If we made it this far, the run loop failed somehow
예제 #3
0
    def test_integration_get_machine_information(self):
        log = logging.getLogger("Test")
        test_conn = Connection()
        test_action = GetMachineInformation()

        test_conn.logger = log
        test_action.logger = log

        try:
            with open("../tests/get_machine_information.json") as file:
                test_json = json.loads(file.read()).get("body")
                connection_params = test_json.get("connection")
                action_params = test_json.get("input")
        except Exception as e:
            message = """
            Could not find or read sample tests from /tests directory
            
            An exception here likely means you didn't fill out your samples correctly in the /tests directory 
            Please use 'icon-plugin generate samples', and fill out the resulting test files in the /tests directory
            """
            self.fail(message)

        test_conn.connect(connection_params)
        test_action.connection = test_conn
        results = test_action.run(action_params)

        self.assertTrue("machine" in results.keys())
예제 #4
0
    def test_integration_stop_and_quarantine_file(self):
        """
        TODO: Implement assertions at the end of this test case

        This is an integration test that will connect to the services your plugin uses. It should be used
        as the basis for tests below that can run independent of a "live" connection.

        This test assumes a normal plugin structure with a /tests directory. In that /tests directory should
        be json samples that contain all the data needed to run this test. To generate samples run:

        icon-plugin generate samples

        """

        log = logging.getLogger("Test")
        test_conn = Connection()
        test_action = StopAndQuarantineFile()

        test_conn.logger = log
        test_action.logger = log

        try:
            with open("../tests/stop_and_quarantine_file.json") as file:
                test_json = json.loads(file.read()).get("body")
                connection_params = test_json.get("connection")
                action_params = test_json.get("input")
        except Exception as e:
            message = """
            Could not find or read sample tests from /tests directory
            
            An exception here likely means you didn't fill out your samples correctly in the /tests directory 
            Please use 'icon-plugin generate samples', and fill out the resulting test files in the /tests directory
            """
            self.fail(message)

        test_conn.connect(connection_params)
        test_action.connection = test_conn
        results = test_action.run(action_params)

        # TODO: Remove this line
        self.fail("Unimplemented test case")

        # TODO: The following assert should be updated to look for data from your action
        # For example: self.assertEquals({"success": True}, results)
        self.assertEquals({}, results)
예제 #5
0
    def test_integration_get_alert_matching_key(self, mockSend):
        """
        TODO: Manually validate results

        Because the send function is essentially an endless loop, there's no way to validate the output from
        that in an elegant way. Really this test is just making sure no exceptions are thrown.

        The bulk of your logic for your trigger should not be in the run loop and should be tested with subsequent
        tests.
        """
        log = logging.getLogger("Test")

        try:
            with open("../tests/get_alert_matching_key.json") as f:
                data = json.load(f)
                connection_params = data.get("body").get("connection")
                trigger_params = data.get("body").get("input")
        except Exception as e:
            message = """
            Could not find or read sample tests from /tests directory
            
            An exception here likely means you didn't fill out your samples correctly in the /tests directory 
            Please use 'icon-plugin generate samples', and fill out the resulting test files in the /tests directory
            """
            self.fail(message)

        test_connection = Connection()
        test_connection.logger = log
        test_connection.connect(connection_params)

        test_email_received = GetAlertMatchingKey()
        test_email_received.connection = test_connection
        test_email_received.logger = log

        test_email_received.run(trigger_params)

        self.fail()  # If we made it this far, the run loop failed somehow