@@ -824,6 +824,79 @@ mod classifications_tests {
824824 }
825825 }
826826
827+ /// An `audits/` the reader cannot search must not look like a missing
828+ /// deed: that would silently fall back to the root `.a2ml` registry.
829+ #[ cfg( unix) ]
830+ #[ test]
831+ fn unreadable_audits_dir_is_an_error_not_a_fallback ( ) {
832+ use std:: os:: unix:: fs:: PermissionsExt ;
833+ let tmp = TempDir :: new ( ) . unwrap ( ) ;
834+ write_deed ( tmp. path ( ) , & deed_with ( ZIG_BRIDGE_DEED_ENTRY ) ) ;
835+ fs:: write (
836+ tmp. path ( ) . join ( ".panic-attack-classifications.a2ml" ) ,
837+ r#"(assail-classifications
838+ (classification (file "a/b.rs") (category "PanicPath")))
839+ "# ,
840+ )
841+ . unwrap ( ) ;
842+ let audits = tmp. path ( ) . join ( "audits" ) ;
843+ fs:: set_permissions ( & audits, fs:: Permissions :: from_mode ( 0o000 ) ) . unwrap ( ) ;
844+ // Root, or any process with CAP_DAC_OVERRIDE/CAP_DAC_READ_SEARCH,
845+ // ignores the mode bits, so the deed stays readable and there is
846+ // nothing to test. Probe instead of checking the uid: the probe also
847+ // covers capabilities granted to a non-root user.
848+ let privileged = fs:: read_dir ( & audits) . is_ok ( ) ;
849+ let result = load_user_classifications ( tmp. path ( ) ) ;
850+ // Restore the mode so TempDir can clean up.
851+ fs:: set_permissions ( & audits, fs:: Permissions :: from_mode ( 0o755 ) ) . unwrap ( ) ;
852+ if privileged {
853+ eprintln ! (
854+ "skipped: running as root (or with DAC override), so a mode-000 directory stays readable"
855+ ) ;
856+ return ;
857+ }
858+ let err = result. expect_err ( "an unreadable audits/ must be an error" ) ;
859+ assert ! (
860+ format!( "{err:#}" ) . contains( "assail-classifications_praxis.deed" ) ,
861+ "error must name the registry: {err:#}"
862+ ) ;
863+ }
864+
865+ #[ test]
866+ fn audits_as_a_regular_file_means_no_deed ( ) {
867+ let tmp = TempDir :: new ( ) . unwrap ( ) ;
868+ fs:: write ( tmp. path ( ) . join ( "audits" ) , "not a directory\n " ) . unwrap ( ) ;
869+ fs:: write (
870+ tmp. path ( ) . join ( ".panic-attack-classifications.a2ml" ) ,
871+ r#"(assail-classifications
872+ (classification (file "a/b.rs") (category "PanicPath")))
873+ "# ,
874+ )
875+ . unwrap ( ) ;
876+ let classifications = load_user_classifications ( tmp. path ( ) ) . unwrap ( ) ;
877+ assert_eq ! ( classifications. len( ) , 1 , "falls back to the root registry" ) ;
878+ }
879+
880+ #[ cfg( unix) ]
881+ #[ test]
882+ fn dangling_deed_symlink_is_an_error_not_a_fallback ( ) {
883+ let tmp = TempDir :: new ( ) . unwrap ( ) ;
884+ let audits = tmp. path ( ) . join ( "audits" ) ;
885+ fs:: create_dir_all ( & audits) . unwrap ( ) ;
886+ std:: os:: unix:: fs:: symlink (
887+ tmp. path ( ) . join ( "nowhere.deed" ) ,
888+ tmp. path ( ) . join ( USER_CLASSIFICATIONS_DEED_PATH ) ,
889+ )
890+ . unwrap ( ) ;
891+ write_registry (
892+ tmp. path ( ) ,
893+ r#"(assail-classifications
894+ (classification (file "a/b.rs") (category "PanicPath")))
895+ "# ,
896+ ) ;
897+ assert ! ( load_user_classifications( tmp. path( ) ) . is_err( ) ) ;
898+ }
899+
827900 #[ test]
828901 fn analyze_fails_on_a_malformed_deed ( ) {
829902 let tmp = TempDir :: new ( ) . unwrap ( ) ;
0 commit comments