@@ -3402,4 +3402,104 @@ def test_next_rotation_occurs_very_fast_while_old_TW_still_waiting_rotate_wait
3402
3402
d . logs [ -2 ..]
3403
3403
] )
3404
3404
end
3405
+
3406
+ sub_test_case "directory permissions and ownership" do
3407
+ setup do
3408
+ @dir = File . expand_path ( "#{ @tmp_dir } /tail#{ rand ( 0 ..10000 ) } " )
3409
+ @pos_dir = File . expand_path ( "#{ @tmp_dir } /pos#{ rand ( 0 ..10000 ) } " )
3410
+ FileUtils . mkdir_p ( @dir )
3411
+ end
3412
+
3413
+ teardown do
3414
+ FileUtils . rm_rf ( @dir ) if File . exist? ( @dir )
3415
+ FileUtils . rm_rf ( @pos_dir ) if File . exist? ( @pos_dir )
3416
+ end
3417
+
3418
+ test 'creates pos_file directory with default permissions when not specified' do
3419
+ pos_file = "#{ @pos_dir } /tail.pos"
3420
+ config = config_element ( "ROOT" , "" , {
3421
+ "path" => "#{ @dir } /tail.txt" ,
3422
+ "pos_file" => pos_file ,
3423
+ "tag" => "t1" ,
3424
+ "format" => "none" ,
3425
+ "read_from_head" => "true"
3426
+ } )
3427
+ d = create_driver ( config )
3428
+ d . run ( expect_emits : 1 ) do
3429
+ File . open ( "#{ @dir } /tail.txt" , "wb" ) { |f | f . puts "test default permissions" }
3430
+ end
3431
+
3432
+ assert_equal ( true , File . directory? ( @pos_dir ) )
3433
+ assert_equal ( 0755 , File . stat ( @pos_dir ) . mode & 0777 )
3434
+ end
3435
+
3436
+ test 'creates pos_file directory with custom permissions' do
3437
+ pos_file = "#{ @pos_dir } /tail.pos"
3438
+ config = config_element ( "ROOT" , "" , {
3439
+ "path" => "#{ @dir } /tail.txt" ,
3440
+ "pos_file" => pos_file ,
3441
+ "tag" => "t1" ,
3442
+ "format" => "none" ,
3443
+ "read_from_head" => "true" ,
3444
+ "pos_dir_perm" => "0770"
3445
+ } )
3446
+ d = create_driver ( config )
3447
+ d . run ( expect_emits : 1 ) do
3448
+ File . open ( "#{ @dir } /tail.txt" , "wb" ) { |f | f . puts "test custom permissions" }
3449
+ end
3450
+
3451
+ assert_equal ( true , File . directory? ( @pos_dir ) )
3452
+ assert_equal ( 0770 , File . stat ( @pos_dir ) . mode & 0777 )
3453
+ end
3454
+
3455
+ test 'creates pos_file directory with custom ownership' do
3456
+ omit "Test requires root privileges" unless Process . uid == 0
3457
+
3458
+ pos_file = "#{ @pos_dir } /tail.pos"
3459
+ config = config_element ( "ROOT" , "" , {
3460
+ "path" => "#{ @dir } /tail.txt" ,
3461
+ "pos_file" => pos_file ,
3462
+ "tag" => "t1" ,
3463
+ "format" => "none" ,
3464
+ "read_from_head" => "true" ,
3465
+ "pos_dir_owner" => Process . uid . to_s ,
3466
+ "pos_dir_group" => Process . gid . to_s
3467
+ } )
3468
+ d = create_driver ( config )
3469
+ d . run ( expect_emits : 1 ) do
3470
+ File . open ( "#{ @dir } /tail.txt" , "wb" ) { |f | f . puts "test custom ownership" }
3471
+ end
3472
+
3473
+ assert_equal ( true , File . directory? ( @pos_dir ) )
3474
+ stat = File . stat ( @pos_dir )
3475
+ assert_equal ( Process . uid , stat . uid )
3476
+ assert_equal ( Process . gid , stat . gid )
3477
+ end
3478
+
3479
+ test 'creates pos_file directory with both custom permissions and ownership' do
3480
+ omit "Test requires root privileges" unless Process . uid == 0
3481
+
3482
+ pos_file = "#{ @pos_dir } /tail.pos"
3483
+ config = config_element ( "ROOT" , "" , {
3484
+ "path" => "#{ @dir } /tail.txt" ,
3485
+ "pos_file" => pos_file ,
3486
+ "tag" => "t1" ,
3487
+ "format" => "none" ,
3488
+ "read_from_head" => "true" ,
3489
+ "pos_dir_perm" => "0770" ,
3490
+ "pos_dir_owner" => Process . uid . to_s ,
3491
+ "pos_dir_group" => Process . gid . to_s
3492
+ } )
3493
+ d = create_driver ( config )
3494
+ d . run ( expect_emits : 1 ) do
3495
+ File . open ( "#{ @dir } /tail.txt" , "wb" ) { |f | f . puts "test custom permissions and ownership" }
3496
+ end
3497
+
3498
+ assert_equal ( true , File . directory? ( @pos_dir ) )
3499
+ stat = File . stat ( @pos_dir )
3500
+ assert_equal ( 0770 , stat . mode & 0777 )
3501
+ assert_equal ( Process . uid , stat . uid )
3502
+ assert_equal ( Process . gid , stat . gid )
3503
+ end
3504
+ end
3405
3505
end
0 commit comments