2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
require "inspec/resource"
|
|
|
|
require "inspec/resources/platform"
|
2018-01-02 19:04:13 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "Inspec::Resources::Platform" do
|
2021-09-29 06:45:39 +00:00
|
|
|
let(:resource) { MockLoader.new(:ubuntu).load_resource("platform") }
|
2018-01-02 19:04:13 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify platform parsing on Ubuntu" do
|
|
|
|
_(resource.name).must_equal "ubuntu"
|
|
|
|
_(resource.family).must_equal "debian"
|
2021-09-29 06:45:39 +00:00
|
|
|
_(resource.release).must_equal "20.04"
|
2019-06-11 22:24:35 +00:00
|
|
|
_(resource.arch).must_equal "x86_64"
|
2018-01-02 19:04:13 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify platform hash parsing on Ubuntu" do
|
|
|
|
_(resource[:name]).must_equal "ubuntu"
|
|
|
|
_(resource[:family]).must_equal "debian"
|
2021-09-29 06:45:39 +00:00
|
|
|
_(resource[:release]).must_equal "20.04"
|
2019-06-11 22:24:35 +00:00
|
|
|
_(resource[:arch]).must_equal "x86_64"
|
2018-01-02 19:04:13 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify platform families" do
|
|
|
|
expect = %w{debian linux unix os}
|
2018-01-02 19:04:13 +00:00
|
|
|
_(resource.families).must_equal expect
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify platform? responds correctly" do
|
|
|
|
_(resource.platform?("windows")).must_equal false
|
|
|
|
_(resource.platform?("unix")).must_equal true
|
|
|
|
_(resource.platform?("ubuntu")).must_equal true
|
|
|
|
_(resource.platform?("mac_os_x")).must_equal false
|
2018-01-02 19:04:13 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify family? responds correctly" do
|
|
|
|
_(resource.in_family?("windows")).must_equal false
|
|
|
|
_(resource.in_family?("unix")).must_equal true
|
|
|
|
_(resource.in_family?("ubuntu")).must_equal false
|
|
|
|
_(resource.in_family?("mac_os_x")).must_equal false
|
2018-01-02 19:04:13 +00:00
|
|
|
end
|
|
|
|
|
2019-12-26 22:01:17 +00:00
|
|
|
it "accept an empty supports collection" do
|
|
|
|
supports = []
|
|
|
|
_(resource).must_be :supported?, supports
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify supported? with multiple families" do
|
2018-01-02 19:04:13 +00:00
|
|
|
supports = [
|
2019-06-11 22:24:35 +00:00
|
|
|
{ os_family: "windows" },
|
2019-07-09 00:20:30 +00:00
|
|
|
{ os_family: "unix" },
|
2018-01-02 19:04:13 +00:00
|
|
|
]
|
2019-12-26 22:01:17 +00:00
|
|
|
_(resource).must_be :supported?, supports
|
2018-01-02 19:04:13 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "loads a profile which supports multiple names" do
|
2018-01-02 19:04:13 +00:00
|
|
|
supports = [
|
2019-06-11 22:24:35 +00:00
|
|
|
{ 'os-family': "windows", 'os-name': "windows_2000" },
|
2019-07-09 00:20:30 +00:00
|
|
|
{ 'os-family': "unix", 'os-name': "ubuntu" },
|
2018-01-02 19:04:13 +00:00
|
|
|
]
|
2019-12-26 22:01:17 +00:00
|
|
|
_(resource).must_be :supported?, supports
|
2018-01-02 19:04:13 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "reject a profile which supports multiple families" do
|
2018-01-02 19:04:13 +00:00
|
|
|
supports = [
|
2019-06-11 22:24:35 +00:00
|
|
|
{ os_family: "windows" },
|
2019-07-09 00:20:30 +00:00
|
|
|
{ os_family: "redhat" },
|
2018-01-02 19:04:13 +00:00
|
|
|
]
|
2019-12-26 22:01:17 +00:00
|
|
|
_(resource).wont_be :supported?, supports
|
2018-01-02 19:04:13 +00:00
|
|
|
end
|
|
|
|
|
2021-09-29 06:45:39 +00:00
|
|
|
it "loads a profile which supports release 20.04" do
|
2018-01-02 19:04:13 +00:00
|
|
|
supports = [
|
2019-06-11 22:24:35 +00:00
|
|
|
{ 'os-family': "windows", 'os-name': "windows_2000" },
|
2021-09-29 06:45:39 +00:00
|
|
|
{ 'os-name': "ubuntu", 'release': "20.04" },
|
2018-01-02 19:04:13 +00:00
|
|
|
]
|
2019-12-26 22:01:17 +00:00
|
|
|
_(resource).must_be :supported?, supports
|
2018-01-02 19:04:13 +00:00
|
|
|
end
|
|
|
|
|
2021-09-29 06:45:39 +00:00
|
|
|
it "loads a profile which supports release 20.*" do
|
2018-01-02 19:04:13 +00:00
|
|
|
supports = [
|
2019-06-11 22:24:35 +00:00
|
|
|
{ 'os-family': "windows", 'os-name': "windows_2000" },
|
2021-09-29 06:45:39 +00:00
|
|
|
{ 'os-name': "ubuntu", 'release': "20.*" },
|
2018-01-02 19:04:13 +00:00
|
|
|
]
|
2019-12-26 22:01:17 +00:00
|
|
|
_(resource).must_be :supported?, supports
|
2018-01-02 19:04:13 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "loads a profile which supports release *.04" do
|
2018-01-02 19:04:13 +00:00
|
|
|
supports = [
|
2019-06-11 22:24:35 +00:00
|
|
|
{ 'os-family': "windows", 'os-name': "windows_2000" },
|
2019-07-09 00:20:30 +00:00
|
|
|
{ 'os-name': "ubuntu", 'release': "*.04" },
|
2018-01-02 19:04:13 +00:00
|
|
|
]
|
2019-12-26 22:01:17 +00:00
|
|
|
_(resource).must_be :supported?, supports
|
2018-01-02 19:04:13 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "reject a profile which supports release 12.*" do
|
2018-01-02 19:04:13 +00:00
|
|
|
supports = [
|
2019-06-11 22:24:35 +00:00
|
|
|
{ 'os-family': "windows", 'os-name': "windows_2000" },
|
2019-07-09 00:20:30 +00:00
|
|
|
{ 'os-name': "ubuntu", 'release': "12.*" },
|
2018-01-02 19:04:13 +00:00
|
|
|
]
|
2019-12-26 22:01:17 +00:00
|
|
|
_(resource).wont_be :supported?, supports
|
2018-01-02 19:04:13 +00:00
|
|
|
end
|
2020-11-08 20:24:43 +00:00
|
|
|
|
|
|
|
let(:resource2) { MockLoader.new(:windows2016).load_resource("platform") }
|
|
|
|
it "loads a profile which supports platform-name windows_server_2016*" do
|
|
|
|
supports = [
|
|
|
|
{ 'platform-name': "windows_server_2016*" },
|
|
|
|
]
|
|
|
|
_(resource2).must_be :supported?, supports
|
|
|
|
end
|
|
|
|
|
|
|
|
it "loads a profile which supports platform-name windows_server_2016*" do
|
|
|
|
supports = [
|
|
|
|
{ 'platform-name': "*2016*" },
|
|
|
|
]
|
|
|
|
_(resource2).must_be :supported?, supports
|
|
|
|
end
|
|
|
|
|
|
|
|
it "reject a profile which supports platform-name not matching regex windows_server_2016*" do
|
|
|
|
supports = [
|
|
|
|
{ 'platform-name': "*2019*" },
|
|
|
|
]
|
|
|
|
_(resource2).wont_be :supported?, supports
|
|
|
|
end
|
|
|
|
|
2018-01-02 19:04:13 +00:00
|
|
|
end
|