Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/linux_admin/registration_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions lib/linux_admin/registration_system/rhn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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]
Expand Down
5 changes: 5 additions & 0 deletions lib/linux_admin/registration_system/subscription_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]}
Expand Down
42 changes: 29 additions & 13 deletions spec/rhn_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 28 additions & 12 deletions spec/subscription_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down