validations for nginx::resource::location

This commit is contained in:
Matthew Haughton 2014-01-06 12:41:47 -05:00 committed by Matthew Haughton
parent 5a9767dcd8
commit 8e71d33121
2 changed files with 81 additions and 26 deletions

View file

@ -130,7 +130,80 @@ define nginx::resource::location (
notify => Class['nginx::service'],
}
validate_re($ensure, '^(present|absent)$',
"${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)
}
validate_string($proxy_read_timeout)
if ($fastcgi != undef) {
validate_string($fastcgi)
}
validate_string($fastcgi_params)
if ($fastcgi_script != undef) {
validate_string($fastcgi_script)
}
if ($fastcgi_split_path != undef) {
validate_string($fastcgi_split_path)
}
validate_bool($ssl)
validate_bool($ssl_only)
if ($location_alias != undef) {
validate_string($location_alias)
}
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 ($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 ($try_files != undef) {
validate_array($try_files)
}
if ($proxy_cache != false) {
validate_string($proxy_cache)
}
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.')
}

View file

@ -69,24 +69,12 @@ describe 'nginx::resource::location' do
:value => 'value',
:match => ' proxy_method value;',
},
{
:title => 'should not set proxy_method',
:attr => 'proxy_method',
:value => false,
:notmatch => /proxy_method/,
},
{
:title => 'should set proxy_set_body',
:attr => 'proxy_set_body',
:value => 'value',
:match => ' proxy_set_body value;',
},
{
:title => 'should not set proxy_set_body',
:attr => 'proxy_set_body',
:value => false,
:notmatch => /proxy_set_body/,
},
{
:title => 'should set proxy_pass',
:attr => 'proxy',
@ -130,7 +118,7 @@ describe 'nginx::resource::location' do
:location => 'location',
:proxy => 'proxy_value',
:vhost => 'vhost1',
:proxy_cache => true,
:proxy_cache => 'true',
:proxy_cache_valid => '10m',
} end
@ -264,12 +252,6 @@ describe 'nginx::resource::location' do
:value => 'value',
:match => ' fastcgi_split_path_info value;'
},
{
:title => 'should not set fastcgi_split_path',
:attr => 'fastcgi_split_path',
:value => false,
:notmatch => /fastcgi_split_path_info/
},
{
:title => 'should set try_file(s)',
:attr => 'try_files',
@ -306,7 +288,7 @@ describe 'nginx::resource::location' do
},
].each do |param|
context "when #{param[:attr]} is #{param[:value]}" do
let :default_params do { :location => 'location', :fastcgi => true, :vhost => 'vhost1' } end
let :default_params do { :location => 'location', :fastcgi => 'localhost:9000', :vhost => 'vhost1' } end
let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end
it { should contain_concat__fragment("vhost1-500-#{params[:location]}") }
@ -444,8 +426,8 @@ describe 'nginx::resource::location' do
end
context 'attribute resources' do
context 'when fastcgi => true' do
let :params do { :fastcgi => true, :vhost => 'vhost1' } end
context 'when fastcgi => "localhost:9000"' do
let :params do { :fastcgi => 'localhost:9000', :vhost => 'vhost1' } end
it { should contain_file('/etc/nginx/fastcgi_params').with_mode('0770') }
end
@ -474,18 +456,18 @@ describe 'nginx::resource::location' do
end
context 'when auth_basic_user_file => true' do
let :params do { :auth_basic_user_file => true, :vhost => 'vhost1', :www_root => '/', } end
let :params do { :auth_basic_user_file => '/path/to/file', :vhost => 'vhost1', :www_root => '/', } end
it { should contain_file("/etc/nginx/rspec-test_htpasswd") }
end
context 'when ensure => absent' do
let :params do {
:www_root => true,
:www_root => '/',
:vhost => 'vhost1',
:ensure => 'absent',
:ssl => true,
:auth_basic_user_file => true,
:auth_basic_user_file => '/path/to/file',
} end
it { should contain_file("/etc/nginx/rspec-test_htpasswd").with_ensure('absent') }
@ -511,7 +493,7 @@ describe 'nginx::resource::location' do
let :params do {
:vhost => 'vhost1',
:www_root => '/',
:proxy => true,
:proxy => 'http://localhost:8000/uri/',
} end
it { expect { should contain_class('nginx::resource::location') }.to raise_error(Puppet::Error, /Cannot define both directory and proxy in a virtual host/) }