Skip to content

Commit

Permalink
Merge pull request #155 from yast/proxy_credentials
Browse files Browse the repository at this point in the history
Read proxy credentials from .curlrc file (bnc#885957)
  • Loading branch information
lslezak committed Aug 28, 2014
2 parents fc54f38 + fc31f41 commit 1877dde
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
7 changes: 7 additions & 0 deletions package/yast2-registration.changes
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Thu Aug 28 14:06:14 UTC 2014 - lslezak@suse.cz

- read proxy credentials from .curlrc file (bnc#885957)
- do not ask for network configuration in Autoyast mode
- 3.1.112

-------------------------------------------------------------------
Tue Aug 26 18:34:07 UTC 2014 - ancor@suse.com

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


Name: yast2-registration
Version: 3.1.111
Version: 3.1.112
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
4 changes: 2 additions & 2 deletions src/lib/registration/connect_helpers.rb
Expand Up @@ -66,9 +66,9 @@ def self.catch_registration_errors(message_prefix: "", show_update_hint: false,
true
rescue SocketError, Errno::ENETUNREACH => e
log.error "Network error: #{e.class}: #{e.message}"
# Error popup
if Yast::Mode.installation || Yast::Mode.update
if (Yast::Mode.installation || Yast::Mode.update) && !(Yast::Mode.autoinst || Yast::Mode.autoupgrade)
if Yast::Popup.YesNo(
# Error popup
_("Network is not configured, the registration server cannot be reached.\n" +
"Do you want to configure the network now?"))

Expand Down
7 changes: 7 additions & 0 deletions src/lib/registration/downloader.rb
Expand Up @@ -27,6 +27,7 @@
require "uri"
require "openssl"
require "registration/exceptions"
require "suse/toolkit/curlrc_dotfile"

module Registration

Expand All @@ -47,6 +48,12 @@ def self.download_file(file_url, insecure: false, redirection_count: 10)
file_url = URI(file_url) unless file_url.is_a?(URI)
http = Net::HTTP.new(file_url.host, file_url.port)

if http.proxy?
log.info "Reading proxy credentials..."
http.proxy_user = SUSE::Toolkit::CurlrcDotfile.new.username
http.proxy_pass = SUSE::Toolkit::CurlrcDotfile.new.password
end

# switch to HTTPS connection if needed
if file_url.is_a? URI::HTTPS
http.use_ssl = true
Expand Down
23 changes: 22 additions & 1 deletion test/downloader_spec.rb
Expand Up @@ -19,6 +19,7 @@

expect_any_instance_of(Net::HTTP).to receive(:request).
with(an_instance_of(Net::HTTP::Get)).and_return(index)
expect_any_instance_of(Net::HTTP).to receive(:proxy?).and_return(false)

expect(Registration::Downloader.download(url)).to eq("response")
end
Expand All @@ -33,6 +34,7 @@
# check for HTTPS setup
expect_any_instance_of(Net::HTTP).to receive(:use_ssl=).with(true)
expect_any_instance_of(Net::HTTP).to receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_PEER)
expect_any_instance_of(Net::HTTP).to receive(:proxy?).and_return(false)

https_url = "https://example.com"
expect(Registration::Downloader.download(https_url)).to eq("response")
Expand All @@ -44,6 +46,7 @@

expect_any_instance_of(Net::HTTP).to receive(:request).
with(an_instance_of(Net::HTTP::Get)).and_return(index)
expect_any_instance_of(Net::HTTP).to receive(:proxy?).and_return(false)

expect{Registration::Downloader.download(url)}.to raise_error Registration::DownloadError,
"Downloading #{url} failed: Not Found"
Expand All @@ -59,9 +62,27 @@
http = double()
expect(Net::HTTP).to receive(:new).twice.and_return(http)
expect(http).to receive(:request).twice.and_return(index1, index2)
expect(http).to receive(:proxy?).twice.and_return(false)

expect(Registration::Downloader.download(url)).to eq("response")
end
end

it "reads proxy credentials when proxy is used" do
user = "proxy_user"
password = "proxy_password"
index = Net::HTTPSuccess.new("1.1", 200, "OK")
expect(index).to receive(:body).and_return("response")

expect_any_instance_of(Net::HTTP).to receive(:request).
with(an_instance_of(Net::HTTP::Get)).and_return(index)
expect_any_instance_of(Net::HTTP).to receive(:proxy?).and_return(true)
expect_any_instance_of(SUSE::Toolkit::CurlrcDotfile).to receive(:username).and_return(user)
expect_any_instance_of(SUSE::Toolkit::CurlrcDotfile).to receive(:password).and_return(password)
expect_any_instance_of(Net::HTTP).to receive(:proxy_user=).with(user)
expect_any_instance_of(Net::HTTP).to receive(:proxy_pass=).with(password)

expect(Registration::Downloader.download(url)).to eq("response")
end

end
end

0 comments on commit 1877dde

Please sign in to comment.