-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
check for old SMT server API when registration fails (bnc#889503)
display error about outdated SMT server - 3.1.106
- Loading branch information
Showing
8 changed files
with
123 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,4 +33,7 @@ def initialize(msg, service) | |
@service = service | ||
end | ||
end | ||
|
||
class DownloadError < RuntimeError | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
require "registration/downloader" | ||
require "uri" | ||
|
||
module Registration | ||
|
||
class SmtStatus | ||
include Yast::Logger | ||
|
||
attr_reader :url, :insecure | ||
|
||
def initialize(url, insecure: false) | ||
@url = url.is_a?(URI) ? url : URI(url) | ||
@insecure = insecure | ||
end | ||
|
||
# check whether (old) NCC API is present at the server | ||
def ncc_api_present? | ||
download_url = ncc_api_url | ||
log.info "Checking NCC API presence: #{download_url}" | ||
|
||
begin | ||
Downloader.download(download_url, insecure: insecure) | ||
log.info "NCC API found" | ||
return true | ||
rescue DownloadError | ||
log.info "Download failed, NCC API probably not present" | ||
return false | ||
end | ||
end | ||
|
||
private | ||
|
||
def ncc_api_url | ||
# create an URI copy, the URL will be modified | ||
ncc_url = url.dup | ||
|
||
# NCC API should provide "/center/regsvc?command=listproducts" query | ||
ncc_url.path = "/center/regsvc" | ||
ncc_url.query = "command=listproducts" | ||
|
||
ncc_url | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#! /usr/bin/env rspec | ||
|
||
require_relative "spec_helper" | ||
require_relative "yast_stubs" | ||
|
||
describe "Registration::SmtStatus" do | ||
before do | ||
stub_yast_require | ||
require "registration/smt_status" | ||
end | ||
|
||
let(:url) { "https://example.com" } | ||
subject { Registration::SmtStatus.new(url) } | ||
|
||
describe "#ncc_api_present?2" do | ||
let(:expected_url) { URI("https://example.com/center/regsvc?command=listproducts") } | ||
|
||
it "returns true when /center/regsvc?command=listproducts returns OK" do | ||
expect(Registration::Downloader).to receive(:download). | ||
with(expected_url, :insecure => false). | ||
and_return(true) | ||
|
||
expect(subject.ncc_api_present?).to be_true | ||
end | ||
|
||
it "returns false otherwise" do | ||
expect(Registration::Downloader).to receive(:download). | ||
with(expected_url, :insecure => false). | ||
and_raise(Registration::DownloadError) | ||
|
||
expect(subject.ncc_api_present?).to be_false | ||
end | ||
end | ||
|
||
end |