def test_no_change_jail(self): jail_name, arguments = TestFail2banJailModule._generate_ansible_arguments( self.jails_directory) run(arguments) success, output = run(arguments) self.assertTrue(success) self.assertFalse(output["changed"]) self._assert_matching_configuration(jail_name, arguments)
def test_change_jail_checked_mode(self): jail_name, original_arguments = TestFail2banJailModule._generate_ansible_arguments( self.jails_directory) run(original_arguments) _, new_arguments = TestFail2banJailModule._generate_ansible_arguments( self.jails_directory, name=jail_name) success, output = run(new_arguments, True) self.assertTrue(success) self.assertTrue(output["changed"]) self._assert_matching_configuration(jail_name, original_arguments)
def test_remove_existing_jail(self): jail_name, arguments = TestFail2banJailModule._generate_ansible_arguments( self.jails_directory) run(arguments) assert os.path.exists( get_config_file_path(jail_name, self.jails_directory)) arguments[PRESENT_PARAMETER] = False success, output = run(arguments) self.assertTrue(success) self.assertTrue(output["changed"]) self.assertFalse( os.path.exists( get_config_file_path(jail_name, self.jails_directory)))
def test_add_jail_without_max_retry_defined(self): jail_name, arguments = TestFail2banJailModule._generate_ansible_arguments( self.jails_directory) max_retry_parameter = AnsibleFail2BanParameter.MAX_RETRY.value[0] del arguments[max_retry_parameter] success, output = run(arguments) assert success self.assertNotIn(max_retry_parameter, arguments)
def test_add_jail_checked_mode(self): jail_name, arguments = TestFail2banJailModule._generate_ansible_arguments( self.jails_directory) success, output = run(arguments, True) self.assertTrue(success) self.assertTrue(output["changed"]) self.assertFalse( os.path.exists( get_config_file_path(jail_name, self.jails_directory)))
def test_remove_non_existing_jail(self): _, arguments = TestFail2banJailModule._generate_ansible_arguments( self.jails_directory, present=False) success, output = run(arguments) self.assertTrue(success) self.assertFalse(output["changed"])
def test_remove_non_managed_jail(self): jail_name, arguments = TestFail2banJailModule._generate_ansible_arguments( self.jails_directory) self._create_non_managed_jail(jail_name) success, output = run(arguments) self.assertFalse(success)
def test_change_non_managed_jail_with_force(self): jail_name, arguments = TestFail2banJailModule._generate_ansible_arguments( self.jails_directory, force=True) self._create_non_managed_jail(jail_name) success, output = run(arguments) self.assertTrue(success)