2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
require "inspec/resource"
|
|
|
|
require "inspec/resources/package"
|
2015-09-08 22:05:05 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "Inspec::Resources::Package" do
|
2015-10-12 11:22:01 +00:00
|
|
|
# arch linux
|
2022-06-02 18:10:26 +00:00
|
|
|
it "generates the resource_id for current resource" do
|
|
|
|
resource = MockLoader.new(:arch).load_resource("package", "curl")
|
|
|
|
_(resource.resource_id).must_equal "curl"
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify arch linux package parsing" do
|
|
|
|
resource = MockLoader.new(:arch).load_resource("package", "curl")
|
2021-12-21 11:10:54 +00:00
|
|
|
pkg = { name: "curl", installed: true, version: "7.37.0-1", type: "pacman", only_version_no: "7.37.0" }
|
2015-10-12 11:22:01 +00:00
|
|
|
_(resource.installed?).must_equal true
|
2019-06-11 22:24:35 +00:00
|
|
|
_(resource.version).must_equal "7.37.0-1"
|
2015-10-12 11:22:01 +00:00
|
|
|
_(resource.info).must_equal pkg
|
2021-12-21 11:10:54 +00:00
|
|
|
_(resource.latest?).must_equal false
|
2015-10-12 11:22:01 +00:00
|
|
|
end
|
2015-10-12 08:38:11 +00:00
|
|
|
|
2015-10-12 11:22:01 +00:00
|
|
|
# ubuntu
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify ubuntu package parsing" do
|
2021-09-30 08:56:43 +00:00
|
|
|
resource = MockLoader.new(:ubuntu).load_resource("package", "curl")
|
2021-12-21 11:10:54 +00:00
|
|
|
pkg = { name: "curl", installed: true, held: false, version: "7.35.0-1ubuntu2", type: "deb", only_version_no: "7.35.0" }
|
2015-10-12 11:22:01 +00:00
|
|
|
_(resource.installed?).must_equal true
|
2017-08-18 15:29:23 +00:00
|
|
|
_(resource.held?).must_equal false
|
2019-06-11 22:24:35 +00:00
|
|
|
_(resource.version).must_equal "7.35.0-1ubuntu2"
|
2015-10-12 11:22:01 +00:00
|
|
|
_(resource.info).must_equal pkg
|
2021-12-21 11:10:54 +00:00
|
|
|
_(resource.latest?).must_equal false
|
2015-10-12 11:22:01 +00:00
|
|
|
end
|
2015-09-08 22:05:05 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify ubuntu package which is held" do
|
2021-09-30 08:56:43 +00:00
|
|
|
resource = MockLoader.new(:ubuntu).load_resource("package", "held-package")
|
2021-12-21 11:10:54 +00:00
|
|
|
pkg = { name: "held-package", installed: true, held: true, version: "1.2.3-1", type: "deb", only_version_no: "1.2.3" }
|
2017-08-18 15:29:23 +00:00
|
|
|
_(resource.installed?).must_equal true
|
|
|
|
_(resource.held?).must_equal true
|
2019-06-11 22:24:35 +00:00
|
|
|
_(resource.version).must_equal "1.2.3-1"
|
2017-08-18 15:29:23 +00:00
|
|
|
_(resource.info).must_equal pkg
|
|
|
|
end
|
|
|
|
|
2016-10-08 21:26:21 +00:00
|
|
|
# mint
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify mint package parsing" do
|
|
|
|
resource = MockLoader.new(:mint17).load_resource("package", "curl")
|
2021-12-21 11:10:54 +00:00
|
|
|
pkg = { name: "curl", installed: true, held: false, version: "7.35.0-1ubuntu2", type: "deb", only_version_no: "7.35.0" }
|
2016-10-08 21:26:21 +00:00
|
|
|
_(resource.installed?).must_equal true
|
2019-06-11 22:24:35 +00:00
|
|
|
_(resource.version).must_equal "7.35.0-1ubuntu2"
|
2016-10-08 21:26:21 +00:00
|
|
|
_(resource.info).must_equal pkg
|
|
|
|
end
|
|
|
|
|
2015-10-12 11:22:01 +00:00
|
|
|
# centos
|
2020-12-21 17:20:18 +00:00
|
|
|
describe "Rpm" do # rubocop:disable Metrics/BlockLength
|
2017-06-28 10:21:15 +00:00
|
|
|
let(:pkg) do
|
|
|
|
{
|
2019-06-11 22:24:35 +00:00
|
|
|
name: "curl",
|
2017-06-28 10:21:15 +00:00
|
|
|
installed: true,
|
2019-06-11 22:24:35 +00:00
|
|
|
version: "7.29.0-19.el7",
|
|
|
|
type: "rpm",
|
2021-12-22 08:18:05 +00:00
|
|
|
only_version_no: "7.29.0",
|
2017-06-28 10:21:15 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "can parse RPM package info" do
|
|
|
|
resource = MockLoader.new(:centos7).load_resource("package", "curl")
|
2017-06-28 10:21:15 +00:00
|
|
|
_(resource.installed?).must_equal true
|
2019-06-11 22:24:35 +00:00
|
|
|
_(resource.version).must_equal "7.29.0-19.el7"
|
2017-06-28 10:21:15 +00:00
|
|
|
_(resource.info).must_equal pkg
|
2021-12-21 11:10:54 +00:00
|
|
|
_(resource.latest?).must_equal true
|
2017-06-28 10:21:15 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "can build an `rpm` command containing `--dbpath`" do
|
2017-06-28 10:21:15 +00:00
|
|
|
resource = MockLoader.new(:centos7).load_resource(
|
2019-06-11 22:24:35 +00:00
|
|
|
"package",
|
|
|
|
"curl",
|
|
|
|
rpm_dbpath: "/var/lib/fake_rpmdb"
|
2017-06-28 10:21:15 +00:00
|
|
|
)
|
|
|
|
_(resource.installed?).must_equal true
|
2019-06-11 22:24:35 +00:00
|
|
|
_(resource.version).must_equal "7.29.0-19.el7"
|
2017-06-28 10:21:15 +00:00
|
|
|
_(resource.info).must_equal pkg
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "can set `resource_skipped` when `--rpmdb` path does not exist" do
|
2017-06-28 10:21:15 +00:00
|
|
|
resource = MockLoader.new(:centos7).load_resource(
|
2019-06-11 22:24:35 +00:00
|
|
|
"package",
|
|
|
|
"curl",
|
|
|
|
rpm_dbpath: "/var/lib/rpmdb_does_not_exist"
|
2017-06-28 10:21:15 +00:00
|
|
|
)
|
2017-11-06 18:28:53 +00:00
|
|
|
_(resource.resource_skipped?).must_equal true
|
2017-06-28 10:21:15 +00:00
|
|
|
end
|
2015-10-12 11:22:01 +00:00
|
|
|
end
|
2015-09-08 22:05:05 +00:00
|
|
|
|
2016-04-21 08:31:56 +00:00
|
|
|
# hpux
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify hpux package parsing" do
|
|
|
|
resource = MockLoader.new(:hpux).load_resource("package", "vim")
|
|
|
|
pkg = { name: "vim", installed: true, version: "7.4", type: "pkg" }
|
2016-04-21 08:31:56 +00:00
|
|
|
_(resource.installed?).must_equal true
|
2019-06-11 22:24:35 +00:00
|
|
|
_(resource.version).must_equal "7.4"
|
2016-04-21 08:31:56 +00:00
|
|
|
_(resource.info).must_equal pkg
|
|
|
|
end
|
|
|
|
|
2015-12-03 03:08:49 +00:00
|
|
|
# wrlinux
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify wrlinux package parsing" do
|
|
|
|
resource = MockLoader.new(:wrlinux).load_resource("package", "curl")
|
2021-12-21 11:10:54 +00:00
|
|
|
pkg = { name: "curl", installed: true, version: "7.29.0-19.el7", type: "rpm", only_version_no: "7.29.0" }
|
2015-12-03 03:08:49 +00:00
|
|
|
_(resource.installed?).must_equal true
|
2019-06-11 22:24:35 +00:00
|
|
|
_(resource.version).must_equal "7.29.0-19.el7"
|
2015-12-03 03:08:49 +00:00
|
|
|
_(resource.info).must_equal pkg
|
|
|
|
end
|
|
|
|
|
2015-10-12 11:22:01 +00:00
|
|
|
# windows
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify windows package parsing" do
|
|
|
|
resource = MockLoader.new(:windows).load_resource("package", "Chef Client v12.12.15")
|
2021-12-21 11:10:54 +00:00
|
|
|
pkg = { name: "Chef Client v12.12.15 ", installed: true, version: "12.12.15.1", type: "windows", only_version_no: "12.12.15.1" }
|
2015-10-12 11:22:01 +00:00
|
|
|
_(resource.installed?).must_equal true
|
2019-06-11 22:24:35 +00:00
|
|
|
_(resource.version).must_equal "12.12.15.1"
|
2015-10-12 11:22:01 +00:00
|
|
|
_(resource.info).must_equal pkg
|
2021-12-22 08:18:05 +00:00
|
|
|
_(resource.latest?).must_equal true
|
2015-10-12 11:22:01 +00:00
|
|
|
end
|
2015-09-23 14:11:48 +00:00
|
|
|
|
2016-01-28 13:47:46 +00:00
|
|
|
# solaris 10
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify solaris 10 package parsing" do
|
|
|
|
resource = MockLoader.new(:solaris10).load_resource("package", "SUNWzfsr")
|
|
|
|
pkg = { name: "SUNWzfsr", installed: true, version: "11.10.0-2006.05.18.01.46", type: "pkg" }
|
2016-01-28 13:47:46 +00:00
|
|
|
_(resource.installed?).must_equal true
|
2019-06-11 22:24:35 +00:00
|
|
|
_(resource.version).must_equal "11.10.0-2006.05.18.01.46"
|
2016-01-28 13:47:46 +00:00
|
|
|
_(resource.info).must_equal pkg
|
|
|
|
end
|
|
|
|
|
|
|
|
# solaris 11
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify solaris 11 package parsing" do
|
|
|
|
resource = MockLoader.new(:solaris11).load_resource("package", "system/file-system/zfs")
|
|
|
|
pkg = { name: "system/file-system/zfs", installed: true, version: "0.5.11-0.175.3.1.0.5.0", type: "pkg" }
|
2016-01-28 13:47:46 +00:00
|
|
|
_(resource.installed?).must_equal true
|
2019-06-11 22:24:35 +00:00
|
|
|
_(resource.version).must_equal "0.5.11-0.175.3.1.0.5.0"
|
2016-01-28 13:47:46 +00:00
|
|
|
_(resource.info).must_equal pkg
|
|
|
|
end
|
|
|
|
|
2017-01-02 16:52:20 +00:00
|
|
|
# darwin (brew)
|
2019-08-28 00:29:10 +00:00
|
|
|
it "can parse ouptut from 'brew' when package is installed" do
|
2020-07-01 22:35:23 +00:00
|
|
|
resource = MockLoader.new(:macos10_10).load_resource("package", "curl")
|
2021-12-21 11:10:54 +00:00
|
|
|
pkg = { name: "curl", installed: true, version: "7.52.1", type: "brew", latest_version: "7.52.1", only_version_no: "7.52.1" }
|
2017-01-02 16:52:20 +00:00
|
|
|
_(resource.installed?).must_equal true
|
2019-06-11 22:24:35 +00:00
|
|
|
_(resource.version).must_equal "7.52.1"
|
2017-01-02 16:52:20 +00:00
|
|
|
_(resource.info).must_equal pkg
|
2021-12-21 11:10:54 +00:00
|
|
|
_(resource.latest?).must_equal true
|
2017-01-02 16:52:20 +00:00
|
|
|
end
|
|
|
|
|
2019-08-28 00:29:10 +00:00
|
|
|
it "can parse ouptut from 'brew' when package is not installed but exists" do
|
2020-07-01 22:35:23 +00:00
|
|
|
resource = MockLoader.new(:macos10_10).load_resource("package", "nginx")
|
2018-02-23 14:01:14 +00:00
|
|
|
pkg = {}
|
|
|
|
_(resource.installed?).must_equal false
|
|
|
|
_(resource.version).must_be_nil
|
|
|
|
_(resource.info).must_equal pkg
|
|
|
|
end
|
|
|
|
|
2019-08-28 00:29:10 +00:00
|
|
|
it "returns {} when 'brew' exits non-zero" do
|
2020-07-01 22:35:23 +00:00
|
|
|
resource = MockLoader.new(:macos10_10).load_resource("package", "nope")
|
2018-02-23 14:01:14 +00:00
|
|
|
pkg = {}
|
|
|
|
_(resource.installed?).must_equal false
|
|
|
|
_(resource.version).must_be_nil
|
|
|
|
_(resource.info).must_equal pkg
|
|
|
|
end
|
|
|
|
|
2018-07-19 19:07:36 +00:00
|
|
|
# alpine
|
2019-06-11 22:24:35 +00:00
|
|
|
it "can parse Alpine packages" do
|
|
|
|
resource = MockLoader.new(:alpine).load_resource("package", "git")
|
2021-12-21 11:10:54 +00:00
|
|
|
pkg = { name: "git", installed: true, version: "2.15.0-r1", type: "pkg", only_version_no: "2.15.0" }
|
2018-07-19 19:07:36 +00:00
|
|
|
_(resource.installed?).must_equal true
|
2019-06-11 22:24:35 +00:00
|
|
|
_(resource.version).must_equal "2.15.0-r1"
|
2018-07-19 19:07:36 +00:00
|
|
|
_(resource.info).must_equal pkg
|
2021-12-21 11:10:54 +00:00
|
|
|
_(resource.latest?).must_equal false
|
2018-07-19 19:07:36 +00:00
|
|
|
end
|
|
|
|
|
2019-12-16 19:18:02 +00:00
|
|
|
# freebsd
|
|
|
|
it "can parse FreeBSD packages" do
|
|
|
|
resource = MockLoader.new(:freebsd11).load_resource("package", "vim-console")
|
2021-12-21 11:10:54 +00:00
|
|
|
pkg = { name: "vim-console", installed: true, version: "8.1.1954", type: "pkg", only_version_no: "8.1.1954" }
|
2019-12-16 19:18:02 +00:00
|
|
|
_(resource.installed?).must_equal true
|
|
|
|
_(resource.version).must_equal "8.1.1954"
|
|
|
|
_(resource.info).must_equal pkg
|
2021-12-21 11:10:54 +00:00
|
|
|
_(resource.latest?).must_equal true
|
2019-12-16 19:18:02 +00:00
|
|
|
end
|
|
|
|
|
2015-10-12 11:22:01 +00:00
|
|
|
# undefined
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify package handling on unsupported os" do
|
|
|
|
resource = MockLoader.new(:undefined).load_resource("package", "curl")
|
2018-01-16 22:27:31 +00:00
|
|
|
_(resource.info).must_equal({})
|
2017-12-15 18:52:41 +00:00
|
|
|
_(resource.resource_skipped?).must_equal true
|
2019-06-11 22:24:35 +00:00
|
|
|
_(resource.resource_exception_message).must_equal "The `package` resource is not supported on your OS yet."
|
2015-09-08 22:05:05 +00:00
|
|
|
end
|
|
|
|
end
|