Skip to content

Commit

Permalink
Merge 9cc98b9 into 0fa8527
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Dec 1, 2022
2 parents 0fa8527 + 9cc98b9 commit 024d8f5
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 8 deletions.
7 changes: 7 additions & 0 deletions package/autoyast2.changes
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Thu Dec 1 09:36:51 UTC 2022 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

- Avoid a potential crash when autoinst.ycp file is empty or
missing (bsc#1205732).
- 4.5.11

-------------------------------------------------------------------
Tue Nov 22 15:50:38 UTC 2022 - Martin Vidner <mvidner@suse.com>

Expand Down
2 changes: 1 addition & 1 deletion package/autoyast2.spec
Expand Up @@ -22,7 +22,7 @@
%endif

Name: autoyast2
Version: 4.5.10
Version: 4.5.11
Release: 0
Summary: YaST2 - Automated Installation
License: GPL-2.0-only
Expand Down
15 changes: 8 additions & 7 deletions src/modules/Profile.rb
Expand Up @@ -113,7 +113,7 @@ def main
Yast.include self, "autoinstall/xml.rb"

# The Complete current Profile
@current = {}
@current = Yast::ProfileHash.new

@changed = false

Expand Down Expand Up @@ -352,7 +352,7 @@ def create(modules, target: :default)
# @return [void]
def Reset
Builtins.y2milestone("Resetting profile contents")
@current = {}
@current = Yast::ProfileHash.new
nil
end

Expand Down Expand Up @@ -430,18 +430,19 @@ def SaveProfileStructure(parsedControlFile)
end

# Read YCP data as the control file
# @param parsedControlFile [Hash] ycp file
# @return [Boolean]
# @param parsedControlFile [String] path of the ycp file
# @return [Boolean] false when the file is empty or missing; true otherwise
def ReadProfileStructure(parsedControlFile)
@current = Convert.convert(
contents = Convert.convert(
SCR.Read(path(".target.ycp"), [parsedControlFile, {}]),
from: "any",
to: "map <string, any>"
)
if @current == {}
if contents == {}
@current = Yast::ProfileHash.new(contents)
return false
else
Import(@current)
Import(contents)
end

true
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/autoconf.ycp
@@ -0,0 +1,7 @@
$[
"general" : $[
"mode" : $[
"confirm" : false
]
]
]
2 changes: 2 additions & 0 deletions test/fixtures/empty-autoconf.ycp
@@ -0,0 +1,2 @@
$[
]
46 changes: 46 additions & 0 deletions test/profile_test.rb
Expand Up @@ -734,4 +734,50 @@ def reboot_scripts
end
end
end

describe "#ReadProfileStructure" do
context "when the file does not exist" do
let(:file_path) { FIXTURES_PATH.join("missing.ycp").to_s }

it "returns false" do
expect(subject.ReadProfileStructure(file_path)).to eq(false)
end

it "resets Profile.current" do
subject.Import("general" => { "self_update" => false })
subject.ReadProfileStructure(file_path)
expect(subject.current).to eq(Yast::ProfileHash.new)
end
end

context "when the structure is empty" do
let(:file_path) { FIXTURES_PATH.join("empty-autoconf.ycp").to_s }

it "returns false" do
expect(subject.ReadProfileStructure(file_path)).to eq(false)
end

it "resets Profile.current" do
subject.Import("general" => { "self_update" => false })
subject.ReadProfileStructure(file_path)
expect(subject.current).to eq(Yast::ProfileHash.new)
end
end

context "when there is some valid YCP content" do
let(:file_path) { FIXTURES_PATH.join("autoconf.ycp").to_s }

it "returns true" do
expect(subject.ReadProfileStructure(file_path)).to eq(true)
end

it "imports the file contents" do
subject.Import("general" => { "self_update" => false })
expect(subject).to receive(:Import).with(
Yast::ProfileHash.new("general" => { "mode" => { "confirm" => false } })
)
subject.ReadProfileStructure(file_path)
end
end
end
end

0 comments on commit 024d8f5

Please sign in to comment.