Skip to content

Commit

Permalink
Merge pull request #558 from yast/SLE-12-SP5-bsc-1159157
Browse files Browse the repository at this point in the history
[SLE-12-SP5] Do not crash on XML parsing errors
  • Loading branch information
imobachgs committed Dec 19, 2019
2 parents cce7a0c + 54828a5 commit 122b965
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 2 deletions.
7 changes: 7 additions & 0 deletions package/autoyast2.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Tue Dec 17 16:19:57 UTC 2019 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

- UI: Report XML parsing errors instead of just crashing
(bsc#1159157).
- 3.2.42

-------------------------------------------------------------------
Wed Nov 27 15:28:20 UTC 2019 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

Expand Down
2 changes: 1 addition & 1 deletion package/autoyast2.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


Name: autoyast2
Version: 3.2.41
Version: 3.2.42
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
3 changes: 2 additions & 1 deletion src/modules/Profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,8 @@ def ReadXML(file)
@current = XML.XMLToYCPFile(file)
end

if @current != {} && Builtins.size(@current) == 0
xml_error = XML.XMLError
if xml_error && !xml_error.empty?
# autoyast has read the autoyast configuration file but something went wrong
message = _(
"The XML parser reported an error while parsing the autoyast profile. The error message is:\n"
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/profiles/invalid.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE profile>
<profile xmlns="http://www.suse.com/1.0/yast2ns" xmlns:config="http://www.suse.com/1.0/configns">
<general>
</profile>
14 changes: 14 additions & 0 deletions test/fixtures/profiles/minimal.xml.asc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-----BEGIN PGP MESSAGE-----

jA0EBwMC3pVu9bV/fs7u0sDfAVP9uQYu878YhSbdllHtB3N9qf2peEdurg/u2ZMe
0Ns33iur6spH6WSapExX6I9pDw+ms07dwGWe55XF9crjbdfY1wKbP4+tVoQbrmAG
qmr6QWfKsYdxQ5d2YPn82phEPdwppXxSVHauIEr4+7eAHzsGUhZD4HV5DUiCr7UO
mAJcBKiP4Z8z/k6fOJ2FeIc5dUFzaZzc2FcY6TvyxFwAD0pd/EfHRGgb/YVZYuIR
wP/XS1NIt/q67G16k3BogdTT3dR5iNVekcHaou8TXw2X/Hd9F/TVlPXNUekuqc44
lqd2CpQNRGwQy7b37vxL/asWBrPYM+k0JdI/oprCAJLRgYCAoM2KjCHB+80CZ8bt
q8u0YjsEwEX2QQBw2E40H4LO/6JehTvRe2DAv5FzzuKUTUD3HsV1WgisA4XOZsO4
OkbhaMNefnMFPZB8mJvdtCWKjpwIGAaJWS+xio6/kIzjXAQSeJH8C1+5izTTgtuc
3S3iJ2NkyrGhEDxqeDfuJf5Vxz0YPRe/viZSkLQN2fvRR31uK0s34/yE150kbkB2
ew==
=0XLd
-----END PGP MESSAGE-----
72 changes: 72 additions & 0 deletions test/profile_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -369,4 +369,76 @@ def patterns_list
end
end
end

describe "#ReadXML" do
let(:path) { File.join(FIXTURES_PATH, "profiles", xml_file) }

before do
subject.main
end

context "when the file is valid" do
let(:xml_file) { "partitions.xml" }

it "returns true" do
expect(subject.ReadXML(path)).to eq(true)
end

it "imports the file content" do
expect(subject).to receive(:Import).with(Hash)
subject.ReadXML(path)
end
end

context "when the file content is invalid" do
let(:xml_file) { "invalid.xml" }

it "returns false" do
expect(subject.ReadXML(path)).to eq(false)
end

it "displays an error message" do
expect(Yast::Popup).to receive(:Error)
subject.ReadXML(path)
end

it "does not import the file content" do
expect(subject).to_not receive(:Import)
subject.ReadXML(path)
end
end

context "when the content is encrypted" do
let(:xml_file) { "profile.xml.asc" }

before do
allow(Yast::UI).to receive(:UserInput).and_return(:ok)
allow(Yast::UI).to receive(:QueryWidget).with(Id(:password), :Value)
.and_return("nots3cr3t")
allow(Yast::UI).to receive(:OpenDialog)
end

around do |example|
FileUtils.cp(File.join(FIXTURES_PATH, "profiles", "minimal.xml.asc"), path)
example.run
FileUtils.rm(path)
end

it "decrypts and imports the file content" do
expect(subject).to receive(:Import).with(Hash)
subject.ReadXML(path)
end

context "during the first stage" do
before do
allow(Yast::Stage).to receive(:initial).and_return(true)
end

it "saves the unencrypted content" do
subject.ReadXML(path)
expect(File.read(path)).to_not include("BEGIN PGP MESSAGE")
end
end
end
end
end

0 comments on commit 122b965

Please sign in to comment.