validations for nginx::resource::location

This commit is contained in:
Matthew Haughton 2014-01-06 12:41:47 -05:00 коммит произвёл Matthew Haughton
Родитель 5a9767dcd8
Коммит 8e71d33121
2 изменённых файлов: 81 добавлений и 26 удалений

Просмотреть файл

@ -130,7 +130,80 @@ define nginx::resource::location (
notify => Class['nginx::service'], 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) 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) { if !is_integer($priority) {
fail('$priority must be an integer.') fail('$priority must be an integer.')
} }

Просмотреть файл

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