2015-09-23 13:19:48 +00:00
|
|
|
# encoding: utf-8
|
2015-10-06 16:55:44 +00:00
|
|
|
# author: Christoph Hartmann
|
|
|
|
# author: Dominik Richter
|
2015-09-23 13:19:48 +00:00
|
|
|
|
|
|
|
require 'helper'
|
2015-10-26 03:04:18 +00:00
|
|
|
require 'inspec/resource'
|
2015-09-23 13:19:48 +00:00
|
|
|
|
2015-10-26 03:04:18 +00:00
|
|
|
describe 'Inspec::Resources::Port' do
|
2015-09-23 13:19:48 +00:00
|
|
|
it 'verify port on Ubuntu 14.04' do
|
|
|
|
resource = MockLoader.new(:ubuntu1404).load_resource('port', 22)
|
|
|
|
_(resource.listening?).must_equal true
|
2015-12-08 12:46:20 +00:00
|
|
|
_(resource.protocols).must_equal %w{ tcp tcp6 }
|
|
|
|
_(resource.pids).must_equal [1]
|
|
|
|
_(resource.processes).must_equal ['sshd']
|
2015-09-23 13:19:48 +00:00
|
|
|
end
|
|
|
|
|
2016-01-14 21:05:22 +00:00
|
|
|
it 'verify UDP port on Ubuntu 14.04' do
|
|
|
|
resource = MockLoader.new(:ubuntu1404).load_resource('port', 111)
|
|
|
|
_(resource.listening?).must_equal true
|
|
|
|
_(resource.protocols).must_equal %w{ udp }
|
|
|
|
_(resource.pids).must_equal [545]
|
|
|
|
_(resource.processes).must_equal ['rpcbind']
|
|
|
|
end
|
|
|
|
|
2015-09-23 13:21:25 +00:00
|
|
|
it 'verify port on MacOs x' do
|
|
|
|
resource = MockLoader.new(:osx104).load_resource('port', 2022)
|
|
|
|
_(resource.listening?).must_equal true
|
2015-12-08 12:46:20 +00:00
|
|
|
_(resource.protocols).must_equal ['tcp']
|
|
|
|
_(resource.processes).must_equal ['VBoxHeadl']
|
2015-09-23 13:21:25 +00:00
|
|
|
end
|
|
|
|
|
2015-09-23 13:22:31 +00:00
|
|
|
it 'verify port on Windows' do
|
|
|
|
resource = MockLoader.new(:windows).load_resource('port', 135)
|
|
|
|
_(resource.listening?).must_equal true
|
2015-12-08 12:46:20 +00:00
|
|
|
_(resource.protocols).must_equal ['tcp']
|
|
|
|
_(resource.processes).must_equal nil
|
2015-09-23 13:22:31 +00:00
|
|
|
end
|
|
|
|
|
2015-09-23 13:24:46 +00:00
|
|
|
it 'verify port on FreeBSD' do
|
|
|
|
resource = MockLoader.new(:freebsd10).load_resource('port', 22)
|
|
|
|
_(resource.listening?).must_equal true
|
2015-12-08 12:46:20 +00:00
|
|
|
_(resource.protocols).must_equal %w{ tcp6 tcp }
|
|
|
|
_(resource.pids).must_equal [668]
|
|
|
|
_(resource.processes).must_equal ['sshd']
|
2015-09-23 13:24:46 +00:00
|
|
|
end
|
|
|
|
|
2015-12-03 03:08:49 +00:00
|
|
|
it 'verify port on wrlinux' do
|
|
|
|
resource = MockLoader.new(:wrlinux).load_resource('port', 22)
|
|
|
|
_(resource.listening?).must_equal true
|
2015-12-08 12:46:20 +00:00
|
|
|
_(resource.protocols).must_equal %w{ tcp tcp6 }
|
|
|
|
_(resource.processes).must_equal ['sshd']
|
2015-12-03 03:08:49 +00:00
|
|
|
end
|
|
|
|
|
2015-09-23 13:19:48 +00:00
|
|
|
it 'verify running on undefined' do
|
|
|
|
resource = MockLoader.new(:undefined).load_resource('port', 22)
|
|
|
|
_(resource.listening?).must_equal false
|
2015-12-08 12:46:20 +00:00
|
|
|
_(resource.protocols).must_equal nil
|
|
|
|
_(resource.pids).must_equal nil
|
|
|
|
_(resource.processes).must_equal nil
|
2015-09-23 13:19:48 +00:00
|
|
|
end
|
2015-12-08 13:04:02 +00:00
|
|
|
|
|
|
|
it 'verify port and interface on Ubuntu 14.04' do
|
|
|
|
resource = MockLoader.new(:ubuntu1404).load_resource('port', '0.0.0.0', 22)
|
|
|
|
_(resource.listening?).must_equal true
|
|
|
|
_(resource.protocols).must_equal %w{ tcp }
|
|
|
|
_(resource.pids).must_equal [1]
|
|
|
|
_(resource.processes).must_equal ['sshd']
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'verify not listening port on interface on Ubuntu 14.04' do
|
|
|
|
resource = MockLoader.new(:ubuntu1404).load_resource('port', '127.0.0.1', 22)
|
|
|
|
_(resource.listening?).must_equal false
|
|
|
|
end
|
2016-01-28 13:47:46 +00:00
|
|
|
|
|
|
|
it 'verify port on Solaris 10' do
|
|
|
|
resource = MockLoader.new(:solaris10).load_resource('port', 22)
|
|
|
|
_(resource.listening?).must_equal true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'verify port on Solaris 11' do
|
|
|
|
resource = MockLoader.new(:solaris11).load_resource('port', 22)
|
|
|
|
_(resource.listening?).must_equal true
|
|
|
|
end
|
2015-09-23 13:19:48 +00:00
|
|
|
end
|