2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
require "inspec/resource"
|
|
|
|
require "inspec/resources/grub_conf"
|
2015-12-22 03:38:49 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "Inspec::Resources::GrubConfig" do
|
2015-12-22 03:38:49 +00:00
|
|
|
|
2018-01-18 21:20:48 +00:00
|
|
|
# Grub2 with `GRUB_DEFAULT=0`
|
2019-06-11 22:24:35 +00:00
|
|
|
it "parses correctly with grub2 and `GRUB_DEfAULT=0`" do
|
|
|
|
resource = MockLoader.new(:centos7).load_resource("grub_conf")
|
2018-01-18 21:20:48 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
resource.kernel.must_include "/vmlinuz-yup-kernel-works"
|
|
|
|
resource.initrd.must_equal "/initramfs-yup-initrd-works"
|
2015-12-22 03:38:49 +00:00
|
|
|
end
|
|
|
|
|
2018-01-18 21:20:48 +00:00
|
|
|
# Grub2 with `GRUB_DEFAULT=saved`
|
2019-06-11 22:24:35 +00:00
|
|
|
it "parses correctly with grub2 and `saved` as the `GRUB_DEFAULT`" do
|
|
|
|
resource = MockLoader.new(:centos7).load_resource("grub_conf")
|
2018-01-18 21:20:48 +00:00
|
|
|
|
|
|
|
# Both Grub1 and Grub2 use `/etc/default/grub`.
|
|
|
|
# This overrides the Grub1 default for testing.
|
|
|
|
resource.instance_variable_set(
|
|
|
|
:@defaults_path,
|
2019-06-11 22:24:35 +00:00
|
|
|
"/etc/default/grub_with_saved"
|
2018-01-18 21:20:48 +00:00
|
|
|
)
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
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"
|
2015-12-22 03:38:49 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "parses correctly with grub2 and an invalid grubenv entry" do
|
|
|
|
resource = MockLoader.new(:centos7).load_resource("grub_conf")
|
2018-01-18 21:20:48 +00:00
|
|
|
|
|
|
|
# Both Grub1 and Grub2 use `/etc/default/grub`.
|
|
|
|
# This overrides the Grub1 default for testing.
|
|
|
|
resource.instance_variable_set(
|
|
|
|
:@defaults_path,
|
2019-06-11 22:24:35 +00:00
|
|
|
"/etc/default/grub_with_saved"
|
2018-01-18 21:20:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
resource.instance_variable_set(
|
|
|
|
:@grubenv_path,
|
2019-06-11 22:24:35 +00:00
|
|
|
"/boot/grub2/grubenv_invalid"
|
2018-01-18 21:20:48 +00:00
|
|
|
)
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
resource.kernel.must_include "/vmlinuz-yup-kernel-works"
|
|
|
|
resource.initrd.must_equal "/initramfs-yup-initrd-works"
|
2018-01-18 21:20:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Grub2 with a specified kernel
|
2019-06-11 22:24:35 +00:00
|
|
|
it "parses data correctly with grub2 and a specified kernel" do
|
2018-01-18 21:20:48 +00:00
|
|
|
resource = MockLoader.new(:centos7).load_resource(
|
2019-06-11 22:24:35 +00:00
|
|
|
"grub_conf",
|
|
|
|
"/boot/grub2/grub.cfg",
|
|
|
|
"CentOS Linux 7 (Core), with Linux 0-rescue"
|
2018-01-18 21:20:48 +00:00
|
|
|
)
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
resource.kernel.must_include "/vmlinuz-0-rescue"
|
|
|
|
resource.initrd.must_equal "/initramfs-0-rescue.img"
|
2015-12-22 03:38:49 +00:00
|
|
|
end
|
|
|
|
|
2018-01-18 21:20:48 +00:00
|
|
|
# Legacy Grub
|
2019-06-11 22:24:35 +00:00
|
|
|
it "parses correctly with grub1 (aka legacy-grub)" do
|
|
|
|
resource = MockLoader.new(:centos6).load_resource("grub_conf")
|
2018-01-18 21:20:48 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
resource.kernel.must_include "/vmlinuz-2.6.32-573.7.1.el6.x86_64"
|
|
|
|
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"
|
2015-12-22 03:38:49 +00:00
|
|
|
end
|
|
|
|
|
2018-01-18 21:20:48 +00:00
|
|
|
# Legacy Grub with a specified kernel
|
2019-06-11 22:24:35 +00:00
|
|
|
it "parses data correctly with grub1 and a specified kernel" do
|
2018-01-18 21:20:48 +00:00
|
|
|
resource = MockLoader.new(:centos6).load_resource(
|
2019-06-11 22:24:35 +00:00
|
|
|
"grub_conf",
|
|
|
|
"/etc/grub.conf",
|
|
|
|
"CentOS 6 (2.6.32-573.el6.x86_64)"
|
2018-01-18 21:20:48 +00:00
|
|
|
)
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
resource.kernel.must_include "/vmlinuz-2.6.32-573.el6.x86_64"
|
|
|
|
resource.initrd.must_equal "/initramfs-2.6.32-573.el6.x86_64.img"
|
|
|
|
resource.default.must_equal "0"
|
|
|
|
resource.timeout.must_equal "5"
|
2018-01-18 21:20:48 +00:00
|
|
|
end
|
2015-12-22 03:38:49 +00:00
|
|
|
end
|