mirror of
https://github.com/inspec/inspec
synced 2025-02-17 06:28:40 +00:00
host resource: fix netcat detection (#1995)
The logic used to determine whether a viable netcat binary exists is wrong and prevents Linux hosts from doing TCP reachability checks. Signed-off-by: Adam Leff <adam@leff.co>
This commit is contained in:
parent
dd3457537e
commit
1fdea330d3
2 changed files with 38 additions and 1 deletions
|
@ -210,7 +210,7 @@ module Inspec::Resources
|
|||
def missing_requirements(protocol)
|
||||
missing = []
|
||||
|
||||
if protocol == 'tcp' && (!inspec.command('nc').exist? || !inspec.command('ncat').exist?)
|
||||
if protocol == 'tcp' && (!inspec.command('nc').exist? && !inspec.command('ncat').exist?)
|
||||
missing << 'netcat must be installed'
|
||||
end
|
||||
|
||||
|
|
|
@ -195,6 +195,43 @@ describe Inspec::Resources::LinuxHostProvider do
|
|||
provider.stubs(:inspec).returns(inspec)
|
||||
end
|
||||
|
||||
describe '#missing_requirements' do
|
||||
it "returns an empty array if nc is installed but ncat is not installed" do
|
||||
inspec.stubs(:command).with('nc').returns(nc_command)
|
||||
nc_command.stubs(:exist?).returns(true)
|
||||
inspec.stubs(:command).with('ncat').returns(ncat_command)
|
||||
ncat_command.stubs(:exist?).returns(false)
|
||||
|
||||
provider.missing_requirements('tcp').must_equal([])
|
||||
end
|
||||
|
||||
it "returns an empty array if nc is not installed but ncat is installed" do
|
||||
inspec.stubs(:command).with('nc').returns(nc_command)
|
||||
nc_command.stubs(:exist?).returns(false)
|
||||
inspec.stubs(:command).with('ncat').returns(ncat_command)
|
||||
ncat_command.stubs(:exist?).returns(true)
|
||||
|
||||
provider.missing_requirements('tcp').must_equal([])
|
||||
end
|
||||
|
||||
it "returns an empty array if both nc and ncat are installed" do
|
||||
inspec.stubs(:command).with('nc').returns(nc_command)
|
||||
nc_command.stubs(:exist?).returns(true)
|
||||
inspec.stubs(:command).with('ncat').returns(ncat_command)
|
||||
ncat_command.stubs(:exist?).returns(true)
|
||||
|
||||
provider.missing_requirements('tcp').must_equal([])
|
||||
end
|
||||
|
||||
it "returns a missing requirement when neither nc nor ncat are installed" do
|
||||
inspec.stubs(:command).with('nc').returns(nc_command)
|
||||
nc_command.stubs(:exist?).returns(false)
|
||||
inspec.stubs(:command).with('ncat').returns(ncat_command)
|
||||
ncat_command.stubs(:exist?).returns(false)
|
||||
|
||||
provider.missing_requirements('tcp').must_equal(['netcat must be installed'])
|
||||
end
|
||||
end
|
||||
describe '#tcp_check_command' do
|
||||
it 'returns an nc command when nc exists' do
|
||||
inspec.expects(:command).with('nc').returns(nc_command)
|
||||
|
|
Loading…
Add table
Reference in a new issue