"${ensure} is not supported for ensure. Allowed values are 'present' and 'absent'.")
validate_string($location)
if ($vhost != undef) {
validate_string($vhost)
}
if ($www_root != undef) {
validate_string($www_root)
}
if ($autoindex != undef) {
validate_string($autoindex)
}
validate_array($index_files)
if ($proxy != undef) {
validate_string($proxy)
}
if ($proxy_redirect != undef) {
validate_string($proxy_redirect)
}
validate_string($proxy_read_timeout)
validate_string($proxy_connect_timeout)
validate_array($proxy_set_header)
if ($fastcgi != undef) {
validate_string($fastcgi)
}
if ($fastcgi_param != undef) {
validate_hash($fastcgi_param)
}
validate_string($fastcgi_params)
if ($fastcgi_script != undef) {
validate_string($fastcgi_script)
}
if ($fastcgi_split_path != undef) {
validate_string($fastcgi_split_path)
}
if ($uwsgi != undef) {
validate_string($uwsgi)
}
validate_string($uwsgi_params)
validate_bool($internal)
validate_bool($ssl)
validate_bool($ssl_only)
if ($location_alias != undef) {
validate_string($location_alias)
}
+ if ($location_satisfy != undef) {
+ validate_re($location_satisfy, '^(any|all)$',
+ "${$location_satisfy} is not supported for location_satisfy. Allowed values are 'any' and 'all'.")
+ }
if ($location_allow != undef) {
validate_array($location_allow)
}
if ($location_deny != undef) {
validate_array($location_deny)
}
if ($option != undef) {
warning('The $option parameter has no effect and is deprecated.')
}
if ($stub_status != undef) {
validate_bool($stub_status)
}
if ($raw_prepend != undef) {
if (is_array($raw_prepend)) {
validate_array($raw_prepend)
} else {
validate_string($raw_prepend)
}
}
if ($raw_append != undef) {
if (is_array($raw_append)) {
validate_array($raw_append)
} else {
validate_string($raw_append)
}
}
if ($location_custom_cfg != undef) {
validate_hash($location_custom_cfg)
}
if ($location_cfg_prepend != undef) {
validate_hash($location_cfg_prepend)
}
if ($location_cfg_append != undef) {
validate_hash($location_cfg_append)
}
if ($include != undef) {
validate_array($include)
}
if ($try_files != undef) {
validate_array($try_files)
}
if ($proxy_cache != false) {
validate_string($proxy_cache)
}
if ($proxy_cache_key != undef) {
validate_string($proxy_cache_key)
}
if ($proxy_cache_use_stale != undef) {
validate_string($proxy_cache_use_stale)
}
if ($proxy_cache_valid != false) {
validate_string($proxy_cache_valid)
}
if ($proxy_method != undef) {
validate_string($proxy_method)
}
if ($proxy_set_body != undef) {
validate_string($proxy_set_body)
}
if ($auth_basic != undef) {
validate_string($auth_basic)
}
if ($auth_basic_user_file != undef) {
validate_string($auth_basic_user_file)
}
if !is_integer($priority) {
fail('$priority must be an integer.')
}
validate_array($rewrite_rules)
if (($priority + 0) < 401) or (($priority + 0) > 899) {
fail('$priority must be in the range 401-899.')
}
# # Shared Variables
$ensure_real = $ensure ? {
'absent' => absent,
default => file,
}
## Check for various error conditions
if ($vhost == undef) {
fail('Cannot create a location reference without attaching to a virtual host')
}
if (($www_root == undef) and ($proxy == undef) and ($location_alias == undef) and ($stub_status == undef) and ($fastcgi == undef) and ($uwsgi == undef) and ($location_custom_cfg == undef) and ($internal == false)) {
fail('Cannot create a location reference without a www_root, proxy, location_alias, fastcgi, uwsgi, stub_status, internal, or location_custom_cfg defined')
}
if (($www_root != undef) and ($proxy != undef)) {
fail('Cannot define both directory and proxy in a virtual host')
}
# Use proxy, fastcgi or uwsgi template if $proxy is defined, otherwise use directory template.
# fastcgi_script is deprecated
if ($fastcgi_script != undef) {
warning('The $fastcgi_script parameter is deprecated; please use $fastcgi_param instead to define custom fastcgi_params!')
let :params do { :fastcgi => 'localhost:9000', :vhost => 'vhost1' } end
it { is_expected.to contain_file('/etc/nginx/fastcgi_params').with_mode('0770') }
end
context 'when uwsgi => "unix:/home/project/uwsgi.socket"' do
let :params do { :uwsgi => 'uwsgi_upstream', :vhost => 'vhost1' } end
it { should contain_file('/etc/nginx/uwsgi_params') }
end
context 'when ssl_only => true' do
let :params do { :ssl_only => true, :vhost => 'vhost1', :www_root => '/', } end
it { is_expected.not_to contain_concat__fragment("vhost1-500-" + Digest::MD5.hexdigest("rspec-test")) }
end
context 'when ssl_only => false' do
let :params do { :ssl_only => false, :vhost => 'vhost1', :www_root => '/', } end
it { is_expected.to contain_concat__fragment("vhost1-500-" + Digest::MD5.hexdigest("rspec-test")) }
end
context 'when ssl => true' do
let :params do { :ssl => true, :vhost => 'vhost1', :www_root => '/', } end
it { is_expected.to contain_concat__fragment("vhost1-800-" + Digest::MD5.hexdigest("rspec-test") + "-ssl") }
end
context 'when ssl => false' do
let :params do { :ssl => false, :vhost => 'vhost1', :www_root => '/', } end
it { is_expected.not_to contain_concat__fragment("vhost1-800-" + Digest::MD5.hexdigest("rspec-test") + "-ssl") }
end
context "vhost missing" do
let :params do {
:www_root => '/',
} end
it { expect { is_expected.to contain_class('nginx::resource::location') }.to raise_error(Puppet::Error, /Cannot create a location reference without attaching to a virtual host/) }
end
context "location type missing" do
let :params do {
:vhost => 'vhost1',
} end
it { expect { is_expected.to contain_class('nginx::resource::location') }.to raise_error(Puppet::Error, /Cannot create a location reference without a www_root, proxy, location_alias, fastcgi, uwsgi, stub_status, internal, or location_custom_cfg defined/) }
end
context "www_root and proxy are set" do
let :params do {
:vhost => 'vhost1',
:www_root => '/',
:proxy => 'http://localhost:8000/uri/',
} end
it { expect { is_expected.to contain_class('nginx::resource::location') }.to raise_error(Puppet::Error, /Cannot define both directory and proxy in a virtual host/) }
end
context 'when vhost name is sanitized' do
let :title do 'www.rspec-location.com' end
let :params do {
:vhost => 'www rspec-vhost com',
:www_root => '/',
:ssl => true,
} end
it { is_expected.to contain_concat__fragment("www_rspec-vhost_com-500-" + Digest::MD5.hexdigest("www.rspec-location.com")).with_target('/etc/nginx/sites-available/www_rspec-vhost_com.conf') }
it { is_expected.to contain_concat__fragment("www_rspec-vhost_com-800-" + Digest::MD5.hexdigest("www.rspec-location.com") + "-ssl").with_target('/etc/nginx/sites-available/www_rspec-vhost_com.conf') }