@@ -780,16 +780,22 @@ def test_find_fit_images_with_boot_kernel(self, mock_get_boot_kernel):
780
780
"._get_boot_kernel_path"
781
781
)
782
782
@patch (
783
- "check_secure_boot_state.FITImageSecureBootChecker"
784
- "._get_snap_kernel_patterns"
783
+ (
784
+ "check_secure_boot_state.FITImageSecureBootChecker."
785
+ "_get_snap_kernel_patterns"
786
+ )
785
787
)
786
788
@patch (
787
- "check_secure_boot_state.FITImageSecureBootChecker"
788
- "._build_search_patterns"
789
+ (
790
+ "check_secure_boot_state.FITImageSecureBootChecker."
791
+ "_build_search_patterns"
792
+ )
789
793
)
790
794
@patch (
791
- "check_secure_boot_state.FITImageSecureBootChecker"
792
- "._find_files_by_patterns"
795
+ (
796
+ "check_secure_boot_state.FITImageSecureBootChecker."
797
+ "_find_files_by_patterns"
798
+ )
793
799
)
794
800
def test_find_fit_images_core_variant (
795
801
self ,
@@ -809,26 +815,28 @@ def test_find_fit_images_core_variant(
809
815
images = self .checker ._find_fit_images ()
810
816
811
817
self .assertEqual (images , ["/snap/test/current/kernel.img" ])
812
- mock_get_patterns .assert_called_once ()
813
- mock_build_patterns .assert_called_once_with (
814
- ["/snap/*/current/kernel.img" ]
815
- )
818
+ patterns = ["/snap/*/current/kernel.img" ]
819
+ mock_build_patterns .assert_called_once_with (patterns )
816
820
817
821
@patch (
818
822
"check_secure_boot_state.FITImageSecureBootChecker"
819
823
"._get_boot_kernel_path"
820
824
)
821
825
@patch (
822
- "check_secure_boot_state.FITImageSecureBootChecker"
823
- ". _get_classic_fit_patterns"
826
+ "check_secure_boot_state.FITImageSecureBootChecker. "
827
+ "_get_classic_fit_patterns"
824
828
)
825
829
@patch (
826
- "check_secure_boot_state.FITImageSecureBootChecker"
827
- "._build_search_patterns"
830
+ (
831
+ "check_secure_boot_state.FITImageSecureBootChecker."
832
+ "_build_search_patterns"
833
+ )
828
834
)
829
835
@patch (
830
- "check_secure_boot_state.FITImageSecureBootChecker"
831
- "._find_files_by_patterns"
836
+ (
837
+ "check_secure_boot_state.FITImageSecureBootChecker."
838
+ "_find_files_by_patterns"
839
+ )
832
840
)
833
841
def test_find_fit_images_classic_variant (
834
842
self ,
@@ -848,20 +856,32 @@ def test_find_fit_images_classic_variant(
848
856
images = self .checker ._find_fit_images ()
849
857
850
858
self .assertEqual (images , ["/boot/vmlinuz-5.4.0" ])
851
- mock_get_patterns . assert_called_once ()
852
- mock_build_patterns .assert_called_once_with ([ "/boot/*.img" ] )
859
+ patterns = [ "/boot/*.img" ]
860
+ mock_build_patterns .assert_called_once_with (patterns )
853
861
854
862
@patch (
855
- "check_secure_boot_state.FITImageSecureBootChecker._get_boot_kernel_path"
863
+ (
864
+ "check_secure_boot_state.FITImageSecureBootChecker."
865
+ "_get_boot_kernel_path"
866
+ )
856
867
)
857
868
@patch (
858
- "check_secure_boot_state.FITImageSecureBootChecker._get_snap_kernel_patterns"
869
+ (
870
+ "check_secure_boot_state.FITImageSecureBootChecker."
871
+ "_get_snap_kernel_patterns"
872
+ )
859
873
)
860
874
@patch (
861
- "check_secure_boot_state.FITImageSecureBootChecker._build_search_patterns"
875
+ (
876
+ "check_secure_boot_state.FITImageSecureBootChecker."
877
+ "_build_search_patterns"
878
+ )
862
879
)
863
880
@patch (
864
- "check_secure_boot_state.FITImageSecureBootChecker._find_files_by_patterns"
881
+ (
882
+ "check_secure_boot_state.FITImageSecureBootChecker."
883
+ "_find_files_by_patterns"
884
+ )
865
885
)
866
886
def test_find_fit_images_no_images_found (
867
887
self ,
@@ -883,16 +903,28 @@ def test_find_fit_images_no_images_found(
883
903
self .assertEqual (images , [])
884
904
885
905
@patch (
886
- "check_secure_boot_state.FITImageSecureBootChecker._get_boot_kernel_path"
906
+ (
907
+ "check_secure_boot_state.FITImageSecureBootChecker."
908
+ "_get_boot_kernel_path"
909
+ )
887
910
)
888
911
@patch (
889
- "check_secure_boot_state.FITImageSecureBootChecker._get_snap_kernel_patterns"
912
+ (
913
+ "check_secure_boot_state.FITImageSecureBootChecker."
914
+ "_get_snap_kernel_patterns"
915
+ )
890
916
)
891
917
@patch (
892
- "check_secure_boot_state.FITImageSecureBootChecker._build_search_patterns"
918
+ (
919
+ "check_secure_boot_state.FITImageSecureBootChecker."
920
+ "_build_search_patterns"
921
+ )
893
922
)
894
923
@patch (
895
- "check_secure_boot_state.FITImageSecureBootChecker._find_files_by_patterns"
924
+ (
925
+ "check_secure_boot_state.FITImageSecureBootChecker."
926
+ "_find_files_by_patterns"
927
+ )
896
928
)
897
929
def test_find_fit_images_with_hostfs_prefix (
898
930
self ,
@@ -925,16 +957,26 @@ def test_find_fit_images_with_hostfs_prefix(
925
957
)
926
958
927
959
@patch (
928
- "check_secure_boot_state.FITImageSecureBootChecker._get_boot_kernel_path"
960
+ (
961
+ "check_secure_boot_state.FITImageSecureBootChecker."
962
+ "_get_boot_kernel_path"
963
+ )
929
964
)
930
965
@patch (
931
- "check_secure_boot_state.FITImageSecureBootChecker._get_classic_fit_patterns"
966
+ "check_secure_boot_state.FITImageSecureBootChecker."
967
+ "_get_classic_fit_patterns"
932
968
)
933
969
@patch (
934
- "check_secure_boot_state.FITImageSecureBootChecker._build_search_patterns"
970
+ (
971
+ "check_secure_boot_state.FITImageSecureBootChecker."
972
+ "_build_search_patterns"
973
+ )
935
974
)
936
975
@patch (
937
- "check_secure_boot_state.FITImageSecureBootChecker._find_files_by_patterns"
976
+ (
977
+ "check_secure_boot_state.FITImageSecureBootChecker."
978
+ "_find_files_by_patterns"
979
+ )
938
980
)
939
981
def test_find_fit_images_unknown_variant (
940
982
self ,
@@ -955,7 +997,7 @@ def test_find_fit_images_unknown_variant(
955
997
956
998
self .assertEqual (images , ["/boot/vmlinuz-5.4.0" ])
957
999
# Should default to classic patterns for unknown variant
958
- mock_get_patterns . assert_called_once ( )
1000
+ self . assertEqual ( mock_get_patterns . call_count , 1 )
959
1001
960
1002
961
1003
class TestUtilityFunctions (unittest .TestCase ):
@@ -977,7 +1019,7 @@ def test_log_secure_boot_info(self):
977
1019
error_msg = None
978
1020
checker_name = "Test Checker"
979
1021
log_secure_boot_info (state , error_msg , checker_name )
980
- self .mock_logger .info .assert_called ( )
1022
+ self .mock_logger .info .assert_called_with ( "Current state: enabled" )
981
1023
982
1024
def test_log_secure_boot_info_with_error (self ):
983
1025
"""Test secure boot info logging with error."""
@@ -994,7 +1036,9 @@ def test_check_secure_boot_result_processing_error(self):
994
1036
check_mode = "enable"
995
1037
result = check_secure_boot_result (state , error_msg , check_mode )
996
1038
self .assertEqual (result , 1 )
997
- self .mock_logger .error .assert_called ()
1039
+ self .mock_logger .error .assert_called_with (
1040
+ "FAIL: Cannot determine if secure boot is enable - Test error"
1041
+ )
998
1042
999
1043
def test_check_secure_boot_result_processing_error_no_mode (self ):
1000
1044
"""Test secure boot result checking - processing error without mode."""
@@ -1003,7 +1047,9 @@ def test_check_secure_boot_result_processing_error_no_mode(self):
1003
1047
check_mode = None
1004
1048
result = check_secure_boot_result (state , error_msg , check_mode )
1005
1049
self .assertEqual (result , 1 )
1006
- self .mock_logger .error .assert_called ()
1050
+ self .mock_logger .error .assert_called_with (
1051
+ "FAIL: Cannot determine secure boot state - Test error"
1052
+ )
1007
1053
1008
1054
def test_check_secure_boot_result_enable_success (self ):
1009
1055
"""Test secure boot result checking - enable success."""
@@ -1012,7 +1058,9 @@ def test_check_secure_boot_result_enable_success(self):
1012
1058
check_mode = "enable"
1013
1059
result = check_secure_boot_result (state , error_msg , check_mode )
1014
1060
self .assertEqual (result , 0 )
1015
- self .mock_logger .info .assert_called ()
1061
+ self .mock_logger .info .assert_called_with (
1062
+ "PASS: Secure boot is enabled"
1063
+ )
1016
1064
1017
1065
def test_check_secure_boot_result_enable_failure (self ):
1018
1066
"""Test secure boot result checking - enable failure."""
@@ -1021,7 +1069,9 @@ def test_check_secure_boot_result_enable_failure(self):
1021
1069
check_mode = "enable"
1022
1070
result = check_secure_boot_result (state , error_msg , check_mode )
1023
1071
self .assertEqual (result , 1 )
1024
- self .mock_logger .log_failure .assert_called ()
1072
+ self .mock_logger .log_failure .assert_called_with (
1073
+ "enable" , SecureBootState .DISABLED , None
1074
+ )
1025
1075
1026
1076
def test_check_secure_boot_result_disabled_success (self ):
1027
1077
"""Test secure boot result checking - disabled success."""
@@ -1030,7 +1080,9 @@ def test_check_secure_boot_result_disabled_success(self):
1030
1080
check_mode = "disabled"
1031
1081
result = check_secure_boot_result (state , error_msg , check_mode )
1032
1082
self .assertEqual (result , 0 )
1033
- self .mock_logger .info .assert_called ()
1083
+ self .mock_logger .info .assert_called_with (
1084
+ "PASS: Secure boot is disabled"
1085
+ )
1034
1086
1035
1087
def test_check_secure_boot_result_disabled_failure (self ):
1036
1088
"""Test secure boot result checking - disabled failure."""
@@ -1039,7 +1091,9 @@ def test_check_secure_boot_result_disabled_failure(self):
1039
1091
check_mode = "disabled"
1040
1092
result = check_secure_boot_result (state , error_msg , check_mode )
1041
1093
self .assertEqual (result , 1 )
1042
- self .mock_logger .log_failure .assert_called ()
1094
+ self .mock_logger .log_failure .assert_called_with (
1095
+ "disabled" , SecureBootState .ENABLED , None
1096
+ )
1043
1097
1044
1098
def test_check_secure_boot_result_no_mode (self ):
1045
1099
"""Test secure boot result checking - no mode specified."""
@@ -1341,7 +1395,7 @@ def test_main_unexpected_error(
1341
1395
main ()
1342
1396
1343
1397
mock_exit .assert_called_with (1 )
1344
- mock_traceback .assert_called_once ()
1398
+ mock_traceback .assert_called_with ()
1345
1399
1346
1400
@patch ("sys.exit" )
1347
1401
@patch ("check_secure_boot_state.create_checker" )
0 commit comments