mirror of
https://github.com/inspec/inspec
synced 2024-11-22 12:43:07 +00:00
Resource id added for filesystem, grub, group, gem and other resources
Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>
This commit is contained in:
parent
f2943b7bc8
commit
7b0b98edac
12 changed files with 58 additions and 0 deletions
|
@ -84,6 +84,10 @@ module Inspec::Resources
|
|||
info = @fsman.info(@partition)
|
||||
info[:name]
|
||||
end
|
||||
|
||||
def resource_id
|
||||
partition
|
||||
end
|
||||
end
|
||||
|
||||
class FsManagement
|
||||
|
|
|
@ -76,5 +76,9 @@ module Inspec::Resources
|
|||
def to_s
|
||||
"gem package #{@package_name}"
|
||||
end
|
||||
|
||||
def resource_id
|
||||
"#{@package_name}-#{version}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -154,6 +154,10 @@ module Inspec::Resources
|
|||
"Group #{@group}"
|
||||
end
|
||||
|
||||
def resource_id
|
||||
gid ? "#{@group}-#{gid}" : ""
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def flatten_entry(group_info, prop)
|
||||
|
|
|
@ -69,6 +69,10 @@ module Inspec::Resources
|
|||
"Grub Config"
|
||||
end
|
||||
|
||||
def resource_id
|
||||
@conf_path
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
######################################################################
|
||||
|
|
|
@ -130,6 +130,10 @@ module Inspec::Resources
|
|||
resource_name
|
||||
end
|
||||
|
||||
def resource_id
|
||||
port ? "#{hostname}-#{port}-#{protocol}" : hostname
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def ping
|
||||
|
|
|
@ -125,6 +125,10 @@ module Inspec::Resources
|
|||
def proxy
|
||||
opts.fetch(:proxy, nil)
|
||||
end
|
||||
|
||||
def resource_id
|
||||
@url
|
||||
end
|
||||
end
|
||||
|
||||
class Local < Base
|
||||
|
|
|
@ -14,6 +14,7 @@ describe "Inspec::Resources::FileSystemResource" do
|
|||
_(resource.type).must_equal "ext4"
|
||||
_(resource.free_kb).must_equal 20760728
|
||||
_(resource.percent_free).must_equal 68
|
||||
_(resource.resource_id).must_equal "/"
|
||||
end
|
||||
|
||||
# windows
|
||||
|
@ -25,5 +26,6 @@ describe "Inspec::Resources::FileSystemResource" do
|
|||
_(resource.type).must_equal "NTFS"
|
||||
_(resource.free_kb).must_equal 30000000
|
||||
_(resource.percent_free).must_equal 75
|
||||
_(resource.resource_id).must_equal "c:"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,6 +20,7 @@ describe "Inspec::Resources::Gem" do
|
|||
_(resource.installed?).must_equal true
|
||||
_(resource.info).must_equal pkg
|
||||
_(resource.gem_binary).must_equal "gem"
|
||||
_(resource.resource_id).must_equal "rubocop-0.33.0"
|
||||
end
|
||||
|
||||
it "specifying gem binary" do
|
||||
|
@ -34,6 +35,7 @@ describe "Inspec::Resources::Gem" do
|
|||
_(resource.installed?).must_equal true
|
||||
_(resource.info).must_equal pkg
|
||||
_(resource.gem_binary).must_equal "/opt/ruby-2.3.1/embedded/bin/gem"
|
||||
_(resource.resource_id).must_equal "pry-0.10.4"
|
||||
end
|
||||
|
||||
it "verify gem in :chef" do
|
||||
|
@ -48,6 +50,7 @@ describe "Inspec::Resources::Gem" do
|
|||
_(resource.installed?).must_equal true
|
||||
_(resource.info).must_equal pkg
|
||||
_(resource.gem_binary).must_equal "/opt/chef/embedded/bin/gem"
|
||||
_(resource.resource_id).must_equal "chef-sugar-3.4.0"
|
||||
end
|
||||
|
||||
it "verifies gem in :chef when multiple versions are installed" do
|
||||
|
@ -56,6 +59,7 @@ describe "Inspec::Resources::Gem" do
|
|||
_(resource.versions[0]).must_match(/3\.4/)
|
||||
_(resource.versions).wont_include(/2\.4/)
|
||||
_(resource.gem_binary).must_equal "/opt/chef/embedded/bin/gem"
|
||||
_(resource.resource_id).must_equal "chef-sugar-3.4.0"
|
||||
end
|
||||
|
||||
it "verify gem in :chef on windows" do
|
||||
|
@ -70,6 +74,7 @@ describe "Inspec::Resources::Gem" do
|
|||
_(resource.installed?).must_equal true
|
||||
_(resource.info).must_equal pkg
|
||||
_(resource.gem_binary).must_equal 'c:\opscode\chef\embedded\bin\gem.bat'
|
||||
_(resource.resource_id).must_equal "json-1.8.3"
|
||||
end
|
||||
|
||||
it "verify gem in :chef_server" do
|
||||
|
@ -84,5 +89,6 @@ describe "Inspec::Resources::Gem" do
|
|||
_(resource.installed?).must_equal true
|
||||
_(resource.info).must_equal pkg
|
||||
_(resource.gem_binary).must_equal "/opt/opscode/embedded/bin/gem"
|
||||
_(resource.resource_id).must_equal "knife-backup-0.0.12"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,24 +8,28 @@ describe "Inspec::Resources::Group" do
|
|||
resource = MockLoader.new(:ubuntu).load_resource("group", "root")
|
||||
_(resource.exists?).must_equal true
|
||||
_(resource.gid).must_equal 0
|
||||
_(resource.resource_id).must_equal "root-0"
|
||||
end
|
||||
|
||||
it "verify group on ubuntu with mixed case" do
|
||||
resource = MockLoader.new(:ubuntu).load_resource("group", "GroupWithCaps")
|
||||
_(resource.exists?).must_equal true
|
||||
_(resource.gid).must_equal 999
|
||||
_(resource.resource_id).must_equal "GroupWithCaps-999"
|
||||
end
|
||||
|
||||
it "verify group on ubuntu with members" do
|
||||
resource = MockLoader.new(:ubuntu).load_resource("group", "www-data")
|
||||
_(resource.exists?).must_equal true
|
||||
_(resource.members).must_equal "www-data,root"
|
||||
_(resource.resource_id).must_equal "www-data-33"
|
||||
end
|
||||
|
||||
it "verify group on ubuntu with members_array" do
|
||||
resource = MockLoader.new(:ubuntu).load_resource("group", "www-data")
|
||||
_(resource.exists?).must_equal true
|
||||
_(resource.members_array).must_equal %w{www-data root}
|
||||
_(resource.resource_id).must_equal "www-data-33"
|
||||
end
|
||||
|
||||
# ubuntu with non-existent group
|
||||
|
@ -33,6 +37,7 @@ describe "Inspec::Resources::Group" do
|
|||
resource = MockLoader.new(:ubuntu).load_resource("group", "nogroup")
|
||||
_(resource.exists?).must_equal false
|
||||
_(resource.gid).must_be_nil
|
||||
_(resource.resource_id).must_equal ""
|
||||
end
|
||||
|
||||
# mac
|
||||
|
|
|
@ -10,6 +10,7 @@ describe "Inspec::Resources::GrubConfig" do
|
|||
|
||||
_(resource.kernel).must_include "/vmlinuz-yup-kernel-works"
|
||||
_(resource.initrd).must_equal "/initramfs-yup-initrd-works"
|
||||
_(resource.resource_id).must_equal "/boot/grub2/grub.cfg"
|
||||
end
|
||||
|
||||
# Grub2 with `GRUB_DEFAULT=saved`
|
||||
|
@ -25,6 +26,7 @@ describe "Inspec::Resources::GrubConfig" do
|
|||
|
||||
_(resource.kernel).must_include "/vmlinuz-3.10.0-229.el7.x86_64"
|
||||
_(resource.initrd).must_equal "/initramfs-3.10.0-229.el7.x86_64.img"
|
||||
_(resource.resource_id).must_equal "/boot/grub2/grub.cfg"
|
||||
end
|
||||
|
||||
it "parses correctly with grub2 and an invalid grubenv entry" do
|
||||
|
@ -44,6 +46,7 @@ describe "Inspec::Resources::GrubConfig" do
|
|||
|
||||
_(resource.kernel).must_include "/vmlinuz-yup-kernel-works"
|
||||
_(resource.initrd).must_equal "/initramfs-yup-initrd-works"
|
||||
_(resource.resource_id).must_equal "/boot/grub2/grub.cfg"
|
||||
end
|
||||
|
||||
# Grub2 with a specified kernel
|
||||
|
@ -56,6 +59,7 @@ describe "Inspec::Resources::GrubConfig" do
|
|||
|
||||
_(resource.kernel).must_include "/vmlinuz-0-rescue"
|
||||
_(resource.initrd).must_equal "/initramfs-0-rescue.img"
|
||||
_(resource.resource_id).must_equal "/boot/grub2/grub.cfg"
|
||||
end
|
||||
|
||||
# Legacy Grub
|
||||
|
@ -66,6 +70,7 @@ describe "Inspec::Resources::GrubConfig" do
|
|||
_(resource.initrd).must_equal "/initramfs-2.6.32-573.7.1.el6.x86_64.img"
|
||||
_(resource.default).must_equal "0"
|
||||
_(resource.timeout).must_equal "5"
|
||||
_(resource.resource_id).must_equal "/etc/grub.conf"
|
||||
end
|
||||
|
||||
# Legacy Grub with a specified kernel
|
||||
|
@ -80,6 +85,7 @@ describe "Inspec::Resources::GrubConfig" do
|
|||
_(resource.initrd).must_equal "/initramfs-2.6.32-573.el6.x86_64.img"
|
||||
_(resource.default).must_equal "0"
|
||||
_(resource.timeout).must_equal "5"
|
||||
_(resource.resource_id).must_equal "/etc/grub.conf"
|
||||
end
|
||||
|
||||
it "parses data with no identations correctly with grub1" do
|
||||
|
@ -93,5 +99,6 @@ describe "Inspec::Resources::GrubConfig" do
|
|||
_(resource.initrd).must_equal "/initramfs-2.6.32-573.el6.x86_64.img"
|
||||
_(resource.default).must_equal "0"
|
||||
_(resource.timeout).must_equal "5"
|
||||
_(resource.resource_id).must_equal "/etc/non_indented_grub.conf"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,6 +10,7 @@ describe "Inspec::Resources::Host" do
|
|||
_(resource.reachable?).must_equal true
|
||||
_(resource.ipaddress).must_equal ["12.34.56.78", "2606:2800:220:1:248:1893:25c8:1946"]
|
||||
_(resource.to_s).must_equal "Host example.com"
|
||||
_(resource.resource_id).must_equal "example.com"
|
||||
end
|
||||
|
||||
it "check host ping on centos 7" do
|
||||
|
@ -18,6 +19,7 @@ describe "Inspec::Resources::Host" do
|
|||
_(resource.reachable?).must_equal true
|
||||
_(resource.ipaddress).must_equal ["12.34.56.78", "2606:2800:220:1:248:1893:25c8:1946"]
|
||||
_(resource.to_s).must_equal "Host example.com"
|
||||
_(resource.resource_id).must_equal "example.com"
|
||||
end
|
||||
|
||||
it "check host ping on darwin" do
|
||||
|
@ -26,6 +28,7 @@ describe "Inspec::Resources::Host" do
|
|||
_(resource.reachable?).must_equal true
|
||||
_(resource.ipaddress).must_equal ["12.34.56.78", "2606:2800:220:1:248:1893:25c8:1946"]
|
||||
_(resource.to_s).must_equal "Host example.com"
|
||||
_(resource.resource_id).must_equal "example.com"
|
||||
end
|
||||
|
||||
it "check host ping on windows" do
|
||||
|
@ -34,6 +37,7 @@ describe "Inspec::Resources::Host" do
|
|||
_(resource.reachable?).must_equal false
|
||||
_(resource.ipaddress).must_equal ["134.170.188.221", "2404:6800:4009:827::200e"]
|
||||
_(resource.to_s).must_equal "Host microsoft.com"
|
||||
_(resource.resource_id).must_equal "microsoft.com"
|
||||
end
|
||||
|
||||
it "check host ping on unsupported os" do
|
||||
|
@ -42,6 +46,7 @@ describe "Inspec::Resources::Host" do
|
|||
_(resource.reachable?).must_equal false
|
||||
_(resource.ipaddress).must_be_nil
|
||||
_(resource.to_s).must_equal "Host example.com"
|
||||
_(resource.resource_id).must_equal "example.com"
|
||||
end
|
||||
|
||||
it "check host tcp on ubuntu" do
|
||||
|
@ -50,6 +55,7 @@ describe "Inspec::Resources::Host" do
|
|||
_(resource.reachable?).must_equal true
|
||||
_(resource.ipaddress).must_equal ["12.34.56.78", "2606:2800:220:1:248:1893:25c8:1946"]
|
||||
_(resource.to_s).must_equal "Host example.com port 1234 proto tcp"
|
||||
_(resource.resource_id).must_equal "example.com-1234-tcp"
|
||||
end
|
||||
|
||||
it "check host udp on ubuntu" do
|
||||
|
@ -58,6 +64,7 @@ describe "Inspec::Resources::Host" do
|
|||
_(resource.reachable?).must_equal true
|
||||
_(resource.ipaddress).must_equal ["12.34.56.78", "2606:2800:220:1:248:1893:25c8:1946"]
|
||||
_(resource.to_s).must_equal "Host example.com port 1234 proto udp"
|
||||
_(resource.resource_id).must_equal "example.com-1234-udp"
|
||||
end
|
||||
|
||||
it "check host tcp on centos 7" do
|
||||
|
@ -66,6 +73,7 @@ describe "Inspec::Resources::Host" do
|
|||
_(resource.reachable?).must_equal true
|
||||
_(resource.ipaddress).must_equal ["12.34.56.78", "2606:2800:220:1:248:1893:25c8:1946"]
|
||||
_(resource.to_s).must_equal "Host example.com port 1234 proto tcp"
|
||||
_(resource.resource_id).must_equal "example.com-1234-tcp"
|
||||
end
|
||||
|
||||
it "check host udp on centos 7" do
|
||||
|
@ -74,6 +82,7 @@ describe "Inspec::Resources::Host" do
|
|||
_(resource.reachable?).must_equal true
|
||||
_(resource.ipaddress).must_equal ["12.34.56.78", "2606:2800:220:1:248:1893:25c8:1946"]
|
||||
_(resource.to_s).must_equal "Host example.com port 1234 proto udp"
|
||||
_(resource.resource_id).must_equal "example.com-1234-udp"
|
||||
end
|
||||
|
||||
it "check host tcp on darwin" do
|
||||
|
@ -82,6 +91,7 @@ describe "Inspec::Resources::Host" do
|
|||
_(resource.reachable?).must_equal true
|
||||
_(resource.ipaddress).must_equal ["12.34.56.78", "2606:2800:220:1:248:1893:25c8:1946"]
|
||||
_(resource.to_s).must_equal "Host example.com port 1234 proto tcp"
|
||||
_(resource.resource_id).must_equal "example.com-1234-tcp"
|
||||
end
|
||||
|
||||
it "check host udp on darwin" do
|
||||
|
@ -90,6 +100,7 @@ describe "Inspec::Resources::Host" do
|
|||
_(resource.reachable?).must_equal true
|
||||
_(resource.ipaddress).must_equal ["12.34.56.78", "2606:2800:220:1:248:1893:25c8:1946"]
|
||||
_(resource.to_s).must_equal "Host example.com port 1234 proto udp"
|
||||
_(resource.resource_id).must_equal "example.com-1234-udp"
|
||||
end
|
||||
|
||||
it "check host tcp on windows" do
|
||||
|
@ -98,6 +109,7 @@ describe "Inspec::Resources::Host" do
|
|||
_(resource.reachable?).must_equal true
|
||||
_(resource.ipaddress).must_equal ["134.170.188.221", "2404:6800:4009:827::200e"]
|
||||
_(resource.to_s).must_equal "Host microsoft.com port 1234 proto tcp"
|
||||
_(resource.resource_id).must_equal "microsoft.com-1234-tcp"
|
||||
end
|
||||
|
||||
it "check host tcp on unsupported os" do
|
||||
|
@ -106,6 +118,7 @@ describe "Inspec::Resources::Host" do
|
|||
_(resource.reachable?).must_equal false
|
||||
_(resource.ipaddress).must_be_nil
|
||||
_(resource.to_s).must_equal "Host example.com port 1234 proto tcp"
|
||||
_(resource.resource_id).must_equal "example.com-1234-tcp"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ describe "Inspec::Resources::Http" do
|
|||
|
||||
_(worker.status).must_equal 200
|
||||
_(worker.body).must_equal "pong"
|
||||
_(worker.resource_id).must_equal "pong"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue