Skip to content

Commit

Permalink
Merge fa565a2 into c2dd21f
Browse files Browse the repository at this point in the history
  • Loading branch information
dgdavid committed Nov 6, 2018
2 parents c2dd21f + fa565a2 commit 53afd57
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 19 deletions.
8 changes: 8 additions & 0 deletions 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

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-registration.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2-registration
Version: 4.1.5
Version: 4.1.6
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
5 changes: 2 additions & 3 deletions src/lib/registration/connect_helpers.rb
Expand Up @@ -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)
Expand Down
50 changes: 35 additions & 15 deletions test/connect_helpers_spec.rb
Expand Up @@ -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

Expand Down

0 comments on commit 53afd57

Please sign in to comment.