foreman/test/functional/unattended_controller_test.rb @ 51e8d9d2
18738311 | Ohad Levy | require 'test_helper'
|
|
class UnattendedControllerTest < ActionController::TestCase
|
|||
f09d61de | Dominic Cleal | setup do
|
|
Host::Managed.any_instance.stubs(:handle_ca).returns(true)
|
|||
end
|
|||
b34e9aea | Ohad Levy | test "should get a kickstart" do
|
|
@request.env["HTTP_X_RHN_PROVISIONING_MAC_0"] = "eth0 #{hosts(:redhat).mac}"
|
|||
0fa5d146 | Dominic Cleal | get :provision
|
|
b34e9aea | Ohad Levy | assert_response :success
|
|
end
|
|||
test "should get a kickstart even if not using the first NIC" do
|
|||
@request.env["HTTP_X_RHN_PROVISIONING_MAC_0"] = "unused NIC"
|
|||
@request.env["HTTP_X_RHN_PROVISIONING_MAC_3"] = "eth4 #{hosts(:redhat).mac}"
|
|||
0fa5d146 | Dominic Cleal | get :provision
|
|
b34e9aea | Ohad Levy | assert_response :success
|
|
end
|
|||
50e78f00 | cyberkov | test "should get a kickstart even if we are behind a loadbalancer" do
|
|
@request.env["HTTP_X_FORWARDED_FOR"] = hosts(:redhat).ip
|
|||
@request.env["REMOTE_ADDR"] = "127.0.0.1"
|
|||
0fa5d146 | Dominic Cleal | get :provision
|
|
50e78f00 | cyberkov | assert_response :success
|
|
end
|
|||
b34e9aea | Ohad Levy | test "should get a preseed finish script" do
|
|
@request.env["REMOTE_ADDR"] = hosts(:ubuntu).ip
|
|||
0fa5d146 | Dominic Cleal | get :finish
|
|
b34e9aea | Ohad Levy | assert_response :success
|
|
end
|
|||
267f1ea2 | Ohad Levy | test "should get a preseed finish script with multiple ips in the request header" do
|
|
@request.env["REMOTE_ADDR"] = [hosts(:ubuntu).ip, '1.2.3.4']
|
|||
0fa5d146 | Dominic Cleal | get :finish
|
|
267f1ea2 | Ohad Levy | assert_response :success
|
|
end
|
|||
b34e9aea | Ohad Levy | test "should get a preseed" do
|
|
@request.env["REMOTE_ADDR"] = hosts(:ubuntu).ip
|
|||
0fa5d146 | Dominic Cleal | get :provision
|
|
b34e9aea | Ohad Levy | assert_response :success
|
|
end
|
|||
test "unattended files content type should be text/plain" do
|
|||
@request.env["REMOTE_ADDR"] = hosts(:ubuntu).ip
|
|||
0fa5d146 | Dominic Cleal | get :provision
|
|
b34e9aea | Ohad Levy | assert_response :success
|
|
0753c1c4 | Justin Sherrill | assert @response.headers["Content-Type"].match("text/plain")
|
|
b34e9aea | Ohad Levy | end
|
|
51e8d9d2 | Greg Sutcliffe | test "should set @static when requested" do
|
|
Setting[:safemode_render]=false
|
|||
@request.env["HTTP_X_RHN_PROVISIONING_MAC_0"] = "eth0 #{hosts(:redhat).mac}"
|
|||
get(:provision, 'static' => 'true')
|
|||
assert_match(%r{static:true}, @response.body)
|
|||
end
|
|||
b34e9aea | Ohad Levy | test "should support spoof" do
|
|
0fa5d146 | Dominic Cleal | get :provision, {:spoof => hosts(:ubuntu).ip}, set_session_user
|
|
b34e9aea | Ohad Levy | assert_response :success
|
|
end
|
|||
224783a1 | Ohad Levy | test "should render spoof when user is not logged in" do
|
|
0fa5d146 | Dominic Cleal | get :provision, {:spoof => hosts(:ubuntu).ip}
|
|
224783a1 | Ohad Levy | assert_response :redirect
|
|
end
|
|||
b34e9aea | Ohad Levy | test "should provide pxe config for redhat" do
|
|
0fa5d146 | Dominic Cleal | get :PXELinux, {:spoof => hosts(:redhat).ip}, set_session_user
|
|
b34e9aea | Ohad Levy | assert_response :success
|
|
end
|
|||
test "should provide pxe config for debian" do
|
|||
0fa5d146 | Dominic Cleal | get :PXELinux, {:spoof => hosts(:ubuntu).ip}, set_session_user
|
|
b34e9aea | Ohad Levy | assert_response :success
|
|
end
|
|||
9269ddca | Lukas Zapletal | test "should render spoof pxelinux for a host" do
|
|
0fa5d146 | Dominic Cleal | get :PXELinux, {:spoof => hosts(:redhat).ip}, set_session_user
|
|
9269ddca | Lukas Zapletal | assert assigns(:initrd)
|
|
assert assigns(:kernel)
|
|||
assert_response :success
|
|||
end
|
|||
test "should render spoof pxegrub for a host" do
|
|||
0fa5d146 | Dominic Cleal | get :PXEGrub, {:spoof => hosts(:redhat).ip}, set_session_user
|
|
assert assigns(:initrd)
|
|||
assert assigns(:kernel)
|
|||
assert_response :success
|
|||
end
|
|||
test "should render spoof iPXE for a host" do
|
|||
get :iPXE, {:spoof => hosts(:redhat).ip}, set_session_user
|
|||
9269ddca | Lukas Zapletal | assert assigns(:initrd)
|
|
assert assigns(:kernel)
|
|||
assert_response :success
|
|||
end
|
|||
test "should render spoof gpxe for a host" do
|
|||
0fa5d146 | Dominic Cleal | get :gPXE, {:spoof => hosts(:redhat).ip}, set_session_user
|
|
9269ddca | Lukas Zapletal | assert assigns(:initrd)
|
|
assert assigns(:kernel)
|
|||
assert_response :success
|
|||
end
|
|||
b34e9aea | Ohad Levy | test "should accept built notifications" do
|
|
@request.env["REMOTE_ADDR"] = hosts(:ubuntu).ip
|
|||
get :built
|
|||
assert_response :created
|
|||
host = Host.find_by_ip(hosts(:ubuntu).ip)
|
|||
assert_equal host.build,false
|
|||
end
|
|||
test "should not provide unattened files to hosts which are not in built state" do
|
|||
@request.env["HTTP_X_RHN_PROVISIONING_MAC_0"] = "eth0 #{hosts(:redhat).mac}"
|
|||
get :built
|
|||
assert_response :created
|
|||
0fa5d146 | Dominic Cleal | get :provision
|
|
b34e9aea | Ohad Levy | assert_response :method_not_allowed
|
|
end
|
|||
test "should not provide unattended files to hosts which we don't know about" do
|
|||
0fa5d146 | Dominic Cleal | get :provision
|
|
b34e9aea | Ohad Levy | assert_response :not_found
|
|
end
|
|||
test "should not provide unattended files to hosts which don't have an assign os" do
|
|||
7838d170 | Ivan Necas | setup_users
|
|
a6db0470 | Paul Kelly | hosts(:otherfullhost).update_attribute(:operatingsystem_id, nil)
|
|
@request.env["HTTP_X_RHN_PROVISIONING_MAC_0"] = "eth0 #{hosts(:otherfullhost).mac}"
|
|||
0fa5d146 | Dominic Cleal | get :provision
|
|
b34e9aea | Ohad Levy | assert_response :conflict
|
|
18738311 | Ohad Levy | end
|
|
e5d3f34e | Ohad Levy | ||
test "template with hostgroup should be rendered" do
|
|||
get :template, {:id => "MyString", :hostgroup => "Common"}
|
|||
assert_response :success
|
|||
end
|
|||
test "template with non-existant hostgroup should not be rendered" do
|
|||
get :template, {:id => "MyString2", :hostgroup => "NotArealHostgroup"}
|
|||
assert_response :not_found
|
|||
end
|
|||
test "requesting a template that does not exist should fail" do
|
|||
get :template, {:id => "kdsfjlkasjdfkl", :hostgroup => "Common"}
|
|||
assert_response :not_found
|
|||
end
|
|||
81159d4b | Greg Sutcliffe | test "hosts with unknown ip and valid token should render a template" do
|
|
Setting[:token_duration] = 30
|
|||
@request.env["REMOTE_ADDR"] = '127.0.0.1'
|
|||
hosts(:ubuntu).create_token(:value => "aaaaaa", :expires => Time.now + 5.minutes)
|
|||
0fa5d146 | Dominic Cleal | get :provision, {'token' => hosts(:ubuntu).token.value }
|
|
81159d4b | Greg Sutcliffe | assert_response :success
|
|
end
|
|||
8d10c655 | Greg Sutcliffe | test "hosts with mismatched ip and update_ip=false should have the old ip" do
|
|
disable_orchestration # avoids dns errors
|
|||
Setting[:token_duration] = 30
|
|||
Setting[:update_ip_from_built_request] = false
|
|||
@request.env["REMOTE_ADDR"] = '127.0.0.1'
|
|||
h=hosts(:ubuntu2)
|
|||
h.create_token(:value => "aaaaaa", :expires => Time.now + 5.minutes)
|
|||
get :built, {'token' => h.token.value }
|
|||
h_new=Host.find_by_name(h.name)
|
|||
assert_response :success
|
|||
assert_equal h.ip, h_new.ip
|
|||
end
|
|||
test "hosts with mismatched ip and update_ip true should have the new ip" do
|
|||
disable_orchestration # avoids dns errors
|
|||
Setting[:token_duration] = 30
|
|||
Setting[:update_ip_from_built_request] = true
|
|||
@request.env["REMOTE_ADDR"] = '2.3.4.199'
|
|||
h=hosts(:ubuntu2)
|
|||
assert_equal '2.3.4.106', h.ip
|
|||
h.create_token(:value => "aaaaab", :expires => Time.now + 5.minutes)
|
|||
get :built, {'token' => h.token.value }
|
|||
h_new=Host.find_by_name(h.name)
|
|||
assert_response :success
|
|||
assert_equal '2.3.4.199', h_new.ip
|
|||
end
|
|||
test "hosts with mismatched ip and update_ip true and a duplicate ip should succeed with no ip update" do
|
|||
disable_orchestration # avoids dns errors
|
|||
Setting[:token_duration] = 30
|
|||
Setting[:update_ip_from_built_request] = true
|
|||
@request.env["REMOTE_ADDR"] = hosts(:redhat).ip
|
|||
h=hosts(:ubuntu2)
|
|||
h.create_token(:value => "aaaaac", :expires => Time.now + 5.minutes)
|
|||
get :built, {'token' => h.token.value }
|
|||
assert_response :success
|
|||
h_new=Host.find_by_name(h.name)
|
|||
assert_equal h.ip, h_new.ip
|
|||
end
|
|||
cb92c0be | Dmitri Dolguikh | # Should this test be moved into renderer_test, as it excercises foreman_url() functionality?
|
|
81159d4b | Greg Sutcliffe | test "template should contain tokens when tokens enabled and present for the host" do
|
|
Setting[:token_duration] = 30
|
|||
8c618ae8 | Greg Sutcliffe | Setting[:unattended_url] = "http://test.host"
|
|
81159d4b | Greg Sutcliffe | @request.env["REMOTE_ADDR"] = hosts(:ubuntu).ip
|
|
hosts(:ubuntu).create_token(:value => "aaaaaa", :expires => Time.now + 5.minutes)
|
|||
0fa5d146 | Dominic Cleal | get :provision
|
|
assert @response.body.include?("http://test.host:80/unattended/finish?token=aaaaaa")
|
|||
81159d4b | Greg Sutcliffe | end
|
|
cb92c0be | Dmitri Dolguikh | # Should this test be moved into renderer_test, as it excercises foreman_url() functionality?
|
|
9f6de1e7 | Greg Sutcliffe | test "template should not contain https when ssl enabled" do
|
|
@request.env["HTTPS"] = "on"
|
|||
@request.env["REMOTE_ADDR"] = hosts(:ubuntu).ip
|
|||
0fa5d146 | Dominic Cleal | get :provision
|
|
assert_match(%r{http://}, @response.body)
|
|||
assert_no_match(%r{https://}, @response.body)
|
|||
end
|
|||
test "should return and log error when template not found" do
|
|||
@request.env["REMOTE_ADDR"] = hosts(:ubuntu).ip
|
|||
Host::Managed.any_instance.expects(:configTemplate).returns(nil)
|
|||
Rails.logger.expects(:error).with(regexp_matches(/unable to find provision template/))
|
|||
get :provision
|
|||
assert_response :not_found
|
|||
9f6de1e7 | Greg Sutcliffe | end
|
|
18738311 | Ohad Levy | end
|