From 198aa99e8e5925cd1bdf9bfd832f0e923e4e8a2b Mon Sep 17 00:00:00 2001 From: "Angel L. Mateo" Date: Thu, 3 Apr 2014 13:09:37 +0200 Subject: [PATCH] Add parameters to configure negotiation module --- README.md | 23 ++++++ manifests/mod/negotiation.pp | 11 ++- spec/acceptance/mod_negotiation_spec.rb | 80 ++++++++++++++++++++ spec/classes/mod/negotiation_spec.rb | 59 +++++++++++++++ spec/fixtures/files/negotiation.conf | 4 + spec/fixtures/templates/negotiation.conf.erb | 4 + templates/mod/negotiation.conf.erb | 4 +- 7 files changed, 182 insertions(+), 3 deletions(-) create mode 100644 spec/acceptance/mod_negotiation_spec.rb create mode 100644 spec/classes/mod/negotiation_spec.rb create mode 100644 spec/fixtures/files/negotiation.conf create mode 100644 spec/fixtures/templates/negotiation.conf.erb diff --git a/README.md b/README.md index 385130df3..7f4ff7ed8 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ * [Class: apache::mod::ssl](#class-apachemodssl) * [Class: apache::mod::wsgi](#class-apachemodwsgi) * [Class: apache::mod::fcgid](#class-apachemodfcgid) + * [Class: apache::mod::negotiation](#class-apachemodnegotiation) * [Defined Type: apache::vhost](#defined-type-apachevhost) * [Parameter: `directories` for apache::vhost](#parameter-directories-for-apachevhost) * [SSL parameters for apache::vhost](#ssl-parameters-for-apachevhost) @@ -641,6 +642,28 @@ It is also possible to set the FcgidWrapper per directory per vhost. You must en See [FcgidWrapper documentation](https://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html#fcgidwrapper) for more information. +####Class: `apache::mod::negotiation` + +Installs and configures mod_negotiation. If there are not provided any +parameter, default apache mod_negotiation configuration is done. + +```puppet + class { '::apache::mod::negotiation': + force_language_priority => 'Prefer', + language_priority => [ 'es', 'en', 'ca', 'cs', 'da', 'de', 'el', 'eo' ], + } +``` + +**Parameters within `apache::mod::negotiation`:** + +#####`force_language_priority` + +A string that sets the `ForceLanguagePriority` option. Defaults to `Prefer Fallback`. + +#####`language_priority` + +An array of languages to set the `LanguagePriority` option of the module. + ####Defined Type: `apache::vhost` The Apache module allows a lot of flexibility in the setup and configuration of virtual hosts. This flexibility is due, in part, to `vhost`'s being a defined resource type, which allows it to be evaluated multiple times with different parameters. diff --git a/manifests/mod/negotiation.pp b/manifests/mod/negotiation.pp index eff685b15..af36b5bd8 100644 --- a/manifests/mod/negotiation.pp +++ b/manifests/mod/negotiation.pp @@ -1,4 +1,13 @@ -class apache::mod::negotiation { +class apache::mod::negotiation ( + $force_language_priority = 'Prefer Fallback', + $language_priority = [ 'en', 'ca', 'cs', 'da', 'de', 'el', 'eo', 'es', 'et', + 'fr', 'he', 'hr', 'it', 'ja', 'ko', 'ltz', 'nl', 'nn', + 'no', 'pl', 'pt', 'pt-BR', 'ru', 'sv', 'zh-CN', + 'zh-TW' ], +) { + validate_string($force_language_priority) + validate_array($language_priority) + ::apache::mod { 'negotiation': } # Template uses no variables file { 'negotiation.conf': diff --git a/spec/acceptance/mod_negotiation_spec.rb b/spec/acceptance/mod_negotiation_spec.rb new file mode 100644 index 000000000..33dcdd982 --- /dev/null +++ b/spec/acceptance/mod_negotiation_spec.rb @@ -0,0 +1,80 @@ +require 'spec_helper_acceptance' + +describe 'apache::mod::negotiation class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do + case fact('osfamily') + when 'Debian' + vhost_dir = '/etc/apache2/sites-enabled' + mod_dir = '/etc/apache2/mods-available' + service_name = 'apache2' + when 'RedHat' + vhost_dir = '/etc/httpd/conf.d' + mod_dir = '/etc/httpd/conf.d' + service_name = 'httpd' + when 'FreeBSD' + vhost_dir = '/usr/local/etc/apache22/Vhosts' + mod_dir = '/usr/local/etc/apache22/Modules' + service_name = 'apache22' + end + + context "default negotiation config" do + it 'succeeds in puppeting negotiation' do + pp= <<-EOS + class { '::apache': } + class { '::apache::mod::negotiation': } + EOS + apply_manifest(pp, :catch_failures => true) + end + + describe file("#{$mod_dir}/negotiation.conf") do + it { should contain "LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW +ForceLanguagePriority Prefer Fallback" } + end + + describe service(service_name) do + it { should be_enabled } + it { should be_running } + end + end + + context "with alternative force_language_priority" do + it 'succeeds in puppeting negotiation' do + pp= <<-EOS + class { '::apache': } + class { '::apache::mod::negotiation': + force_language_priority => 'Prefer', + } + EOS + apply_manifest(pp, :catch_failures => true) + end + + describe file("#{$mod_dir}/negotiation.conf") do + it { should contain "ForceLanguagePriority Prefer" } + end + + describe service(service_name) do + it { should be_enabled } + it { should be_running } + end + end + + context "with alternative language_priority" do + it 'succeeds in puppeting negotiation' do + pp= <<-EOS + class { '::apache': } + class { '::apache::mod::negotiation': + language_priority => [ 'en', 'es' ], + } + EOS + apply_manifest(pp, :catch_failures => true) + end + + describe file("#{$mod_dir}/negotiation.conf") do + it { should contain "LanguagePriority en es" } + end + + describe service(service_name) do + it { should be_enabled } + it { should be_running } + end + end +end diff --git a/spec/classes/mod/negotiation_spec.rb b/spec/classes/mod/negotiation_spec.rb new file mode 100644 index 000000000..a5d4ba92d --- /dev/null +++ b/spec/classes/mod/negotiation_spec.rb @@ -0,0 +1,59 @@ +require 'spec_helper' + +describe 'apache::mod::negotiation', :type => :class do + describe "OS independent tests" do + + let :facts do + { + :osfamily => 'Debian', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + + context "default params" do + let :pre_condition do + 'class {"::apache": }' + end + it { should contain_class("apache") } + it do + should contain_file('negotiation.conf').with( { + :ensure => 'file', + :content => 'LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW +ForceLanguagePriority Prefer Fallback +', + } ) + end + end + + context 'with force_language_priority parameter' do + let :pre_condition do + 'class {"::apache": default_mods => ["negotiation"]}' + end + let :params do + { :force_language_priority => 'Prefer' } + end + it do + should contain_file('negotiation.conf').with( { + :ensure => 'file', + :content => /^ForceLanguagePriority Prefer$/, + } ) + end + end + + context 'with language_priority parameter' do + let :pre_condition do + 'class {"::apache": default_mods => ["negotiation"]}' + end + let :params do + { :language_priority => [ 'en', 'es' ] } + end + it do + should contain_file('negotiation.conf').with( { + :ensure => 'file', + :content => /^LanguagePriority en es$/, + } ) + end + end + end +end diff --git a/spec/fixtures/files/negotiation.conf b/spec/fixtures/files/negotiation.conf new file mode 100644 index 000000000..c0bb8b9fd --- /dev/null +++ b/spec/fixtures/files/negotiation.conf @@ -0,0 +1,4 @@ +# This is a file only for spec testing + +LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW +ForceLanguagePriority Prefer Fallback diff --git a/spec/fixtures/templates/negotiation.conf.erb b/spec/fixtures/templates/negotiation.conf.erb new file mode 100644 index 000000000..557502246 --- /dev/null +++ b/spec/fixtures/templates/negotiation.conf.erb @@ -0,0 +1,4 @@ +# This is a template only for spec testing + +LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW +ForceLanguagePriority Prefer Fallback diff --git a/templates/mod/negotiation.conf.erb b/templates/mod/negotiation.conf.erb index 50921019b..55b2ab529 100644 --- a/templates/mod/negotiation.conf.erb +++ b/templates/mod/negotiation.conf.erb @@ -1,2 +1,2 @@ -LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW -ForceLanguagePriority Prefer Fallback +LanguagePriority <%= @language_priority.join(' ') %> +ForceLanguagePriority <%= @force_language_priority %>