Skip to content

Commit

Permalink
in_tail: test: Add testcase for path w/ Linux capability
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Hatake <hatake@clear-code.com>
  • Loading branch information
cosmo0920 committed Nov 9, 2020
1 parent 8e7b83e commit 344b1be
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions test/plugin/test_in_tail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,49 @@ def count_timer_object
end
end

sub_test_case "path w/ Linux capability" do
def capability_enabled?
if Fluent.linux?
begin
require 'capng'
true
rescue LoadError
false
end
else
false
end
end

setup do
omit "This environment is not enabled Linux capability handling feature" unless capability_enabled?

@capng = CapNG.new(:current_process)
flexstub(Fluent::Capability) do |klass|
klass.should_receive(:new).with(:current_process).and_return(@capng)
end
end

data("dac_read_search" => [:dac_read_search, true, 1],
"dac_override" => [:dac_override, true, 1],
"chown" => [:chown, false, 0],
)
test "with partially elevated privileges" do |data|
cap, result, readable_paths = data
@capng.update(:add, :effective, cap)

d = create_driver(
config_element("ROOT", "", {
"path" => "/var/log/ker*.log", # Use /var/log/kern.log
"tag" => "t1",
"rotate_wait" => "2s"
}) + PARSE_SINGLE_LINE_CONFIG, false)

assert_equal readable_paths, d.instance.expand_paths.length
assert_equal result, d.instance.have_read_capability?
end
end

def test_pos_file_dir_creation
config = config_element("", "", {
"tag" => "tail",
Expand Down

0 comments on commit 344b1be

Please sign in to comment.