Skip to content

Commit

Permalink
Do not report an error when "silent-mode" is active
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dgdavid committed Nov 6, 2018
1 parent c2dd21f commit ba0e7b4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 18 deletions.
5 changes: 2 additions & 3 deletions src/lib/registration/connect_helpers.rb
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 ba0e7b4

Please sign in to comment.