From a4fdce7301a640fb897ec0879af7d2dd2e2fb616 Mon Sep 17 00:00:00 2001 From: Brandon Dunne Date: Thu, 5 Dec 2013 16:41:05 -0500 Subject: [PATCH] Set the sslCACert option if the certificate RPM is installed. https://bugzilla.redhat.com/show_bug.cgi?id=1027396 --- lib/linux_admin/registration_system/rhn.rb | 14 ++++++++------ spec/rhn_spec.rb | 7 ++++++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/linux_admin/registration_system/rhn.rb b/lib/linux_admin/registration_system/rhn.rb index 832c65a..b187e6f 100644 --- a/lib/linux_admin/registration_system/rhn.rb +++ b/lib/linux_admin/registration_system/rhn.rb @@ -3,6 +3,7 @@ class LinuxAdmin class Rhn < RegistrationSystem SATELLITE5_SERVER_CERT_PATH = "pub/rhn-org-trusted-ssl-cert-1.0-1.noarch.rpm" + INSTALLED_SERVER_CERT_PATH = "/usr/share/rhn/RHN-ORG-TRUSTED-SSL-CERT" def registered? id = "" @@ -27,13 +28,14 @@ def register(options) end install_server_certificate(options[:server_url], SATELLITE5_SERVER_CERT_PATH) if options[:server_url] + certificate_installed = LinuxAdmin::Rpm.list_installed["rhn-org-trusted-ssl-cert"] - params["--proxy="] = options[:proxy_address] if options[:proxy_address] - params["--proxyUser="] = options[:proxy_username] if options[:proxy_username] - params["--proxyPassword="] = options[:proxy_password] if options[:proxy_password] - params["--serverUrl="] = options[:server_url] if options[:server_url] - params["--systemorgid="] = options[:org] if options[:server_url] && options[:org] - params["--sslCACert="] = options[:server_cert] if options[:server_cert] + params["--proxy="] = options[:proxy_address] if options[:proxy_address] + params["--proxyUser="] = options[:proxy_username] if options[:proxy_username] + params["--proxyPassword="] = options[:proxy_password] if options[:proxy_password] + params["--serverUrl="] = options[:server_url] if options[:server_url] + params["--systemorgid="] = options[:org] if options[:server_url] && options[:org] + params["--sslCACert="] = INSTALLED_SERVER_CERT_PATH if certificate_installed run!(cmd, :params => params) end diff --git a/spec/rhn_spec.rb b/spec/rhn_spec.rb index 0543cf6..20c702a 100644 --- a/spec/rhn_spec.rb +++ b/spec/rhn_spec.rb @@ -33,15 +33,17 @@ :server_cert => "/path/to/cert", } } - let(:run_params) { {:params=>{"--username="=>"SomeUser@SomeDomain.org", "--password="=>"SomePass", "--proxy="=>"1.2.3.4", "--proxyUser="=>"ProxyUser", "--proxyPassword="=>"ProxyPass", "--sslCACert="=>"/path/to/cert"}} } + let(:run_params) { {:params=>{"--username="=>"SomeUser@SomeDomain.org", "--password="=>"SomePass", "--proxy="=>"1.2.3.4", "--proxyUser="=>"ProxyUser", "--proxyPassword="=>"ProxyPass"}} } it "with server_url" do run_params.store_path(:params, "--systemorgid=", "2") run_params.store_path(:params, "--serverUrl=", "https://server.url") + run_params.store_path(:params, "--sslCACert=", "/usr/share/rhn/RHN-ORG-TRUSTED-SSL-CERT") base_options.store_path(:server_url, "https://server.url") described_class.any_instance.should_receive(:run!).once.with("rhnreg_ks", run_params) LinuxAdmin::Rpm.should_receive(:upgrade).with("http://server.url/pub/rhn-org-trusted-ssl-cert-1.0-1.noarch.rpm") + LinuxAdmin::Rpm.should_receive(:list_installed).and_return({"rhn-org-trusted-ssl-cert" => "1.0"}) described_class.new.register(base_options) end @@ -49,6 +51,7 @@ it "without server_url" do described_class.any_instance.should_receive(:run!).once.with("rhnreg_ks", run_params) described_class.any_instance.should_not_receive(:install_server_certificate) + LinuxAdmin::Rpm.should_receive(:list_installed).and_return({"rhn-org-trusted-ssl-cert" => nil}) described_class.new.register(base_options) end @@ -56,6 +59,8 @@ it "with activation key" do described_class.any_instance.should_receive(:run!).once.with("rhnreg_ks", {:params=>{"--activationkey="=>"123abc", "--proxy="=>"1.2.3.4", "--proxyUser="=>"ProxyUser", "--proxyPassword="=>"ProxyPass"}}) + LinuxAdmin::Rpm.should_receive(:list_installed).and_return({"rhn-org-trusted-ssl-cert" => nil}) + described_class.new.register( :activationkey => "123abc", :proxy_address => "1.2.3.4",