class LocalizationInterfaceTestCase(unittest.TestCase): """Test DBus interface for the localization module.""" def setUp(self): """Set up the localization module.""" # Set up the localization module. self.localization_module = LocalizationService() self.localization_interface = LocalizationInterface( self.localization_module) # Connect to the properties changed signal. self.callback = PropertiesChangedCallback() self.localization_interface.PropertiesChanged.connect(self.callback) def test_kickstart_properties(self): """Test kickstart properties.""" assert self.localization_interface.KickstartCommands == [ "keyboard", "lang" ] assert self.localization_interface.KickstartSections == [] assert self.localization_interface.KickstartAddons == [] self.callback.assert_not_called() def test_language_property(self): """Test the Language property.""" self.localization_interface.SetLanguage("cs_CZ.UTF-8") assert self.localization_interface.Language == "cs_CZ.UTF-8" self.callback.assert_called_once_with(LOCALIZATION.interface_name, {'Language': 'cs_CZ.UTF-8'}, []) def test_language_support_property(self): """Test the LanguageSupport property.""" self.localization_interface.SetLanguageSupport(["fr_FR"]) assert self.localization_interface.LanguageSupport == ["fr_FR"] self.callback.assert_called_once_with(LOCALIZATION.interface_name, {'LanguageSupport': ["fr_FR"]}, []) def test_vc_keymap_property(self): """Test the VirtualConsoleKeymap property.""" self.localization_interface.SetVirtualConsoleKeymap("cz") assert self.localization_interface.VirtualConsoleKeymap == "cz" self.callback.assert_called_once_with(LOCALIZATION.interface_name, {'VirtualConsoleKeymap': 'cz'}, []) def test_x_layouts_property(self): """Test the XLayouts property.""" self.localization_interface.SetXLayouts(["en", "cz(querty)"]) assert self.localization_interface.XLayouts == ["en", "cz(querty)"] self.callback.assert_called_once_with( LOCALIZATION.interface_name, {'XLayouts': ["en", "cz(querty)"]}, []) def test_switch_options_property(self): """Test the LayoutSwitchOptions property.""" self.localization_interface.SetLayoutSwitchOptions( ["grp:alt_shift_toggle"]) assert self.localization_interface.LayoutSwitchOptions == [ "grp:alt_shift_toggle" ] self.callback.assert_called_once_with( LOCALIZATION.interface_name, {'LayoutSwitchOptions': ["grp:alt_shift_toggle"]}, []) def test_keyboard_seen(self): """Test the KeyboardKickstarted property.""" assert self.localization_interface.KeyboardKickstarted == False ks_in = """ lang cs_CZ.UTF-8 """ ks_in = dedent(ks_in).strip() self.localization_interface.ReadKickstart(ks_in) assert self.localization_interface.KeyboardKickstarted == False ks_in = """ lang cs_CZ.UTF-8 keyboard cz """ ks_in = dedent(ks_in).strip() self.localization_interface.ReadKickstart(ks_in) assert self.localization_interface.KeyboardKickstarted == True def test_language_seen(self): """Test the LanguageKickstarted property.""" assert self.localization_interface.LanguageKickstarted == False ks_in = """ keyboard cz """ ks_in = dedent(ks_in).strip() self.localization_interface.ReadKickstart(ks_in) assert self.localization_interface.LanguageKickstarted == False ks_in = """ keyboard cz lang cs_CZ.UTF-8 """ ks_in = dedent(ks_in).strip() self.localization_interface.ReadKickstart(ks_in) assert self.localization_interface.LanguageKickstarted == True def test_set_language_kickstarted(self): """Test SetLanguageKickstarted.""" self.localization_interface.SetLanguageKickstarted(True) assert self.localization_interface.LanguageKickstarted == True self.callback.assert_called_once_with(LOCALIZATION.interface_name, {'LanguageKickstarted': True}, []) def test_set_keyboard_kickstarted(self): """Test SetLanguageKickstarted.""" self.localization_interface.SetKeyboardKickstarted(True) assert self.localization_interface.KeyboardKickstarted == True self.callback.assert_called_once_with(LOCALIZATION.interface_name, {'KeyboardKickstarted': True}, []) @patch("pyanaconda.modules.localization.runtime.try_to_load_keymap") def test_set_keyboard(self, mocked_load_keymap): """Test SetKeyboard.""" # Makes sure VirtualConsoleKeymap setting will be used no matter the # conf.system.can_activate_keyboard value is. mocked_load_keymap.return_value = True self.localization_interface.SetKeyboard("us") assert self.localization_interface.VirtualConsoleKeymap == "us" def test_collect_requirements(self): """Test the CollectRequirements method.""" # No default requirements. assert self.localization_interface.CollectRequirements() == [] # No additional support for ascii keyboard layouts. self.localization_interface.SetVirtualConsoleKeymap("en") assert self.localization_interface.CollectRequirements() == [] # Additional support for non-ascii keyboard layouts. self.localization_interface.SetVirtualConsoleKeymap("ru") requirements = Requirement.from_structure_list( self.localization_interface.CollectRequirements()) assert len(requirements) == 1 assert requirements[0].type == "package" assert requirements[0].name == "kbd-legacy" # "fi" keyboard layout is in kbd-legacy too (#1955793) self.localization_interface.SetVirtualConsoleKeymap("fi") requirements = Requirement.from_structure_list( self.localization_interface.CollectRequirements()) assert len(requirements) == 1 assert requirements[0].type == "package" assert requirements[0].name == "kbd-legacy" @patch_dbus_publish_object def test_install_with_task(self, publisher): """Test InstallWithTask.""" self.localization_interface.SetLanguage("cs_CZ.UTF-8") self.localization_interface.SetVirtualConsoleKeymap('us') self.localization_interface.SetXLayouts(['cz', 'cz (qwerty)']) self.localization_interface.SetLayoutSwitchOptions( ["grp:alt_shift_toggle"]) tasks = self.localization_interface.InstallWithTasks() language_installation_task_path = tasks[0] keyboard_installation_task_path = tasks[1] publisher.assert_called() object_path = publisher.call_args_list[0][0][0] obj = publisher.call_args_list[0][0][1] assert language_installation_task_path == object_path assert isinstance(obj, TaskInterface) assert isinstance(obj.implementation, LanguageInstallationTask) assert obj.implementation._lang == "cs_CZ.UTF-8" object_path = publisher.call_args_list[1][0][0] obj = publisher.call_args_list[1][0][1] assert keyboard_installation_task_path == object_path assert isinstance(obj, TaskInterface) assert isinstance(obj.implementation, KeyboardInstallationTask) assert obj.implementation._x_layouts == ['cz', 'cz (qwerty)'] assert obj.implementation._vc_keymap == 'us' assert obj.implementation._switch_options == ["grp:alt_shift_toggle"] @patch_dbus_publish_object def test_populate_missing_keyboard_configuration_with_task( self, publisher): """Test PopulateMissingKeyboardConfigurationWithTask.""" self.localization_interface.SetVirtualConsoleKeymap('us') self.localization_interface.SetXLayouts(['cz', 'cz (qwerty)']) task_path = self.localization_interface.PopulateMissingKeyboardConfigurationWithTask( ) obj = check_task_creation(task_path, publisher, GetMissingKeyboardConfigurationTask) assert obj.implementation._vc_keymap == 'us' assert obj.implementation._x_layouts == ['cz', 'cz (qwerty)'] @patch_dbus_publish_object def test_apply_keyboard_with_task(self, publisher): """Test ApplyKeyboardWithTask.""" self.localization_interface.SetVirtualConsoleKeymap('us') self.localization_interface.SetXLayouts(['cz', 'cz (qwerty)']) self.localization_interface.SetLayoutSwitchOptions( ["grp:alt_shift_toggle"]) task_path = self.localization_interface.ApplyKeyboardWithTask() obj = check_task_creation(task_path, publisher, ApplyKeyboardTask) assert obj.implementation._vc_keymap == 'us' assert obj.implementation._x_layouts == ['cz', 'cz (qwerty)'] assert obj.implementation._switch_options == ["grp:alt_shift_toggle"] def _test_kickstart(self, ks_in, ks_out): check_kickstart_interface(self.localization_interface, ks_in, ks_out) def test_no_kickstart(self): """Test with no kickstart.""" ks_in = None ks_out = "" self._test_kickstart(ks_in, ks_out) def test_kickstart_empty(self): """Test with empty string.""" ks_in = "" ks_out = "" self._test_kickstart(ks_in, ks_out) def test_lang_kickstart(self): """Test the lang command.""" ks_in = """ lang cs_CZ.UTF-8 """ ks_out = """ # System language lang cs_CZ.UTF-8 """ self._test_kickstart(ks_in, ks_out) def test_lang_kickstart2(self): """Test the lang command with added language support..""" ks_in = """ lang en_US.UTF-8 --addsupport=cs_CZ.UTF-8 """ ks_out = """ # System language lang en_US.UTF-8 --addsupport=cs_CZ.UTF-8 """ self._test_kickstart(ks_in, ks_out) def test_keyboard_kickstart1(self): """Test the keyboard command.""" ks_in = """ keyboard --vckeymap=us --xlayouts='us','cz (qwerty)' """ ks_out = """ # Keyboard layouts keyboard --vckeymap=us --xlayouts='us','cz (qwerty)' """ self._test_kickstart(ks_in, ks_out) def test_keyboard_kickstart2(self): """Test the keyboard command.""" ks_in = """ keyboard us """ ks_out = """ # Keyboard layouts keyboard --vckeymap=us """ self._test_kickstart(ks_in, ks_out) def test_keyboard_kickstart_ignore_generic_keyboard(self): """Test that keyboard argument is ignored if there is specific option.""" ks_in = """ keyboard --vckeymap cz us """ ks_out = """ # Keyboard layouts keyboard --vckeymap=cz """ self._test_kickstart(ks_in, ks_out) @patch("pyanaconda.modules.localization.runtime.conf") @patch("pyanaconda.modules.localization.runtime.try_to_load_keymap") def test_keyboard_kickstart_keyboard_assign(self, mocked_load_keymap, mocked_conf): """Test the keyboard command assignment to proper setting (running a task with try_to_load_keymap).""" mocked_conf.system.can_activate_keyboard = True mocked_load_keymap.return_value = True ks_in = """ keyboard us """ ks_out = """ # Keyboard layouts keyboard --vckeymap=us """ self._test_kickstart(ks_in, ks_out) mocked_load_keymap.return_value = False ks_in = """ keyboard us """ ks_out = """ # Keyboard layouts keyboard --xlayouts='us' """ self._test_kickstart(ks_in, ks_out) def test_keyboard_kickstart3(self): """Test the keyboard command.""" ks_in = """ keyboard --xlayouts=cz,'cz (qwerty)' --switch=grp:alt_shift_toggle """ ks_out = """ # Keyboard layouts keyboard --xlayouts='cz','cz (qwerty)' --switch='grp:alt_shift_toggle' """ self._test_kickstart(ks_in, ks_out) def test_keyboard_kickstart4(self): """Test the keyboard command.""" ks_in = """ keyboard --xlayouts='cz (qwerty)','en' en """ ks_out = """ # Keyboard layouts keyboard --xlayouts='cz (qwerty)','en' """ self._test_kickstart(ks_in, ks_out)
class TimezoneInterfaceTestCase(unittest.TestCase): """Test DBus interface for the timezone module.""" def setUp(self): """Set up the timezone module.""" # Set up the timezone module. self.timezone_module = TimezoneService() self.timezone_interface = TimezoneInterface(self.timezone_module) # Connect to the properties changed signal. self.callback = PropertiesChangedCallback() self.timezone_interface.PropertiesChanged.connect(self.callback) def _check_dbus_property(self, *args, **kwargs): check_dbus_property(self, TIMEZONE, self.timezone_interface, *args, **kwargs) def test_kickstart_properties(self): """Test kickstart properties.""" self.assertEqual(self.timezone_interface.KickstartCommands, ["timezone", "timesource"]) self.assertEqual(self.timezone_interface.KickstartSections, []) self.assertEqual(self.timezone_interface.KickstartAddons, []) self.callback.assert_not_called() def test_timezone_property(self): """Test the Timezone property.""" self.timezone_interface.SetTimezone("Europe/Prague") self.assertEqual(self.timezone_interface.Timezone, "Europe/Prague") self.callback.assert_called_once_with(TIMEZONE.interface_name, {'Timezone': 'Europe/Prague'}, []) def test_utc_property(self): """Test the IsUtc property.""" self.timezone_interface.SetIsUTC(True) self.assertEqual(self.timezone_interface.IsUTC, True) self.callback.assert_called_once_with(TIMEZONE.interface_name, {'IsUTC': True}, []) def test_ntp_property(self): """Test the NTPEnabled property.""" self.timezone_interface.SetNTPEnabled(False) self.assertEqual(self.timezone_interface.NTPEnabled, False) self.callback.assert_called_once_with(TIMEZONE.interface_name, {'NTPEnabled': False}, []) def test_time_sources_property(self): """Test the TimeSources property.""" server = { "type": get_variant(Str, TIME_SOURCE_SERVER), "hostname": get_variant(Str, "ntp.cesnet.cz"), "options": get_variant(List[Str], ["iburst"]), } pool = { "type": get_variant(Str, TIME_SOURCE_POOL), "hostname": get_variant(Str, "0.fedora.pool.ntp.org"), "options": get_variant(List[Str], []), } self._check_dbus_property("TimeSources", [server, pool]) def _test_kickstart(self, ks_in, ks_out): check_kickstart_interface(self, self.timezone_interface, ks_in, ks_out) def test_no_kickstart(self): """Test with no kickstart.""" ks_in = None ks_out = """ # System timezone timezone America/New_York """ self._test_kickstart(ks_in, ks_out) def test_kickstart_empty(self): """Test with empty string.""" ks_in = "" ks_out = "" self._test_kickstart(ks_in, ks_out) def test_kickstart(self): """Test the timezone command.""" ks_in = """ timezone Europe/Prague """ ks_out = """ # System timezone timezone Europe/Prague """ self._test_kickstart(ks_in, ks_out) def test_kickstart2(self): """Test the timezone command with flags.""" ks_in = """ timezone --utc --nontp Europe/Prague """ ks_out = """ timesource --ntp-disable # System timezone timezone Europe/Prague --utc """ self._test_kickstart(ks_in, ks_out) def test_kickstart3(self): """Test the timezone command with ntp servers.""" ks_in = """ timezone --ntpservers ntp.cesnet.cz Europe/Prague """ ks_out = """ timesource --ntp-server=ntp.cesnet.cz # System timezone timezone Europe/Prague """ self._test_kickstart(ks_in, ks_out) def test_kickstart_timesource_ntp_disabled(self): """Test the timesource command with ntp disabled.""" ks_in = """ timesource --ntp-disable """ ks_out = """ timesource --ntp-disable """ self._test_kickstart(ks_in, ks_out) def test_kickstart_timesource_ntp_server(self): """Test the timesource command with ntp servers.""" ks_in = """ timesource --ntp-server ntp.cesnet.cz """ ks_out = """ timesource --ntp-server=ntp.cesnet.cz """ self._test_kickstart(ks_in, ks_out) def test_kickstart_timesource_ntp_pool(self): """Test the timesource command with ntp pools.""" ks_in = """ timesource --ntp-pool ntp.cesnet.cz """ ks_out = """ timesource --ntp-pool=ntp.cesnet.cz """ self._test_kickstart(ks_in, ks_out) def test_kickstart_timesource_nts(self): """Test the timesource command with the nts option.""" ks_in = """ timesource --ntp-pool ntp.cesnet.cz --nts """ ks_out = """ timesource --ntp-pool=ntp.cesnet.cz --nts """ self._test_kickstart(ks_in, ks_out) def test_kickstart_timesource_all(self): """Test the timesource commands.""" ks_in = """ timesource --ntp-server ntp.cesnet.cz timesource --ntp-pool 0.fedora.pool.ntp.org """ ks_out = """ timesource --ntp-server=ntp.cesnet.cz timesource --ntp-pool=0.fedora.pool.ntp.org """ self._test_kickstart(ks_in, ks_out) def test_kickstart_timezone_timesource(self): """Test the combination of timezone and timesource commands.""" ks_in = """ timezone --ntpservers ntp.cesnet.cz,0.fedora.pool.ntp.org Europe/Prague timesource --ntp-server ntp.cesnet.cz --nts timesource --ntp-pool 0.fedora.pool.ntp.org """ ks_out = """ timesource --ntp-server=ntp.cesnet.cz timesource --ntp-server=0.fedora.pool.ntp.org timesource --ntp-server=ntp.cesnet.cz --nts timesource --ntp-pool=0.fedora.pool.ntp.org # System timezone timezone Europe/Prague """ self._test_kickstart(ks_in, ks_out) def test_collect_requirements(self): """Test the requirements of the Timezone module.""" # Check the default requirements. requirements = Requirement.from_structure_list( self.timezone_interface.CollectRequirements()) self.assertEqual(len(requirements), 1) self.assertEqual(requirements[0].type, "package") self.assertEqual(requirements[0].name, "chrony") # Check requirements with disabled NTP service. self.timezone_interface.SetNTPEnabled(False) requirements = Requirement.from_structure_list( self.timezone_interface.CollectRequirements()) self.assertEqual(len(requirements), 0) @patch_dbus_publish_object def test_install_with_tasks_default(self, publisher): """Test install tasks - module in default state.""" task_classes = [ ConfigureTimezoneTask, ConfigureNTPTask, ] task_paths = self.timezone_interface.InstallWithTasks() task_objs = check_task_creation_list(self, task_paths, publisher, task_classes) # ConfigureTimezoneTask obj = task_objs[0] self.assertEqual(obj.implementation._timezone, "America/New_York") self.assertEqual(obj.implementation._is_utc, False) # ConfigureNTPTask obj = task_objs[1] self.assertEqual(obj.implementation._ntp_enabled, True) self.assertEqual(obj.implementation._ntp_servers, []) @patch_dbus_publish_object def test_install_with_tasks_configured(self, publisher): """Test install tasks - module in configured state.""" self.timezone_interface.SetIsUTC(True) self.timezone_interface.SetTimezone("Asia/Tokyo") self.timezone_interface.SetNTPEnabled(False) # --nontp and --ntpservers are mutually exclusive in kicstart but # there is no such enforcement in the module so for testing this is ok server = TimeSourceData() server.type = TIME_SOURCE_SERVER server.hostname = "clock1.example.com" server.options = ["iburst"] pool = TimeSourceData() pool.type = TIME_SOURCE_POOL pool.hostname = "clock2.example.com" self.timezone_interface.SetTimeSources( TimeSourceData.to_structure_list([server, pool])) task_classes = [ ConfigureTimezoneTask, ConfigureNTPTask, ] task_paths = self.timezone_interface.InstallWithTasks() task_objs = check_task_creation_list(self, task_paths, publisher, task_classes) # ConfigureTimezoneTask obj = task_objs[0] self.assertEqual(obj.implementation._timezone, "Asia/Tokyo") self.assertEqual(obj.implementation._is_utc, True) # ConfigureNTPTask obj = task_objs[1] self.assertEqual(obj.implementation._ntp_enabled, False) self.assertEqual(len(obj.implementation._ntp_servers), 2) self.assertTrue( compare_data(obj.implementation._ntp_servers[0], server)) self.assertTrue(compare_data(obj.implementation._ntp_servers[1], pool)) def test_deprecated_warnings(self): response = self.timezone_interface.ReadKickstart( "timezone --isUtc Europe/Bratislava") report = KickstartReport.from_structure(response) warning = "The option --isUtc will be deprecated in future releases. " \ "Please modify your kickstart file to replace this option with " \ "its preferred alias --utc." self.assertEqual(len(report.warning_messages), 1) self.assertEqual(report.warning_messages[0].message, warning)
class UsersInterfaceTestCase(unittest.TestCase): """Test DBus interface for the users module.""" def setUp(self): """Set up the user module.""" # Set up the users module. self.users_module = UsersService() self.users_interface = UsersInterface(self.users_module) # Connect to the properties changed signal. self.callback = PropertiesChangedCallback() self.users_interface.PropertiesChanged.connect(self.callback) def test_kickstart_properties(self): """Test kickstart properties.""" assert self.users_interface.KickstartCommands == ["rootpw", "user", "group", "sshkey"] assert self.users_interface.KickstartSections == [] assert self.users_interface.KickstartAddons == [] self.callback.assert_not_called() def _check_dbus_property(self, *args, **kwargs): check_dbus_property( USERS, self.users_interface, *args, **kwargs ) def test_default_property_values(self): """Test the default user module values are as expected.""" assert self.users_interface.Users == [] assert self.users_interface.Groups == [] assert self.users_interface.SshKeys == [] assert self.users_interface.RootPassword == "" assert self.users_interface.IsRootPasswordSet is False assert self.users_interface.IsRootAccountLocked is True assert self.users_interface.IsRootPasswordCrypted is False assert self.users_interface.RootPasswordSSHLoginAllowed is False assert self.users_interface.CanChangeRootPassword is True def test_users_property(self): """Test the Users property.""" user_1 = { "name": get_variant(Str, "user1"), "uid-mode": get_variant(Str, ID_MODE_USE_VALUE), "uid": get_variant(UInt32, 123), "groups": get_variant(List[Str], ["foo", "bar"]), "gid-mode": get_variant(Str, ID_MODE_USE_VALUE), "gid": get_variant(UInt32, 321), "homedir": get_variant(Str, "user1_home"), "password": get_variant(Str, "swordfish"), "is-crypted": get_variant(Bool, False), "lock": get_variant(Bool, False), "shell": get_variant(Str, "zsh"), "gecos": get_variant(Str, "some stuff"), } user_2 = { "name": get_variant(Str, "user2"), "uid-mode": get_variant(Str, ID_MODE_USE_DEFAULT), "uid": get_variant(UInt32, 456), "groups": get_variant(List[Str], ["baz", "bar"]), "gid-mode": get_variant(Str, ID_MODE_USE_DEFAULT), "gid": get_variant(UInt32, 654), "homedir": get_variant(Str, "user2_home"), "password": get_variant(Str, "laksdjaskldjhasjhd"), "is-crypted": get_variant(Bool, True), "lock": get_variant(Bool, False), "shell": get_variant(Str, "csh"), "gecos": get_variant(Str, "some other stuff"), } self._check_dbus_property( "Users", [user_1, user_2] ) def test_groups_property(self): """Test the Groups property.""" group_1 = { "name": get_variant(Str, "group1"), "gid-mode": get_variant(Str, ID_MODE_USE_VALUE), "gid": get_variant(UInt32, 321), } group_2 = { "name": get_variant(Str, "group2"), "gid-mode": get_variant(Str, ID_MODE_USE_DEFAULT), "gid": get_variant(UInt32, 654), } self._check_dbus_property( "Groups", [group_1, group_2] ) def test_ssh_keys_property(self): """Test the SshKeys property.""" key_1 = { "key": get_variant(Str, "aaa"), "username": get_variant(Str, "user1"), } key_2 = { "key": get_variant(Str, "bbb"), "username": get_variant(Str, "user2"), } self._check_dbus_property( "SshKeys", [key_1, key_2] ) def test_set_crypted_roopw(self): """Test if setting crypted root password works correctly.""" self.users_interface.SetCryptedRootPassword("abcef") assert self.users_interface.RootPassword == "abcef" assert self.users_interface.IsRootPasswordCrypted is True assert self.users_interface.IsRootPasswordSet is True assert self.users_interface.IsRootAccountLocked is True self.callback.assert_called_once_with(USERS.interface_name, {'IsRootPasswordSet': True}, []) def test_set_crypted_roopw_and_unlock(self): """Test if setting crypted root password & unlocking it from kickstart works correctly.""" self.users_interface.SetCryptedRootPassword("abcef") assert self.users_interface.IsRootPasswordSet is True assert self.users_interface.IsRootAccountLocked is True assert self.users_interface.CanChangeRootPassword is True self.callback.assert_called_once_with(USERS.interface_name, {'IsRootPasswordSet': True}, []) # this should not be a valid admin user for interactive install assert not self.users_interface.CheckAdminUserExists() # root password is locked by default and remains locked even after a password is set # and needs to be unlocked via another DBus API call self.users_interface.SetRootAccountLocked(False) assert self.users_interface.IsRootPasswordSet is True assert self.users_interface.IsRootAccountLocked is False self.callback.assert_called_with(USERS.interface_name, {'IsRootAccountLocked': False}, []) def test_lock_root_account(self): """Test if root account can be locked via DBus correctly.""" self.users_interface.SetRootAccountLocked(True) assert self.users_interface.IsRootPasswordSet is False assert self.users_interface.IsRootAccountLocked is True self.callback.assert_called_once_with(USERS.interface_name, {'IsRootAccountLocked': True}, []) def test_clear_rootpw(self): """Test clearing of the root password.""" # set the password to something self.users_interface.SetCryptedRootPassword("abcef") assert self.users_interface.IsRootPasswordSet is True assert self.users_interface.IsRootAccountLocked is True self.callback.assert_called_once_with(USERS.interface_name, {'IsRootPasswordSet': True}, []) # clear it self.users_interface.ClearRootPassword() # check if it looks cleared assert self.users_interface.IsRootPasswordSet is False assert self.users_interface.IsRootAccountLocked is True self.callback.assert_called_with(USERS.interface_name, {'IsRootPasswordSet': False, 'IsRootAccountLocked': True}, []) def test_clear_unlocked_rootpw(self): """Test clearing of unlocked root password.""" # set the password to something self.users_interface.SetCryptedRootPassword("abcef") self.callback.assert_called_once_with(USERS.interface_name, {'IsRootPasswordSet': True}, []) self.users_interface.SetRootAccountLocked(False) self.callback.assert_called_with(USERS.interface_name, {'IsRootAccountLocked': False}, []) assert self.users_interface.IsRootPasswordSet is True assert self.users_interface.IsRootAccountLocked is False # clear it self.users_interface.ClearRootPassword() # check if it looks cleared assert self.users_interface.IsRootPasswordSet is False assert self.users_interface.IsRootAccountLocked is True self.callback.assert_called_with(USERS.interface_name, {'IsRootPasswordSet': False, 'IsRootAccountLocked': True}, []) def test_allow_root_password_ssh_login(self): """Test if root password SSH login can be allowed.""" self.users_interface.SetRootPasswordSSHLoginAllowed(True) assert self.users_interface.RootPasswordSSHLoginAllowed is True self.callback.assert_called_once_with(USERS.interface_name, {'RootPasswordSSHLoginAllowed': True}, []) self.callback.reset_mock() self.users_interface.SetRootPasswordSSHLoginAllowed(False) assert self.users_interface.RootPasswordSSHLoginAllowed is False self.callback.assert_called_once_with(USERS.interface_name, {'RootPasswordSSHLoginAllowed': False}, []) def test_admin_user_detection_1(self): """Test that admin user detection works correctly - 3 admins.""" # 2 admin users, unlocked root user1 = UserData() user1.name = "user1" user1.groups = ["foo", "wheel", "bar"] user1.lock = False user2 = UserData() user2.name = "user2" user2.groups = ["baz", "bar", "wheel"] user2.lock = False self.users_interface.SetUsers(UserData.to_structure_list([user1, user2])) self.users_interface.SetCryptedRootPassword("abc") self.users_interface.SetRootAccountLocked(False) assert self.users_interface.CheckAdminUserExists() def test_admin_user_detection_2(self): """Test that admin user detection works correctly - 0 admins (case 1).""" # 2 locked admin users, locked root user1 = UserData() user1.name = "user1" user1.groups = ["foo", "wheel", "bar"] user1.lock = True user2 = UserData() user2.name = "user2" user2.groups = ["baz", "bar", "wheel"] user2.lock = True self.users_interface.SetUsers(UserData.to_structure_list([user1, user2])) self.users_interface.SetCryptedRootPassword("abc") self.users_interface.SetRootAccountLocked(True) assert not self.users_interface.CheckAdminUserExists() def test_admin_user_detection_3(self): """Test that admin user detection works correctly - 1 admin (case 2).""" # 2 locked admin users, unlocked root user1 = UserData() user1.name = "user1" user1.groups = ["foo", "wheel", "bar"] user1.lock = True user2 = UserData() user2.name = "user2" user2.groups = ["baz", "bar", "wheel"] user2.lock = True self.users_interface.SetUsers(UserData.to_structure_list([user1, user2])) self.users_interface.SetCryptedRootPassword("abc") self.users_interface.SetRootAccountLocked(False) assert self.users_interface.CheckAdminUserExists() def test_admin_user_detection_4(self): """Test that admin user detection works correctly - 1 admin (case 3).""" # 1 locked admin user, 1 unlocked admin user, locked root user1 = UserData() user1.name = "user1" user1.groups = ["foo", "wheel", "bar"] user1.lock = False user2 = UserData() user2.name = "user2" user2.groups = ["baz", "bar", "wheel"] user2.lock = True self.users_interface.SetUsers(UserData.to_structure_list([user1, user2])) self.users_interface.SetCryptedRootPassword("abc") self.users_interface.SetRootAccountLocked(True) assert self.users_interface.CheckAdminUserExists() def test_admin_user_detection_5(self): """Test that admin user detection works correctly - 1 admin (case 4).""" # 1 user, 1 unlocked admin user, locked root user1 = UserData() user1.name = "user1" user1.groups = ["foo", "bar"] user1.lock = False user2 = UserData() user2.name = "user2" user2.groups = ["baz", "bar", "wheel"] user2.lock = False self.users_interface.SetUsers(UserData.to_structure_list([user1, user2])) self.users_interface.SetCryptedRootPassword("abc") self.users_interface.SetRootAccountLocked(True) assert self.users_interface.CheckAdminUserExists() def test_admin_user_detection_6(self): """Test that admin user detection works correctly - 1 admin (case 5).""" # 2 users, unlocked root user1 = UserData() user1.name = "user1" user1.groups = ["foo", "bar"] user1.lock = False user2 = UserData() user2.name = "user2" user2.groups = ["baz", "bar"] user2.lock = False self.users_interface.SetUsers(UserData.to_structure_list([user1, user2])) self.users_interface.SetCryptedRootPassword("abc") self.users_interface.SetRootAccountLocked(False) assert self.users_interface.CheckAdminUserExists() def _test_kickstart(self, ks_in, ks_out, ks_tmp=None): check_kickstart_interface(self.users_interface, ks_in, ks_out, ks_tmp=ks_tmp) def test_no_kickstart(self): """Test with no kickstart.""" ks_in = None ks_out = """ #Root password rootpw --lock """ self._test_kickstart(ks_in, ks_out) # root password should be empty and locked by default, but mutable assert self.users_interface.IsRootPasswordSet is False assert self.users_interface.IsRootAccountLocked is True assert self.users_interface.CanChangeRootPassword is True # this should not be considered a valid admin user for interactive install assert not self.users_interface.CheckAdminUserExists() def test_kickstart_empty(self): """Test with empty string.""" ks_in = "" ks_out = """ #Root password rootpw --lock """ self._test_kickstart(ks_in, ks_out) # password should be marked as not set, locked and mutable assert self.users_interface.IsRootPasswordSet is False assert self.users_interface.IsRootAccountLocked is True assert self.users_interface.CanChangeRootPassword is True # not a valid admin user from kickstart PoV assert not self.users_interface.CheckAdminUserExists() def test_kickstart_set_rootpw(self): """Test the setting root password via kickstart.""" ks_in = """ rootpw abcdef """ ks_out = """ # Root password rootpw --plaintext abcdef """ self._test_kickstart(ks_in, ks_out) # if rootpw shows up in the kickstart is should be reported as immutable assert self.users_interface.IsRootPasswordSet is True assert self.users_interface.IsRootAccountLocked is False assert self.users_interface.CanChangeRootPassword is False # but this should still be a valid admin user from kickstart PoV assert self.users_interface.CheckAdminUserExists() def test_kickstart_set_plain_rootpw(self): """Test the setting plaintext root password via kickstart.""" ks_in = """ rootpw --plaintext abcdef """ ks_out = """ # Root password rootpw --plaintext abcdef """ self._test_kickstart(ks_in, ks_out) def test_kickstart_set_crypted_rootpw(self): """Test the setting crypted root password via kickstart.""" ks_in = """ rootpw --iscrypted abcdef """ ks_out = """ # Root password rootpw --iscrypted abcdef """ self._test_kickstart(ks_in, ks_out) assert self.users_interface.IsRootPasswordSet is True assert self.users_interface.IsRootAccountLocked is False def test_kickstart_lock_root_account(self): """Test locking the root account via kickstart.""" ks_in = """ rootpw --lock """ ks_out = """ #Root password rootpw --lock """ self._test_kickstart(ks_in, ks_out) # password should be marked as not set, locked and immutable assert self.users_interface.IsRootPasswordSet is False assert self.users_interface.IsRootAccountLocked is True assert self.users_interface.CanChangeRootPassword is False # but this should still be a valid admin user from kickstart PoV assert self.users_interface.CheckAdminUserExists() def test_kickstart_lock_root_account_with_password(self): """Test locking the root account with a password via kickstart.""" ks_in = """ rootpw abcdef --lock """ ks_out = """ # Root password rootpw --lock --plaintext abcdef """ self._test_kickstart(ks_in, ks_out) # password should be marked as set, locked and immutable assert self.users_interface.IsRootPasswordSet is True assert self.users_interface.IsRootAccountLocked is True assert self.users_interface.CanChangeRootPassword is False # but this should still be a valid admin user from kickstart PoV assert self.users_interface.CheckAdminUserExists() def test_kickstart_user(self): """Test kickstart user input and output.""" ks_in = """ user --name=user1 --password=abcedf """ ks_out = """ #Root password rootpw --lock user --name=user1 --password=abcedf """ self._test_kickstart(ks_in, ks_out) # password should be marked as not set, locked and mutable assert self.users_interface.IsRootPasswordSet is False assert self.users_interface.IsRootAccountLocked is True assert self.users_interface.CanChangeRootPassword is True # no a valid admin user exists from kickstart PoV assert not self.users_interface.CheckAdminUserExists() def test_kickstart_user_admin(self): """Test kickstart admin user input and output.""" ks_in = """ user --groups=wheel --name=user1 --password=abcedf """ ks_out = """ #Root password rootpw --lock user --groups=wheel --name=user1 --password=abcedf """ self._test_kickstart(ks_in, ks_out) # password should be marked as not set, locked and mutable assert self.users_interface.IsRootPasswordSet is False assert self.users_interface.IsRootAccountLocked is True assert self.users_interface.CanChangeRootPassword is True # provides a valid admin user exists from kickstart PoV assert self.users_interface.CheckAdminUserExists() def test_kickstart_users(self): """Test kickstart users input and output.""" ks_in = """ user --name=user1 --homedir=user1_home --password=foo --shell=ksh --uid=123 --gecos=baz --gid=345 --groups=a,b,c,d --plaintext user --name=user2 --homedir=user2_home --password=asasas --shell=csh --uid=321 --gecos=bar --gid=543 --groups=wheel,mockuser --iscrypted user --name=user3 --lock """ ks_out = """ #Root password rootpw --lock user --groups=a,b,c,d --homedir=user1_home --name=user1 --password=foo --shell=ksh --uid=123 --gecos="baz" --gid=345 user --groups=wheel,mockuser --homedir=user2_home --name=user2 --password=asasas --iscrypted --shell=csh --uid=321 --gecos="bar" --gid=543 user --name=user3 --lock """ self._test_kickstart(ks_in, ks_out) def test_kickstart_groups(self): """Test kickstart groups input and output.""" ks_in = """ group --name=group1 --gid=321 group --name=group2 --gid=654 group --name=group3 """ ks_out = """ group --name=group1 --gid=321 group --name=group2 --gid=654 group --name=group3 #Root password rootpw --lock """ self._test_kickstart(ks_in, ks_out) def test_kickstart_ssh_keys(self): """Test kickstart ssh keys input and output.""" ks_in = """ sshkey --username=user1 "aaa" sshkey --username=user2 "bbb" sshkey --username=user3 "ccc" """ ks_out = """ #Root password rootpw --lock sshkey --username=user1 "aaa" sshkey --username=user2 "bbb" sshkey --username=user3 "ccc" """ self._test_kickstart(ks_in, ks_out) @patch_dbus_publish_object def test_install_with_tasks(self, publisher): """Test InstallWithTasks.""" task_classes = [ CreateGroupsTask, CreateUsersTask, SetRootPasswordTask, SetSshKeysTask, ConfigureRootPasswordSSHLoginTask ] task_paths = self.users_interface.InstallWithTasks() check_task_creation_list(task_paths, publisher, task_classes) @patch_dbus_publish_object def test_configure_groups_with_task(self, publisher): """Test ConfigureGroupsWithTask.""" task_path = self.users_interface.ConfigureGroupsWithTask() check_task_creation(task_path, publisher, CreateGroupsTask) @patch_dbus_publish_object def test_configure_users_with_task(self, publisher): """Test ConfigureUsersWithTask.""" task_path = self.users_interface.ConfigureUsersWithTask() check_task_creation(task_path, publisher, CreateUsersTask) @patch_dbus_publish_object def test_set_root_password_with_task(self, publisher): """Test SetRootPasswordWithTask.""" task_path = self.users_interface.SetRootPasswordWithTask() check_task_creation(task_path, publisher, SetRootPasswordTask)
class SecurityInterfaceTestCase(unittest.TestCase): """Test DBus interface for the Security module.""" def setUp(self): """Set up the security module.""" # Set up the security module. self.security_module = SecurityService() self.security_interface = SecurityInterface(self.security_module) # Connect to the properties changed signal. self.callback = PropertiesChangedCallback() self.security_interface.PropertiesChanged.connect(self.callback) def _check_dbus_property(self, *args, **kwargs): check_dbus_property(SECURITY, self.security_interface, *args, **kwargs) def test_kickstart_properties(self): """Test kickstart properties.""" assert self.security_interface.KickstartCommands == \ ["authselect", "selinux", "realm"] assert self.security_interface.KickstartSections == [] assert self.security_interface.KickstartAddons == [] self.callback.assert_not_called() def test_selinux_property(self): """Test the selinux property.""" self._check_dbus_property("SELinux", SELINUX_ENFORCING) def test_authselect_property(self): """Test the authselect property.""" self._check_dbus_property("Authselect", ["sssd", "with-mkhomedir"]) def test_fingerprint_auth_enabled(self): """Test the fingerprint_auth_enabled property.""" self._check_dbus_property("FingerprintAuthEnabled", True) def test_realm_property(self): """Test the realm property.""" realm = { "name": get_variant(Str, "domain.example.com"), "discover-options": get_variant(List[Str], ["--client-software=sssd"]), "join-options": get_variant(List[Str], ["--one-time-password=password"]), "discovered": get_variant(Bool, True), "required-packages": get_variant(List[Str], []) } self._check_dbus_property("Realm", realm) def _test_kickstart(self, ks_in, ks_out): check_kickstart_interface(self.security_interface, ks_in, ks_out) def test_no_kickstart(self): """Test with no kickstart.""" ks_in = None ks_out = "" self._test_kickstart(ks_in, ks_out) def test_kickstart_empty(self): """Test with empty string.""" ks_in = "" ks_out = "" self._test_kickstart(ks_in, ks_out) def test_selinux_kickstart(self): """Test the selinux command.""" ks_in = """ selinux --permissive """ ks_out = """ # SELinux configuration selinux --permissive """ self._test_kickstart(ks_in, ks_out) def test_authselect_kickstart(self): """Test the authselect command.""" ks_in = """ authselect select sssd with-mkhomedir """ ks_out = """ # System authorization information authselect select sssd with-mkhomedir """ self._test_kickstart(ks_in, ks_out) def test_realm_kickstart(self): """Test the realm command.""" ks_in = """ realm join --one-time-password=password --client-software=sssd domain.example.com """ ks_out = """ # Realm or domain membership realm join --one-time-password=password --client-software=sssd domain.example.com """ self._test_kickstart(ks_in, ks_out) @patch_dbus_publish_object def test_realm_discover_default(self, publisher): """Test module in default state with realm discover task.""" realm_discover_task_path = self.security_interface.DiscoverRealmWithTask( ) obj = check_task_creation(realm_discover_task_path, publisher, RealmDiscoverTask) assert obj.implementation._realm_data.name == "" assert obj.implementation._realm_data.discover_options == [] @patch_dbus_publish_object def test_realm_discover_configured(self, publisher): """Test module in configured state with realm discover task.""" realm = RealmData() realm.name = "domain.example.com" realm.discover_options = ["--client-software=sssd"] self.security_interface.SetRealm(RealmData.to_structure(realm)) realm_discover_task_path = self.security_interface.DiscoverRealmWithTask( ) obj = check_task_creation(realm_discover_task_path, publisher, RealmDiscoverTask) assert obj.implementation._realm_data.name == "domain.example.com" assert obj.implementation._realm_data.discover_options == [ "--client-software=sssd" ] @patch_dbus_publish_object def test_install_with_tasks_default(self, publisher): """Test InstallWithTasks.""" task_classes = [ ConfigureSELinuxTask, ConfigureFingerprintAuthTask, ConfigureAuthselectTask, ] task_paths = self.security_interface.InstallWithTasks() task_objs = check_task_creation_list(task_paths, publisher, task_classes) # ConfigureSELinuxTask obj = task_objs[0] assert obj.implementation._selinux_mode == SELinuxMode.DEFAULT # ConfigureFingerprintAuthTask obj = task_objs[1] assert obj.implementation._fingerprint_auth_enabled is False # ConfigureAuthselectTask obj = task_objs[2] assert obj.implementation._authselect_options == [] @patch_dbus_publish_object def test_realm_join_default(self, publisher): """Test module in default state with realm join task.""" realm_join_task_path = self.security_interface.JoinRealmWithTask() obj = check_task_creation(realm_join_task_path, publisher, RealmJoinTask) assert obj.implementation._realm_data.discovered is False assert obj.implementation._realm_data.name == "" assert obj.implementation._realm_data.join_options == [] @patch_dbus_publish_object def test_install_with_tasks_configured(self, publisher): """Test install tasks - module in configured state.""" realm = RealmData() realm.name = "domain.example.com" realm.discover_options = ["--client-software=sssd"] realm.join_options = ["--one-time-password=password"] realm.discovered = True authselect = ['select', 'sssd'] fingerprint = True self.security_interface.SetRealm(RealmData.to_structure(realm)) self.security_interface.SetSELinux(SELINUX_PERMISSIVE) self.security_interface.SetAuthselect(authselect) self.security_interface.SetFingerprintAuthEnabled(fingerprint) task_classes = [ ConfigureSELinuxTask, ConfigureFingerprintAuthTask, ConfigureAuthselectTask, ] task_paths = self.security_interface.InstallWithTasks() task_objs = check_task_creation_list(task_paths, publisher, task_classes) # ConfigureSELinuxTask obj = task_objs[0] assert obj.implementation._selinux_mode == SELinuxMode.PERMISSIVE # ConfigureFingerprintAuthTask obj = task_objs[1] assert obj.implementation._fingerprint_auth_enabled == fingerprint # ConfigureAuthselectTask obj = task_objs[2] assert obj.implementation._authselect_options == authselect @patch_dbus_publish_object def test_realm_join_configured(self, publisher): """Test module in configured state with realm join task.""" realm = RealmData() realm.name = "domain.example.com" realm.discover_options = ["--client-software=sssd"] realm.join_options = ["--one-time-password=password"] realm.discovered = True self.security_interface.SetRealm(RealmData.to_structure(realm)) realm_join_task_path = self.security_interface.JoinRealmWithTask() obj = check_task_creation(realm_join_task_path, publisher, RealmJoinTask) assert obj.implementation._realm_data.discovered is True assert obj.implementation._realm_data.name == "domain.example.com" assert obj.implementation._realm_data.join_options == [ "--one-time-password=password" ] @patch_dbus_publish_object def test_realm_data_propagation(self, publisher): """Test that realm data changes propagate to realm join task.""" # We connect to the realm_changed signal and update the realm data holder # in the realm join task when the signal is triggered. realm1 = RealmData() realm1.name = "domain.example.com" realm1.discover_options = ["--client-software=sssd"] realm1.discovered = False self.security_interface.SetRealm(RealmData.to_structure(realm1)) realm_join_task_path = self.security_interface.JoinRealmWithTask() # realm join - after task creation obj = check_task_creation(realm_join_task_path, publisher, RealmJoinTask) assert obj.implementation._realm_data.discovered is False assert obj.implementation._realm_data.name == "domain.example.com" assert obj.implementation._realm_data.join_options == [] # change realm data and check the changes propagate to the realm join task realm2 = RealmData() realm2.name = "domain.example.com" realm2.discover_options = ["--client-software=sssd"] realm2.join_options = ["--one-time-password=password"] realm2.discovered = True self.security_interface.SetRealm(RealmData.to_structure(realm2)) # realm join - after realm data update assert obj.implementation._realm_data.discovered is True assert obj.implementation._realm_data.name == "domain.example.com" assert obj.implementation._realm_data.join_options == [ "--one-time-password=password" ] @patch_dbus_publish_object def test_preconfigure_fips_with_task(self, publisher): """Test the PreconfigureFIPSWithTask method.""" task_path = self.security_interface.PreconfigureFIPSWithTask( PAYLOAD_TYPE_DNF) obj = check_task_creation(task_path, publisher, PreconfigureFIPSTask) assert obj.implementation._sysroot == "/mnt/sysroot" assert obj.implementation._payload_type == PAYLOAD_TYPE_DNF assert obj.implementation._fips_enabled is False @patch_dbus_publish_object def test_configure_fips_with_task(self, publisher): """Test the ConfigureFIPSWithTask method.""" task_path = self.security_interface.ConfigureFIPSWithTask() obj = check_task_creation(task_path, publisher, ConfigureFIPSTask) assert obj.implementation._sysroot == "/mnt/sysroot" assert obj.implementation._fips_enabled is False def test_collect_requirements_default(self): """Test requrements are empty by default.""" reqs = self.security_interface.CollectRequirements() assert reqs == [] @patch("pyanaconda.modules.security.security.kernel_arguments") def test_fips_requirements(self, kernel_arguments_mock): """Test the package requirements for fips.""" kernel_arguments_mock.is_enabled.return_value = True assert self.security_interface.CollectRequirements() == [{ "type": get_variant(Str, "package"), "name": get_variant(Str, "/usr/bin/fips-mode-setup"), "reason": get_variant(Str, "Required for FIPS compliance.") }] kernel_arguments_mock.is_enabled.assert_called_once_with("fips") def test_realmd_requirements(self): """Test that package requirements in realm data propagate correctly.""" realm = RealmData() realm.name = "domain.example.com" realm.discover_options = ["--client-software=sssd"] realm.join_options = ["--one-time-password=password"] realm.discovered = True realm.required_packages = ["realmd", "foo", "bar"] self.security_interface.SetRealm(RealmData.to_structure(realm)) # check that the teamd package is requested assert self.security_interface.CollectRequirements() == [{ "type": get_variant(Str, "package"), "name": get_variant(Str, "realmd"), "reason": get_variant(Str, "Needed to join a realm.") }, { "type": get_variant(Str, "package"), "name": get_variant(Str, "foo"), "reason": get_variant(Str, "Needed to join a realm.") }, { "type": get_variant(Str, "package"), "name": get_variant(Str, "bar"), "reason": get_variant(Str, "Needed to join a realm.") }] def test_authselect_requirements(self): """Test that package requirements for authselect propagate correctly.""" self.security_interface.SetAuthselect(['select', 'sssd']) requirements = Requirement.from_structure_list( self.security_interface.CollectRequirements()) assert len(requirements) == 1 assert requirements[0].type == "package" assert requirements[0].name == "authselect" self.security_interface.SetAuthselect([]) self.security_interface.SetFingerprintAuthEnabled(True) requirements = Requirement.from_structure_list( self.security_interface.CollectRequirements()) assert len(requirements) == 1 assert requirements[0].type == "package" assert requirements[0].name == "authselect"
class ServicesInterfaceTestCase(unittest.TestCase): """Test DBus interface for the services module.""" def setUp(self): """Set up the services module.""" # Set up the services module. self.services_module = ServicesService() self.services_interface = ServicesInterface(self.services_module) # Connect to the properties changed signal. self.callback = PropertiesChangedCallback() self.services_interface.PropertiesChanged.connect(self.callback) def test_kickstart_properties(self): """Test kickstart properties.""" assert self.services_interface.KickstartCommands == ["firstboot", "services", "skipx", "xconfig"] assert self.services_interface.KickstartSections == [] assert self.services_interface.KickstartAddons == [] self.callback.assert_not_called() def test_enabled_services_property(self): """Test the enabled services property.""" self.services_interface.SetEnabledServices(["a", "b", "c"]) assert self.services_interface.EnabledServices == ["a", "b", "c"] self.callback.assert_called_once_with( SERVICES.interface_name, {'EnabledServices': ["a", "b", "c"]}, [] ) def test_disabled_services_property(self): """Test the disabled services property.""" self.services_interface.SetDisabledServices(["a", "b", "c"]) assert self.services_interface.DisabledServices == ["a", "b", "c"] self.callback.assert_called_once_with( SERVICES.interface_name, {'DisabledServices': ["a", "b", "c"]}, [] ) def test_default_target_property_default_graphical(self): """Test the default target property - default value.""" self.callback.assert_not_called() assert self.services_interface.DefaultTarget == "" def test_default_target_property_graphical(self): """Test the default target property - set graphical target.""" self.services_interface.SetDefaultTarget(GRAPHICAL_TARGET) assert self.services_interface.DefaultTarget == GRAPHICAL_TARGET self.callback.assert_called_once_with( SERVICES.interface_name, {'DefaultTarget': GRAPHICAL_TARGET}, [] ) def test_default_target_property_text(self): """Test the default target property - set text target.""" self.services_interface.SetDefaultTarget(TEXT_ONLY_TARGET) assert self.services_interface.DefaultTarget == TEXT_ONLY_TARGET self.callback.assert_called_once_with( SERVICES.interface_name, {'DefaultTarget': TEXT_ONLY_TARGET}, [] ) def test_default_desktop_property(self): """Test the default desktop property.""" self.services_interface.SetDefaultDesktop("KDE") assert self.services_interface.DefaultDesktop == "KDE" self.callback.assert_called_once_with( SERVICES.interface_name, {'DefaultDesktop': "KDE"}, [] ) def test_setup_on_boot_property(self): """Test the setup on boot property.""" self.services_interface.SetSetupOnBoot(SETUP_ON_BOOT_DISABLED) assert self.services_interface.SetupOnBoot == SETUP_ON_BOOT_DISABLED self.callback.assert_called_once_with( SERVICES.interface_name, {'SetupOnBoot': SETUP_ON_BOOT_DISABLED}, [] ) def test_post_install_tools_disabled(self): """Test the post-install-tools-enabled property.""" # should not be marked as disabled by default assert self.services_interface.PostInstallToolsEnabled is True # mark as disabled self.services_interface.SetPostInstallToolsEnabled(False) assert self.services_interface.PostInstallToolsEnabled is False self.callback.assert_called_once_with( SERVICES.interface_name, {'PostInstallToolsEnabled': False}, [] ) # mark as not disabled again self.services_interface.SetPostInstallToolsEnabled(True) assert self.services_interface.PostInstallToolsEnabled is True self.callback.assert_called_with( SERVICES.interface_name, {'PostInstallToolsEnabled': True}, [] ) def _test_kickstart(self, ks_in, ks_out): check_kickstart_interface(self.services_interface, ks_in, ks_out) def test_no_kickstart(self): """Test with no kickstart.""" ks_in = None ks_out = "" self._test_kickstart(ks_in, ks_out) assert self.services_interface.SetupOnBoot == SETUP_ON_BOOT_DEFAULT assert self.services_interface.PostInstallToolsEnabled is True def test_kickstart_empty(self): """Test with empty string.""" ks_in = "" ks_out = "" self._test_kickstart(ks_in, ks_out) assert self.services_interface.SetupOnBoot == SETUP_ON_BOOT_DEFAULT assert self.services_interface.PostInstallToolsEnabled is True def test_services_kickstart(self): """Test the services command.""" ks_in = """ services --disabled=a,b,c --enabled=d,e,f """ ks_out = """ # System services services --disabled="a,b,c" --enabled="d,e,f" """ self._test_kickstart(ks_in, ks_out) def test_skipx_kickstart(self): """Test the skipx command.""" ks_in = """ skipx """ ks_out = """ # Do not configure the X Window System skipx """ self._test_kickstart(ks_in, ks_out) def test_xconfig_kickstart(self): """Test the xconfig command.""" ks_in = """ xconfig --defaultdesktop GNOME --startxonboot """ ks_out = """ # X Window System configuration information xconfig --defaultdesktop=GNOME --startxonboot """ self._test_kickstart(ks_in, ks_out) def test_firstboot_disabled_kickstart(self): """Test the firstboot command - disabled.""" ks_in = """ firstboot --disable """ ks_out = """ firstboot --disable """ self._test_kickstart(ks_in, ks_out) assert self.services_interface.SetupOnBoot == SETUP_ON_BOOT_DISABLED assert self.services_interface.PostInstallToolsEnabled is False def test_firstboot_enabled_kickstart(self): """Test the firstboot command - enabled.""" ks_in = """ firstboot --enable """ ks_out = """ # Run the Setup Agent on first boot firstboot --enable """ self._test_kickstart(ks_in, ks_out) assert self.services_interface.SetupOnBoot == SETUP_ON_BOOT_ENABLED assert self.services_interface.PostInstallToolsEnabled is True def test_firstboot_reconfig_kickstart(self): """Test the firstboot command - reconfig.""" ks_in = """ firstboot --reconfig """ ks_out = """ # Run the Setup Agent on first boot firstboot --reconfig """ self._test_kickstart(ks_in, ks_out) assert self.services_interface.SetupOnBoot == SETUP_ON_BOOT_RECONFIG assert self.services_interface.PostInstallToolsEnabled is True