From e4046db7efb9d50fd1877f9abf4aac1d4d39615f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Imobach=20Gonz=C3=A1lez=20Sosa?= Date: Tue, 17 Dec 2019 16:16:26 +0000 Subject: [PATCH 1/3] Fix the detection of XML parsing errors --- src/modules/Profile.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/modules/Profile.rb b/src/modules/Profile.rb index a08dd1ccc..395923323 100644 --- a/src/modules/Profile.rb +++ b/src/modules/Profile.rb @@ -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" From 20e70bc5bc220aa6012b3d14c5cbd54186b41af4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Imobach=20Gonz=C3=A1lez=20Sosa?= Date: Tue, 17 Dec 2019 16:20:51 +0000 Subject: [PATCH 2/3] Bump version and update changes file --- package/autoyast2.changes | 7 +++++++ package/autoyast2.spec | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/package/autoyast2.changes b/package/autoyast2.changes index b5b6210e0..517dfae2a 100644 --- a/package/autoyast2.changes +++ b/package/autoyast2.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Tue Dec 17 16:19:57 UTC 2019 - Imobach Gonzalez Sosa + +- UI: Report XML parsing errors instead of just crashing + (bsc#1159157). +- 3.2.36.5 + ------------------------------------------------------------------- Wed Nov 27 15:28:20 UTC 2019 - Imobach Gonzalez Sosa diff --git a/package/autoyast2.spec b/package/autoyast2.spec index e667b4cec..111ac1a7e 100644 --- a/package/autoyast2.spec +++ b/package/autoyast2.spec @@ -17,7 +17,7 @@ Name: autoyast2 -Version: 3.2.36.4 +Version: 3.2.36.5 Release: 0 BuildRoot: %{_tmppath}/%{name}-%{version}-build From 451bc41b2ca9ea07df08a4a070c3bb2f73a58901 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Imobach=20Gonz=C3=A1lez=20Sosa?= Date: Wed, 18 Dec 2019 11:17:06 +0000 Subject: [PATCH 3/3] Add tests for Profile.ReadXML --- test/fixtures/profiles/invalid.xml | 5 ++ test/fixtures/profiles/minimal.xml.asc | 14 +++++ test/profile_test.rb | 72 ++++++++++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 test/fixtures/profiles/invalid.xml create mode 100644 test/fixtures/profiles/minimal.xml.asc diff --git a/test/fixtures/profiles/invalid.xml b/test/fixtures/profiles/invalid.xml new file mode 100644 index 000000000..dd0ffe97c --- /dev/null +++ b/test/fixtures/profiles/invalid.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/test/fixtures/profiles/minimal.xml.asc b/test/fixtures/profiles/minimal.xml.asc new file mode 100644 index 000000000..94092b909 --- /dev/null +++ b/test/fixtures/profiles/minimal.xml.asc @@ -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----- diff --git a/test/profile_test.rb b/test/profile_test.rb index 6ac39a2e1..9606e1309 100755 --- a/test/profile_test.rb +++ b/test/profile_test.rb @@ -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