Revision 4e68ddfe
Added by Julian Todt almost 6 years ago
test/models/host_test.rb | ||
---|---|---|
assert_equal domain, host.domain
|
||
end
|
||
|
||
test "handle_ca must not perform actions when the manage_puppetca setting is false" do
|
||
h = FactoryBot.create(:host)
|
||
Setting[:manage_puppetca] = false
|
||
h.expects(:initialize_puppetca).never
|
||
h.expects(:setAutosign).never
|
||
assert h.handle_ca
|
||
end
|
||
|
||
test "handle_ca must not perform actions when no Puppet CA proxy is associated even if associated with hostgroup" do
|
||
hostgroup = FactoryBot.create(:hostgroup, :with_puppet_orchestration, :with_domain, :with_os)
|
||
h = FactoryBot.create(:host, :managed, :with_environment, :hostgroup => hostgroup)
|
||
Setting[:manage_puppetca] = true
|
||
|
||
h.puppet_proxy_id = h.puppet_ca_proxy_id = nil
|
||
h.save
|
||
|
||
refute h.puppetca?
|
||
|
||
h.expects(:initialize_puppetca).never
|
||
assert h.handle_ca
|
||
end
|
||
|
||
test "handle_ca must not perform actions when no Puppet CA proxy is associated" do
|
||
h = FactoryBot.create(:host)
|
||
Setting[:manage_puppetca] = true
|
||
refute h.puppetca?
|
||
h.expects(:initialize_puppetca).never
|
||
assert h.handle_ca
|
||
end
|
||
|
||
test "handle_ca must call initialize, delete cert and add autosign methods" do
|
||
h = FactoryBot.create(:host, :with_puppet_orchestration)
|
||
Setting[:manage_puppetca] = true
|
||
assert h.puppetca?
|
||
h.expects(:initialize_puppetca).returns(true)
|
||
h.expects(:delCertificate).returns(true)
|
||
h.expects(:setAutosign).returns(true)
|
||
assert h.handle_ca
|
||
end
|
||
|
||
test "if the user toggles off the use_uuid_for_certificates option, revoke the UUID and autosign the hostname" do
|
||
h = FactoryBot.create(:host, :with_puppet_orchestration)
|
||
Setting[:manage_puppetca] = true
|
||
assert h.puppetca?
|
||
|
||
Setting[:use_uuid_for_certificates] = false
|
||
some_uuid = Foreman.uuid
|
||
h.certname = some_uuid
|
||
|
||
h.expects(:initialize_puppetca).returns(true)
|
||
mock_puppetca = Object.new
|
||
mock_puppetca.expects(:del_certificate).with(some_uuid).returns(true)
|
||
mock_puppetca.expects(:set_autosign).with(h.name).returns(true)
|
||
h.instance_variable_set("@puppetca", mock_puppetca)
|
||
|
||
assert h.handle_ca
|
||
assert_equal h.certname, h.name
|
||
end
|
||
|
||
test "if the user changes a hostname in non-use_uuid_for_cetificates mode, revoke the old hostname and autosign the new hostname" do
|
||
Setting[:use_uuid_for_certificates] = false
|
||
Setting[:manage_puppetca] = true
|
||
|
||
h = FactoryBot.create(:host, :with_puppet_orchestration)
|
||
assert h.puppetca?
|
||
|
||
old_name = 'oldhostname'
|
||
h.certname = old_name
|
||
|
||
h.expects(:initialize_puppetca).returns(true)
|
||
mock_puppetca = Object.new
|
||
mock_puppetca.expects(:del_certificate).with(old_name).returns(true)
|
||
mock_puppetca.expects(:set_autosign).with(h.name).returns(true)
|
||
h.instance_variable_set("@puppetca", mock_puppetca)
|
||
|
||
assert h.handle_ca
|
||
assert_equal h.certname, h.name
|
||
end
|
||
|
||
test "custom_disk_partition_with_erb" do
|
||
h = FactoryBot.create(:host)
|
||
h.disk = "<%= template_name %>"
|
Also available in: Unified diff
Fixes #23626 - Move autosign to build queue