diff --git a/lib/linux_admin/registration_system.rb b/lib/linux_admin/registration_system.rb index bfc3572..cf273e9 100644 --- a/lib/linux_admin/registration_system.rb +++ b/lib/linux_admin/registration_system.rb @@ -39,6 +39,12 @@ def self.white_list_methods end end private_class_method :white_list_methods + + def install_server_certificate(server, cert_path) + host = server.start_with?("http") ? URI.parse(server).host : server + + LinuxAdmin::Rpm.upgrade("http://#{host}/#{cert_path}") + end end end diff --git a/lib/linux_admin/registration_system/rhn.rb b/lib/linux_admin/registration_system/rhn.rb index b7d3da4..6612c16 100644 --- a/lib/linux_admin/registration_system/rhn.rb +++ b/lib/linux_admin/registration_system/rhn.rb @@ -2,6 +2,8 @@ class LinuxAdmin class Rhn < RegistrationSystem + SATELLITE5_SERVER_CERT_PATH = "pub/rhn-org-trusted-ssl-cert-1.0-1.noarch.rpm" + def registered? id = "" if File.exists?(systemid_file) @@ -24,6 +26,8 @@ def register(options) raise ArgumentError, "activation key or username and password are required" end + install_server_certificate(options[:server_url], SATELLITE5_SERVER_CERT_PATH) if options[:server_url] + 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] diff --git a/lib/linux_admin/registration_system/subscription_manager.rb b/lib/linux_admin/registration_system/subscription_manager.rb index 28f5d2f..086fe9d 100644 --- a/lib/linux_admin/registration_system/subscription_manager.rb +++ b/lib/linux_admin/registration_system/subscription_manager.rb @@ -9,6 +9,8 @@ def run!(cmd, options = {}) raise end + SATELLITE6_SERVER_CERT_PATH = "pub/candlepin-cert-consumer-latest.noarch.rpm" + def validate_credentials(options) !!organizations(options) end @@ -35,6 +37,9 @@ def organizations(options) def register(options) raise ArgumentError, "username and password are required" unless options[:username] && options[:password] + + install_server_certificate(options[:server_url], SATELLITE6_SERVER_CERT_PATH) if options[:server_url] + cmd = "subscription-manager register" params = {"--username=" => options[:username], "--password=" => options[:password]} diff --git a/spec/rhn_spec.rb b/spec/rhn_spec.rb index bb1e4be..023312d 100644 --- a/spec/rhn_spec.rb +++ b/spec/rhn_spec.rb @@ -23,27 +23,43 @@ expect { described_class.new.register({}) }.to raise_error(ArgumentError) end - it "with username and password" do - described_class.any_instance.should_receive(:run!).once.with("rhnreg_ks", {:params=>{"--username="=>"SomeUser", "--password="=>"SomePass", "--proxy="=>"1.2.3.4", "--proxyUser="=>"ProxyUser", "--proxyPassword="=>"ProxyPass", "--serverUrl="=>"192.168.1.1", "--systemorgid="=>1}}) - described_class.new.register( - :username => "SomeUser", - :password => "SomePass", - :proxy_address => "1.2.3.4", - :proxy_username => "ProxyUser", - :proxy_password => "ProxyPass", - :server_url => "192.168.1.1", - :org => 1, - ) + context "with username and password" do + let(:base_options) { {:username => "SomeUser@SomeDomain.org", + :password => "SomePass", + :org => "2", + :proxy_address => "1.2.3.4", + :proxy_username => "ProxyUser", + :proxy_password => "ProxyPass", + } + } + 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") + 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") + + described_class.new.register(base_options) + end + + 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) + + described_class.new.register(base_options) + end end 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", "--serverUrl="=>"192.168.1.1"}}) + described_class.any_instance.should_receive(:run!).once.with("rhnreg_ks", {:params=>{"--activationkey="=>"123abc", "--proxy="=>"1.2.3.4", "--proxyUser="=>"ProxyUser", "--proxyPassword="=>"ProxyPass"}}) described_class.new.register( :activationkey => "123abc", :proxy_address => "1.2.3.4", :proxy_username => "ProxyUser", :proxy_password => "ProxyPass", - :server_url => "192.168.1.1", ) end end diff --git a/spec/subscription_manager_spec.rb b/spec/subscription_manager_spec.rb index 8ac9335..cb68d9c 100644 --- a/spec/subscription_manager_spec.rb +++ b/spec/subscription_manager_spec.rb @@ -23,18 +23,34 @@ expect { described_class.new.register }.to raise_error(ArgumentError) end - it "with username and password" do - run_options = ["subscription-manager register", {:params=>{"--username="=>"SomeUser@SomeDomain.org", "--password="=>"SomePass", "--org="=>"IT", "--proxy="=>"1.2.3.4", "--proxyuser="=>"ProxyUser", "--proxypassword="=>"ProxyPass", "--serverurl="=>"192.168.1.1"}}] - described_class.any_instance.should_receive(:run!).once.with(*run_options) - described_class.new.register( - :username => "SomeUser@SomeDomain.org", - :password => "SomePass", - :org => "IT", - :proxy_address => "1.2.3.4", - :proxy_username => "ProxyUser", - :proxy_password => "ProxyPass", - :server_url => "192.168.1.1", - ) + context "with username and password" do + let(:base_options) { {:username => "SomeUser@SomeDomain.org", + :password => "SomePass", + :org => "IT", + :proxy_address => "1.2.3.4", + :proxy_username => "ProxyUser", + :proxy_password => "ProxyPass", + } + } + 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, "--org=", "IT") + run_params.store_path(:params, "--serverurl=", "https://server.url") + base_options.store_path(:server_url, "https://server.url") + + described_class.any_instance.should_receive(:run!).once.with("subscription-manager register", run_params) + LinuxAdmin::Rpm.should_receive(:upgrade).with("http://server.url/pub/candlepin-cert-consumer-latest.noarch.rpm") + + described_class.new.register(base_options) + end + + it "without server_url" do + described_class.any_instance.should_receive(:run!).once.with("subscription-manager register", run_params) + described_class.any_instance.should_not_receive(:install_server_certificate) + + described_class.new.register(base_options) + end end end