@@ -474,58 +474,54 @@ mod tests {
474474
475475 let result = get_selinux_security_context ( path, false ) ;
476476
477- if result. is_ok ( ) {
478- let context = result. unwrap ( ) ;
479- println ! ( "Retrieved SELinux context: {context}" ) ;
480-
481- assert ! (
482- is_selinux_enabled( ) ,
483- "Got a successful context result but SELinux is not enabled"
484- ) ;
477+ match result {
478+ Ok ( context) => {
479+ println ! ( "Retrieved SELinux context: {context}" ) ;
485480
486- if !context. is_empty ( ) {
487481 assert ! (
488- context . contains ( ':' ) ,
489- "SELinux context '{ context}' doesn't match expected format "
482+ is_selinux_enabled ( ) ,
483+ "Got a successful context result but SELinux is not enabled "
490484 ) ;
491- }
492- } else {
493- let err = result. unwrap_err ( ) ;
494485
495- match err {
496- SeLinuxError :: SELinuxNotEnabled => {
486+ if !context. is_empty ( ) {
497487 assert ! (
498- !is_selinux_enabled( ) ,
499- "Got SELinuxNotEnabled error, but is_selinux_enabled() returned true"
500- ) ;
501- }
502- SeLinuxError :: ContextRetrievalFailure ( e) => {
503- assert ! (
504- is_selinux_enabled( ) ,
505- "Got ContextRetrievalFailure when SELinux is not enabled"
506- ) ;
507- assert ! ( !e. is_empty( ) , "Error message should not be empty" ) ;
508- println ! ( "Context retrieval failure: {e}" ) ;
509- }
510- SeLinuxError :: ContextConversionFailure ( ctx, e) => {
511- assert ! (
512- is_selinux_enabled( ) ,
513- "Got ContextConversionFailure when SELinux is not enabled"
514- ) ;
515- assert ! ( !e. is_empty( ) , "Error message should not be empty" ) ;
516- println ! ( "Context conversion failure for '{ctx}': {e}" ) ;
517- }
518- SeLinuxError :: ContextSetFailure ( ctx, e) => {
519- assert ! ( !e. is_empty( ) , "Error message should not be empty" ) ;
520- println ! ( "Context conversion failure for '{ctx}': {e}" ) ;
521- }
522- SeLinuxError :: FileOpenFailure ( e) => {
523- assert ! (
524- Path :: new( path) . exists( ) ,
525- "File open failure occurred despite file being created: {e}"
488+ context. contains( ':' ) ,
489+ "SELinux context '{context}' doesn't match expected format"
526490 ) ;
527491 }
528492 }
493+ Err ( SeLinuxError :: SELinuxNotEnabled ) => {
494+ assert ! (
495+ !is_selinux_enabled( ) ,
496+ "Got SELinuxNotEnabled error, but is_selinux_enabled() returned true"
497+ ) ;
498+ }
499+ Err ( SeLinuxError :: ContextRetrievalFailure ( e) ) => {
500+ assert ! (
501+ is_selinux_enabled( ) ,
502+ "Got ContextRetrievalFailure when SELinux is not enabled"
503+ ) ;
504+ assert ! ( !e. is_empty( ) , "Error message should not be empty" ) ;
505+ println ! ( "Context retrieval failure: {e}" ) ;
506+ }
507+ Err ( SeLinuxError :: ContextConversionFailure ( ctx, e) ) => {
508+ assert ! (
509+ is_selinux_enabled( ) ,
510+ "Got ContextConversionFailure when SELinux is not enabled"
511+ ) ;
512+ assert ! ( !e. is_empty( ) , "Error message should not be empty" ) ;
513+ println ! ( "Context conversion failure for '{ctx}': {e}" ) ;
514+ }
515+ Err ( SeLinuxError :: ContextSetFailure ( ctx, e) ) => {
516+ assert ! ( !e. is_empty( ) , "Error message should not be empty" ) ;
517+ println ! ( "Context conversion failure for '{ctx}': {e}" ) ;
518+ }
519+ Err ( SeLinuxError :: FileOpenFailure ( e) ) => {
520+ assert ! (
521+ Path :: new( path) . exists( ) ,
522+ "File open failure occurred despite file being created: {e}"
523+ ) ;
524+ }
529525 }
530526 }
531527
0 commit comments