@@ -161,6 +161,8 @@ def test_check_not_fetchd
161
161
sub_test_case "yaml config" do
162
162
def test_included
163
163
write_config "#{ TMP_DIR } /config_test_not_fetched.yaml" , <<-EOS
164
+ system:
165
+ umask: "0022"
164
166
config:
165
167
- source:
166
168
$type: dummy
@@ -195,12 +197,13 @@ def test_included
195
197
flush_mode: interval
196
198
flush_interval: 1s
197
199
EOS
198
- root_conf = read_config ( "#{ TMP_DIR } /config_test_not_fetched.yaml" , use_yaml : true )
199
- dummy_source_conf = root_conf . elements . first
200
- tcp_source_conf = root_conf . elements [ 1 ]
200
+ root_conf = read_config ( "#{ TMP_DIR } /config_test_not_fetched.yaml" , use_yaml : true )
201
+ system_conf = root_conf . elements . find { |e | e . name == "system" }
202
+ dummy_source_conf = root_conf . elements . find { |e | e . name == "source" && e [ '@type' ] == "dummy" }
203
+ tcp_source_conf = root_conf . elements . find { |e | e . name == "source" && e [ '@type' ] == "tcp" }
201
204
parse_tcp_conf = tcp_source_conf . elements . first
202
- match_conf = root_conf . elements [ 2 ]
203
- label_conf = root_conf . elements [ 3 ]
205
+ match_conf = root_conf . elements . find { | e | e . name == "match" && e . arg == "tag.*" }
206
+ label_conf = root_conf . elements . find { | e | e . name == "label" }
204
207
fluent_log_conf = label_conf . elements . first
205
208
fluent_log_buffer_conf = fluent_log_conf . elements . first
206
209
@@ -222,6 +225,7 @@ def test_included
222
225
'memory' ,
223
226
'interval' ,
224
227
'1s' ,
228
+ '0022' ,
225
229
] ,
226
230
[
227
231
dummy_source_conf [ '@type' ] ,
@@ -240,11 +244,14 @@ def test_included
240
244
fluent_log_buffer_conf [ '@type' ] ,
241
245
fluent_log_buffer_conf [ 'flush_mode' ] ,
242
246
fluent_log_buffer_conf [ 'flush_interval' ] ,
247
+ system_conf [ 'umask' ] ,
243
248
] )
244
249
end
245
250
246
251
def test_included_glob
247
252
write_config "#{ TMP_DIR } /config.yaml" , <<-EOS
253
+ system:
254
+ umask: "0022"
248
255
config:
249
256
- !include "include/*.yaml"
250
257
EOS
@@ -272,10 +279,11 @@ def test_included_glob
272
279
flush_interval: 1s
273
280
EOS
274
281
root_conf = read_config ( "#{ TMP_DIR } /config.yaml" , use_yaml : true )
275
- tcp_source_conf = root_conf . elements . first
276
- dummy_source_conf = root_conf . elements [ 1 ]
282
+ system_conf = root_conf . elements . find { |e | e . name == "system" }
283
+ tcp_source_conf = root_conf . elements . find { |e | e . name == "source" && e [ '@type' ] == "tcp" }
284
+ dummy_source_conf = root_conf . elements . find { |e | e . name == "source" && e [ '@type' ] == "dummy" }
277
285
parse_tcp_conf = tcp_source_conf . elements . first
278
- match_conf = root_conf . elements [ 2 ]
286
+ match_conf = root_conf . elements . find { | e | e . name == "match" && e . arg == "tag.*" }
279
287
280
288
assert_equal (
281
289
[
@@ -287,6 +295,7 @@ def test_included_glob
287
295
'tag.dummy' ,
288
296
'stdout' ,
289
297
'tag.*' ,
298
+ '0022' ,
290
299
] ,
291
300
[
292
301
tcp_source_conf [ '@type' ] ,
@@ -297,6 +306,7 @@ def test_included_glob
297
306
dummy_source_conf [ 'tag' ] ,
298
307
match_conf [ '@type' ] ,
299
308
match_conf . arg ,
309
+ system_conf [ 'umask' ] ,
300
310
] )
301
311
end
302
312
@@ -343,6 +353,42 @@ def test_check_not_fetchd
343
353
10 . times { match_conf [ 'type' ] }
344
354
assert_equal before_size , match_conf . unused . size
345
355
end
356
+
357
+ test 'yaml system config with umask' do
358
+ write_config "#{ TMP_DIR } /config_test_umask.yaml" , <<-EOS
359
+ system:
360
+ umask: "0022"
361
+ config:
362
+ - source:
363
+ $type: dummy
364
+ tag: tag.dummy
365
+ - match:
366
+ $tag: tag.*
367
+ $type: stdout
368
+ EOS
369
+ conf = read_config ( "#{ TMP_DIR } /config_test_umask.yaml" , use_yaml : true )
370
+ assert_equal "0022" , conf . elements . find { |e | e . name == "system" } [ "umask" ]
371
+ end
372
+
373
+ test 'system config with invalid umask' do
374
+ conf = <<-EOC
375
+ <system>
376
+ umask 0999 # invalid octal
377
+ </system>
378
+ EOC
379
+ conf = Fluent ::Config . parse ( conf , "(test)" , "(test_dir)" , true )
380
+ assert_equal "0999" , conf . elements . find { |e | e . name == "system" } [ "umask" ]
381
+ end
382
+
383
+ test 'system config without umask' do
384
+ conf = <<-EOC
385
+ <system>
386
+ # no umask setting
387
+ </system>
388
+ EOC
389
+ conf = Fluent ::Config . parse ( conf , "(test)" , "(test_dir)" , true )
390
+ assert_nil conf . elements . find { |e | e . name == "system" } [ "umask" ]
391
+ end
346
392
end
347
393
348
394
def write_config ( path , data , encoding : 'utf-8' )
@@ -371,5 +417,52 @@ def write_config(path, data, encoding: 'utf-8')
371
417
assert_equal ( 'value' , c [ 'key' ] )
372
418
assert_equal ( 'value2' , c [ 'key2' ] )
373
419
end
420
+
421
+ test 'system config with umask' do
422
+ conf = <<-EOC
423
+ <system>
424
+ umask 0022
425
+ </system>
426
+ EOC
427
+ conf = Fluent ::Config . parse ( conf , "(test)" , "(test_dir)" , true )
428
+ ra = Fluent ::RootAgent . new ( log : $log)
429
+ old_umask = File . umask
430
+ begin
431
+ ra . configure ( conf )
432
+ assert_equal 0022 , File . umask
433
+ ensure
434
+ File . umask ( old_umask )
435
+ end
436
+ end
437
+
438
+ test 'system config with invalid umask' do
439
+ conf = <<-EOC
440
+ <system>
441
+ umask 0999 # invalid octal
442
+ </system>
443
+ EOC
444
+ conf = Fluent ::Config . parse ( conf , "(test)" , "(test_dir)" , true )
445
+ ra = Fluent ::RootAgent . new ( log : $log)
446
+ assert_raise ( Fluent ::ConfigError ) do
447
+ ra . configure ( conf )
448
+ end
449
+ end
450
+
451
+ test 'system config without umask' do
452
+ conf = <<-EOC
453
+ <system>
454
+ # no umask setting
455
+ </system>
456
+ EOC
457
+ conf = Fluent ::Config . parse ( conf , "(test)" , "(test_dir)" , true )
458
+ ra = Fluent ::RootAgent . new ( log : $log)
459
+ old_umask = File . umask
460
+ begin
461
+ ra . configure ( conf )
462
+ assert_equal 0022 , File . umask
463
+ ensure
464
+ File . umask ( old_umask )
465
+ end
466
+ end
374
467
end
375
- end
468
+ end
0 commit comments