def test_integration_delete_asset(self):
        log = logging.getLogger("Test")
        test_conn = Connection()
        test_action = DeleteAsset()

        test_conn.logger = log
        test_action.logger = log

        try:
            with open("../tests/delete_asset.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.assertEqual({"deleted": ["10.0.2.15"], "not_deleted": [], "success": True}, results)
Example #2
0
    def test_integration_search_threat_agents(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 = SearchThreatAgents()

        test_conn.logger = log
        test_action.logger = log

        try:
            with open("../tests/search_threat_agents.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)
    def test_find_agent_by_ip(self):
        ip = "10.0.2.15"
        ip_device_id = "6be117da-2f5d-4645-8878-1bc6476a399a"
        log = logging.getLogger("Test")
        test_conn = Connection()
        test_action = DeleteAsset()
        test_conn.logger = log
        test_action.logger = log

        try:
            with open("../tests/delete_asset.json") as file:
                test_json = json.loads(file.read()).get("body")
                connection_params = test_json.get("connection")
        except Exception as e:
            message = "Could not connection from /tests directory"
            self.fail(message)

        test_conn.connect(connection_params)
        test_action.connection = test_conn

        self.assertEqual(find_agent_by_ip(test_action.connection, "1.1.1.1"), "1.1.1.1")
        self.assertEqual(find_agent_by_ip(test_action.connection, ip), ip_device_id)
        self.assertNotEqual(find_agent_by_ip(test_action.connection, ip), "1.1.1.1")
        self.assertNotEqual(find_agent_by_ip(test_action.connection, ip), "10.0.2.15")