Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
schubi2 committed Apr 26, 2024
1 parent 14e8393 commit 1cf70fe
Showing 1 changed file with 60 additions and 13 deletions.
73 changes: 60 additions & 13 deletions test/systemdboot_test.rb
Expand Up @@ -11,48 +11,90 @@
end

let(:destdir) { File.expand_path("data/", __dir__) }
let(:kerneldir) { File.join(destdir, "etc", "kernel") }
let(:cmdline_content) { "splash=silent quiet security=apparmor mitigations=off" }

before do
allow(Yast::BootStorage).to receive(:available_swap_partitions).and_return([])
allow(Yast::Arch).to receive(:architecture).and_return("x86_64")
allow(Yast::Package).to receive(:Available).and_return(true)
FileUtils.mkdir_p(kerneldir)
end

after do
FileUtils.remove_entry(kerneldir) if Dir.exist?(kerneldir)
end

describe "#read" do
it "reads bootloader flags from sysconfig" do
before do
expect(Bootloader::Systeminfo).to receive(:secure_boot_active?).and_return(true)
allow(Yast::Installation).to receive(:destdir).and_return(destdir)
end

it "reads bootloader flags from sysconfig" do
subject.read

expect(subject.secure_boot).to eq true
expect(subject.cpu_mitigations.to_human_string).to eq "offdd"
expect(subject.kernel_params.serialize).to eq "splash=silent quiet security=apparmor mitigations=off"
end

it "reads entries from /etc/kernel/cmdline" do
subject.read

expect(subject.cpu_mitigations.to_human_string).to eq "Off"
expect(subject.kernel_params.serialize).to eq cmdline_content
end
end

describe "#write" do
it "installs bootloader and creates menue entries" do
before do
allow(subject).to receive(:secure_boot).and_return(false)
allow(Yast::Stage).to receive(:initial).and_return(true)
allow(Yast::Installation).to receive(:destdir).and_return(destdir)
subject.kernel_params.replace(cmdline_content)
subject.menue_timeout = 10
end

it "installs the bootloader" do
allow(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "--verbose", "add-all-kernels")
allow_any_instance_of(CFA::SystemdBoot).to receive(:save)

# install bootloader
expect(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "--verbose", "install")

subject.write
end

it "writes kernel cmdline" do
allow(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "--verbose", "install")
allow(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "--verbose", "add-all-kernels")
allow_any_instance_of(CFA::SystemdBoot).to receive(:save)

subject.write
# Checking written kernel parameters
subject.read
expect(subject.cpu_mitigations.to_human_string).to eq "Off"
expect(subject.kernel_params.serialize).to eq cmdline_content
end

it "creates menue entries" do
allow(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "--verbose", "install")
allow_any_instance_of(CFA::SystemdBoot).to receive(:save)

# create menue entries
allow(Yast::Installation).to receive(:destdir).and_return(destdir)
expect(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "--verbose", "add-all-kernels")

subject.write
end

it "saves menue timeout" do
allow(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "--verbose", "install")
allow(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "--verbose", "add-all-kernels")

# Saving menue timeout
expect_any_instance_of(CFA::SystemdBoot).to receive(:save)

subject.menue_timeout = 10
subject.write
end
end
Expand All @@ -79,18 +121,23 @@
end

describe "#merge" do
it "overwrite secure boot and menue timeout if specified in merged one" do
it "overwrite secure boot, mitigations and menue timeout if specified in merged one" do
other_cmdline = "splash=silent quiet mitigations=auto"
other = described_class.new
other.secure_boot = true
other.menue_timeout = 12
other.kernel_params.replace(other_cmdline)

subject.secure_boot = false
subject.menue_timeout = 10
subject.kernel_params.replace(cmdline_content)

subject.merge(other)

expect(subject.secure_boot).to eq true
expect(subject.menue_timeout).to eq 12
expect(subject.cpu_mitigations.to_human_string).to eq "Auto"
expect(subject.kernel_params.serialize).to eq "security=apparmor splash=silent quiet mitigations=auto"
end
end
end

0 comments on commit 1cf70fe

Please sign in to comment.