@@ -228,15 +228,14 @@ impl Bpf {
228228
229229#[ cfg( all( test, feature = "bpf-test" ) ) ]
230230mod bpf_tests {
231- use std:: { env, path:: PathBuf , time:: Duration } ;
231+ use std:: { env, os :: unix :: fs :: PermissionsExt , path:: PathBuf , time:: Duration } ;
232232
233- use fact_ebpf:: file_activity_type_t;
234233 use tempfile:: NamedTempFile ;
235234 use tokio:: { sync:: watch, time:: timeout} ;
236235
237236 use crate :: {
238237 config:: { reloader:: Reloader , FactConfig } ,
239- event:: process:: Process ,
238+ event:: { process:: Process , EventTestData } ,
240239 host_info,
241240 metrics:: exporter:: Exporter ,
242241 } ;
@@ -273,20 +272,39 @@ mod bpf_tests {
273272 let file = NamedTempFile :: new_in ( monitored_path) . expect ( "Failed to create temporary file" ) ;
274273 println ! ( "Created {file:?}" ) ;
275274
275+ // Trigger permission changes
276+ let mut perms = file
277+ . path ( )
278+ . metadata ( )
279+ . expect ( "Failed to read file permissions" )
280+ . permissions ( ) ;
281+ let old_perm = perms. mode ( ) as u16 ;
282+ let new_perm: u16 = 0o666 ;
283+ perms. set_mode ( new_perm as u32 ) ;
284+ std:: fs:: set_permissions ( file. path ( ) , perms) . expect ( "Failed to set file permissions" ) ;
285+
276286 let current = Process :: current ( ) ;
277287 let file_path = file. path ( ) . to_path_buf ( ) ;
278288
279289 let expected_events = [
280290 Event :: new (
281- file_activity_type_t:: FILE_ACTIVITY_CREATION ,
291+ EventTestData :: Creation ,
292+ host_info:: get_hostname ( ) ,
293+ file_path. clone ( ) ,
294+ PathBuf :: new ( ) , // host path is resolved by HostScanner
295+ current. clone ( ) ,
296+ )
297+ . unwrap ( ) ,
298+ Event :: new (
299+ EventTestData :: Chmod ( new_perm, old_perm) ,
282300 host_info:: get_hostname ( ) ,
283301 file_path. clone ( ) ,
284302 PathBuf :: new ( ) , // host path is resolved by HostScanner
285303 current. clone ( ) ,
286304 )
287305 . unwrap ( ) ,
288306 Event :: new (
289- file_activity_type_t :: FILE_ACTIVITY_UNLINK ,
307+ EventTestData :: Unlink ,
290308 host_info:: get_hostname ( ) ,
291309 file_path,
292310 PathBuf :: new ( ) , // host path is resolved by HostScanner
@@ -298,12 +316,13 @@ mod bpf_tests {
298316 // Close the file, removing it
299317 file. close ( ) . expect ( "Failed to close temp file" ) ;
300318
301- println ! ( "Expected: {expected_events:?}" ) ;
302319 let wait = timeout ( Duration :: from_secs ( 1 ) , async move {
303320 for expected in expected_events {
321+ println ! ( "expected: {expected:#?}" ) ;
304322 while let Some ( event) = rx. recv ( ) . await {
305- println ! ( "{event:?}" ) ;
323+ println ! ( "{event:# ?}" ) ;
306324 if event == expected {
325+ println ! ( "Found!" ) ;
307326 break ;
308327 }
309328 }
0 commit comments