From ba0e7b45dc8177968052bf1275da156c47f6faae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20D=C3=ADaz=20Gonz=C3=A1lez?= Date: Tue, 6 Nov 2018 13:47:27 +0000 Subject: [PATCH 1/2] Do not report an error when "silent-mode" is active At the time to catch a 402 registration error, do not report it if the `silent_reg_code_mismatch` was setted, no matter what contains the error message received. Related to bsc#1091825. --- src/lib/registration/connect_helpers.rb | 5 +-- test/connect_helpers_spec.rb | 50 +++++++++++++++++-------- 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/src/lib/registration/connect_helpers.rb b/src/lib/registration/connect_helpers.rb index 1ee4ff74a..b97b25753 100644 --- a/src/lib/registration/connect_helpers.rb +++ b/src/lib/registration/connect_helpers.rb @@ -103,9 +103,8 @@ def self.catch_registration_errors(message_prefix: "", check_smt_api(error_msg) report_error(message_prefix + _("Connection to registration server failed."), error_msg) when 422 - if silent_reg_code_mismatch && e.response.body["error"] =~ - /does not include the requested product/ - log.info "Reg code does not work for this product, that's OK" + if silent_reg_code_mismatch + log.info "Reg code does not work for this product." else # Error popup report_error(message_prefix + _("Connection to registration server failed."), error_msg) diff --git a/test/connect_helpers_spec.rb b/test/connect_helpers_spec.rb index 1d4fb4723..c9ce36d23 100755 --- a/test/connect_helpers_spec.rb +++ b/test/connect_helpers_spec.rb @@ -113,29 +113,49 @@ def api_error(code: 400, headers: {}, body: {}) include_examples "old registration server", JSON::ParserError.new("error message") end - context "error 404 is received" do - include_examples "old registration server", api_error(code: 404) - end + [400, 401, 500, 42].each do |error_code| + exception = api_error(code: error_code) - [400, 401, 422, 500, 42].each do |error_code| context "error #{error_code} is received" do - include_examples "reports error and returns false", api_error(code: error_code) + include_examples "reports error and returns false", exception + + it "logs the exception" do + expect(helpers.log).to receive(:error).with(/#{exception.response.inspect}/) + + helpers.catch_registration_errors { raise exception } + end end end - context "'silent_reg_code_mismatch' parameter is set and a mismatch error occurs" do - before do - allow(Registration::UrlHelpers).to receive(:registration_url) - .and_return(SUSE::Connect::YaST::DEFAULT_URL) + context "error 404 is received" do + include_examples "old registration server", api_error(code: 404) + end + + context "error 422 is received" do + context "and 'silent_reg_code_mismatch' param is not set" do + include_examples "reports error and returns false", api_error(code: 422) end - it "does not report an error and returns false" do - msg = "Subscription does not include the requested product 'Fountain Wristwatch'" - exc = api_error(code: 422, body: { "error" => msg }) + context "and 'silent_reg_code_mismatch' param is set" do + let(:error_msg) { "Something went wrong" } + let(:exception) { api_error(code: 422, body: { "error" => error_msg }) } + + before do + allow(Registration::UrlHelpers).to receive(:registration_url) + .and_return(SUSE::Connect::YaST::DEFAULT_URL) + end + + it "does not report an error" do + expect(Yast::Report).to_not receive(:Error) - expect(Yast::Report).to_not receive(:Error) - expect(helpers.catch_registration_errors(silent_reg_code_mismatch: true) { raise exc }) - .to eq(false) + helpers.catch_registration_errors(silent_reg_code_mismatch: true) { raise exception } + end + + it "returns false" do + expect( + helpers.catch_registration_errors(silent_reg_code_mismatch: true) { raise exception } + ).to eq(false) + end end end From fa565a22189e0568af3b5e2fa46329f0824b5d85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20D=C3=ADaz=20Gonz=C3=A1lez?= Date: Tue, 6 Nov 2018 14:01:11 +0000 Subject: [PATCH 2/2] Update version and changelog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Ladislav Slezák --- package/yast2-registration.changes | 8 ++++++++ package/yast2-registration.spec | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/package/yast2-registration.changes b/package/yast2-registration.changes index 1cea401ac..549986ac3 100644 --- a/package/yast2-registration.changes +++ b/package/yast2-registration.changes @@ -1,3 +1,11 @@ +------------------------------------------------------------------- +Tue Nov 6 13:56:48 UTC 2018 - dgonzalez@suse.com + +- Do not display a connection error when automatically trying to + use the base product registration code for the extensions + (bsc#1091825). +- 4.1.6 + ------------------------------------------------------------------- Tue Oct 16 15:35:43 CEST 2018 - schubi@suse.de diff --git a/package/yast2-registration.spec b/package/yast2-registration.spec index 2a89cb1ed..fe6510811 100644 --- a/package/yast2-registration.spec +++ b/package/yast2-registration.spec @@ -17,7 +17,7 @@ Name: yast2-registration -Version: 4.1.5 +Version: 4.1.6 Release: 0 BuildRoot: %{_tmppath}/%{name}-%{version}-build