コード例 #1
0
    def test_integration_add_access_rule(self):
        log = logging.getLogger("Test")
        test_conn = Connection()
        test_action = AddAccessRule()

        test_conn.logger = log
        test_action.logger = log

        try:
            with open("../tests/add_access_rule.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:
            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.assertIsNotNone(results)
    def test_integration_add_host_to_network_group(self):
        log = logging.getLogger("Test")
        test_conn = Connection()
        test_action = AddHostToNetworkGroup()

        test_conn.logger = log
        test_action.logger = log

        try:
            with open("../tests/add_host_to_network_group.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.assertEquals({"success": True}, results)
コード例 #3
0
    def test_add_access_rule_object_locked(self, mockPost):
        logger = logging.getLogger("test")
        test_connection = Connection()
        test_action = AddAccessRule()

        test_connection.logger = logger
        test_action.logger = logger

        connection_params = {
            "port": 666,
            "server": "1.1.1.2",
            "ssl_verify": True,
            "username_password": {
                "password": "******",
                "username": "******"
            }
        }

        action_params = {
            "action": "Drop",
            "layer": "Network",
            "list_of_services": ["AOL"],
            "name": "Test from Komand",
            "position": "top",
            "discard_other_sessions": True
        }

        test_connection.connect(connection_params)
        test_action.connection = test_connection
        with self.assertRaises(Exception):  # When the add rule call is retried it will throw an exception
            test_action.run(action_params)

        # This asserts that we've called the mock with these arguments
        # specifically, I want to make sure we're calling the discard endpoint
        mockPost.assert_any_call('https://1.1.1.2:666/web_api/discard', headers={'Content-Type': 'application/json', 'X-chkp-sid': 'fakeSID'}, json={'uid': '0892b540-5fff-4f6f-90d4-b94b15a14f09'}, verify=True)
コード例 #4
0
    def test_add_access_rule(self, mockPost):
        logger = logging.getLogger("test")
        test_connection = Connection()
        test_action = AddAccessRule()

        test_connection.logger = logger
        test_action.logger = logger

        connection_params = {
            "port": 666,
            "server": "1.1.1.1",
            "ssl_verify": False,
            "username_password": {
                "password": "******",
                "username": "******"
            }
        }

        action_params = {
            "action": "Drop",
            "layer": "Network",
            "list_of_services": ["AOL"],
            "name": "Test from Komand",
            "position": "top",
            "discard_other_sessions": False
        }

        test_connection.connect(connection_params)
        test_action.connection = test_connection
        result = test_action.run(action_params)

        expected = {'access_rule': {'uid': 'fakeUID', 'sid': 'fakeSID', 'url': 'https://1.1.1.1:666/web_api', 'session-timeout': 600, 'last-login-was-at': {'posix': 10000, 'iso-8601': '2020-02-28T10:49-0500'}, 'disk-space-message': "Partition /opt has: 716 MB of free space and it's lower than required: 2000 MB\n", 'api-server-version': '1.1'}}

        self.assertEqual(expected, result)
コード例 #5
0
    def test_integration_show_access_rulebase(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 = ShowAccessRulebase()

        test_conn.logger = log
        test_action.logger = log

        try:
            with open("../tests/show_access_rulebase.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:
            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)

        keys = results.keys()

        self.assertTrue("access_rules" in keys)

        # Assert we have some rules, the rulebase should never be empty
        self.assertTrue(len(results.get("access_rules").get("rulebase")) > 0)
コード例 #6
0
    def test_integration_add_host(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 = AddHost()

        test_conn.logger = log
        test_action.logger = log

        try:
            with open("../tests/add_host.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)

        actual = results.get("host_object")

        self.assertEquals(actual.get("name"), "192.1.2.1")
        self.assertEquals(actual.get("ipv4-address"), "192.1.2.1")
        self.assertEquals(actual.get("type"), "host")
コード例 #7
0
    def test_integration_remove_access_rule(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 = RemoveAccessRule()

        test_conn.logger = log
        test_action.logger = log

        try:
            with open("../tests/remove_access_rule.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:
            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)

        expected = {'message': 'OK', 'success': True}

        self.assertEquals(expected, results)