2222import unittest
2323from contextlib import contextmanager
2424from textwrap import dedent
25+ from types import SimpleNamespace
2526from unittest .mock import patch
2627
2728import pytest
3637from pyanaconda .modules .common .structures .requirement import Requirement
3738from pyanaconda .modules .security .constants import SELinuxMode
3839from pyanaconda .modules .security .installation import (
40+ AUTHSELECT_ARGS ,
3941 AUTHSELECT_TOOL_PATH ,
4042 PAM_SO_64_PATH ,
4143 PAM_SO_PATH ,
@@ -159,6 +161,22 @@ def test_authselect_kickstart(self):
159161 """
160162 self ._test_kickstart (ks_in , ks_out )
161163
164+ def test_kickstart_contains_authselect_when_module_property_is_set (self ):
165+ self .security_interface .Authselect = [
166+ "select" ,
167+ "sssd" ,
168+ "with-fingerprint" ,
169+ "with-silent-lastlog" ,
170+ "--force" ,
171+ ]
172+
173+ ks_in = ""
174+ ks_out = """
175+ # System authorization information
176+ authselect select sssd with-fingerprint with-silent-lastlog --force
177+ """
178+ self ._test_kickstart (ks_in , ks_out )
179+
162180 def test_realm_kickstart (self ):
163181 """Test the realm command."""
164182 ks_in = """
@@ -232,17 +250,6 @@ def test_certificates_kickstart(self):
232250 """
233251 self ._test_kickstart (ks_in , ks_out )
234252
235- def test_kickstart_authselect_merges_with_fingerprint (self ):
236- self .security_interface .FingerprintAuthEnabled = True
237-
238- ks_in = ""
239- ks_out = """
240- # System authorization information
241- authselect enable-feature with-fingerprint
242- """
243-
244- self ._test_kickstart (ks_in , ks_out )
245-
246253 @patch_dbus_publish_object
247254 def test_realm_discover_default (self , publisher ):
248255 """Test module in default state with realm discover task."""
@@ -270,21 +277,13 @@ def test_install_with_tasks_default(self, publisher):
270277 """Test InstallWithTasks."""
271278 task_classes = [
272279 ConfigureSELinuxTask ,
273- ConfigureFingerprintAuthTask ,
274- ConfigureAuthselectTask ,
275280 ]
276281 task_paths = self .security_interface .InstallWithTasks ()
277282 task_objs = check_task_creation_list (task_paths , publisher , task_classes )
278283
279284 # ConfigureSELinuxTask
280285 obj = task_objs [0 ]
281286 assert obj .implementation ._selinux_mode == SELinuxMode .DEFAULT
282- # ConfigureFingerprintAuthTask
283- obj = task_objs [1 ]
284- assert obj .implementation ._fingerprint_auth_enabled is False
285- # ConfigureAuthselectTask
286- obj = task_objs [2 ]
287- assert obj .implementation ._authselect_options == []
288287
289288 @patch_dbus_publish_object
290289 def test_realm_join_default (self , publisher ):
@@ -312,9 +311,9 @@ def test_install_with_tasks_configured(self, publisher):
312311 self .security_interface .Authselect = authselect
313312 self .security_interface .FingerprintAuthEnabled = fingerprint
314313
314+ # We have ks args => no fingerprint task
315315 task_classes = [
316316 ConfigureSELinuxTask ,
317- ConfigureFingerprintAuthTask ,
318317 ConfigureAuthselectTask ,
319318 ]
320319 task_paths = self .security_interface .InstallWithTasks ()
@@ -323,13 +322,30 @@ def test_install_with_tasks_configured(self, publisher):
323322 # ConfigureSELinuxTask
324323 obj = task_objs [0 ]
325324 assert obj .implementation ._selinux_mode == SELinuxMode .PERMISSIVE
326- # ConfigureFingerprintAuthTask
327- obj = task_objs [1 ]
328- assert obj .implementation ._fingerprint_auth_enabled == fingerprint
329325 # ConfigureAuthselectTask
330- obj = task_objs [2 ]
326+ obj = task_objs [1 ]
331327 assert obj .implementation ._authselect_options == authselect
332328
329+ @patch_dbus_publish_object
330+ def test_install_with_tasks_fingerprint_only (self , publisher ):
331+ """When fingerprint is enabled and KS authselect is empty, enqueue fingerprint task."""
332+ self .security_interface .FingerprintAuthEnabled = True
333+ self .security_interface .Authselect = []
334+
335+ task_classes = [
336+ ConfigureSELinuxTask ,
337+ ConfigureFingerprintAuthTask ,
338+ ]
339+ task_paths = self .security_interface .InstallWithTasks ()
340+ task_objs = check_task_creation_list (task_paths , publisher , task_classes )
341+
342+ # ConfigureSELinuxTask
343+ obj = task_objs [0 ]
344+ assert obj .implementation ._selinux_mode == SELinuxMode .DEFAULT
345+ # ConfigureFingerprintAuthTask
346+ obj = task_objs [1 ]
347+ assert obj .implementation ._fingerprint_auth_enabled is True
348+
333349 @patch_dbus_publish_object
334350 def test_realm_join_configured (self , publisher ):
335351 """Test module in configured state with realm join task."""
@@ -888,9 +904,12 @@ def test_realm_join_not_discovered(self, execWithRedirect):
888904 # check if the realm command invocation looks right
889905 execWithRedirect .assert_not_called ()
890906
891- @patch ('pyanaconda.core.util.execWithRedirect' )
892- def test_configure_fingerprint_auth_task (self , execWithRedirect ):
893- """Test the configure fingerprint task."""
907+ @patch ("pyanaconda.modules.security.installation.SECURITY.get_proxy" )
908+ @patch ("pyanaconda.core.util.execWithRedirect" )
909+ def test_configure_fingerprint_auth_task (self , execWithRedirect , get_proxy ):
910+ proxy = SimpleNamespace (Authselect = [])
911+ get_proxy .return_value = proxy
912+
894913 with tempfile .TemporaryDirectory () as sysroot :
895914
896915 authselect_dir = os .path .normpath (sysroot + os .path .dirname (AUTHSELECT_TOOL_PATH ))
@@ -925,6 +944,7 @@ def test_configure_fingerprint_auth_task(self, execWithRedirect):
925944
926945 # Authselect command and pam library are there
927946 execWithRedirect .reset_mock ()
947+ proxy .Authselect = []
928948 os .mknod (pam_so_path )
929949 os .mknod (authselect_path )
930950 task = ConfigureFingerprintAuthTask (
@@ -934,14 +954,16 @@ def test_configure_fingerprint_auth_task(self, execWithRedirect):
934954 task .run ()
935955 execWithRedirect .assert_called_once_with (
936956 AUTHSELECT_TOOL_PATH ,
937- [ "enable-feature" , "with-fingerprint" ] ,
957+ AUTHSELECT_ARGS ,
938958 root = sysroot
939959 )
960+ assert proxy .Authselect == AUTHSELECT_ARGS
940961 os .remove (pam_so_path )
941962 os .remove (authselect_path )
942963
943964 # Authselect command and pam library are there
944965 execWithRedirect .reset_mock ()
966+ proxy .Authselect = []
945967 os .mknod (pam_so_64_path )
946968 os .mknod (authselect_path )
947969 task = ConfigureFingerprintAuthTask (
@@ -951,9 +973,10 @@ def test_configure_fingerprint_auth_task(self, execWithRedirect):
951973 task .run ()
952974 execWithRedirect .assert_called_once_with (
953975 AUTHSELECT_TOOL_PATH ,
954- [ "enable-feature" , "with-fingerprint" ] ,
976+ AUTHSELECT_ARGS ,
955977 root = sysroot
956978 )
979+ assert proxy .Authselect == AUTHSELECT_ARGS
957980 os .remove (pam_so_64_path )
958981 os .remove (authselect_path )
959982
0 commit comments