From 7fdafeeb3bdda9c5fc4d7bb1cfaa3c236e1b40e5 Mon Sep 17 00:00:00 2001 From: Matthias Kneer Date: Tue, 14 Apr 2015 12:56:10 +0200 Subject: [PATCH 1/2] - Changed vhost.pp to make use of the proxy template when proxy_pass_match is defined - Added rspec tests for proxy_pass_match --- manifests/vhost.pp | 3 +- spec/acceptance/vhost_spec.rb | 68 +++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/manifests/vhost.pp b/manifests/vhost.pp index fb4136805..bbb5e61f2 100644 --- a/manifests/vhost.pp +++ b/manifests/vhost.pp @@ -624,9 +624,10 @@ # Template uses: # - $proxy_dest # - $proxy_pass + # - $proxy_pass_match # - $proxy_preserve_host # - $no_proxy_uris - if $proxy_dest or $proxy_pass { + if $proxy_dest or $proxy_pass or $proxy_pass_match { concat::fragment { "${name}-proxy": target => "${priority_real}${filename}.conf", order => 140, diff --git a/spec/acceptance/vhost_spec.rb b/spec/acceptance/vhost_spec.rb index 6fe87c5a8..08594fa22 100644 --- a/spec/acceptance/vhost_spec.rb +++ b/spec/acceptance/vhost_spec.rb @@ -119,6 +119,33 @@ class { 'apache': } end end + context 'new proxy vhost on port 80' do + it 'should configure an apache proxy vhost' do + pp = <<-EOS + class { 'apache': } + apache::vhost { 'proxy.example.com': + port => '80', + docroot => '/var/www/proxy', + proxy_pass_match => [ + { 'path' => '/foo', 'url' => 'http://backend-foo/'}, + ], + proxy_preserve_host => true, + proxy_error_override => true, + } + EOS + apply_manifest(pp, :catch_failures => true) + end + + describe file("#{$vhost_dir}/25-proxy.example.com.conf") do + it { is_expected.to contain '' } + it { is_expected.to contain "ServerName proxy.example.com" } + it { is_expected.to contain "ProxyPassMatch" } + it { is_expected.to contain "ProxyPreserveHost On" } + it { is_expected.to contain "ProxyErrorOverride On" } + it { is_expected.not_to contain "" } + end + end + context 'new vhost on port 80' do it 'should configure two apache vhosts' do pp = <<-EOS @@ -498,6 +525,47 @@ class { 'apache': default_vhost => false, } end end + context 'proxy_pass_match for alternative vhost' do + it 'should configure a local vhost and a proxy vhost' do + apply_manifest(%{ + class { 'apache': default_vhost => false, } + apache::vhost { 'localhost': + docroot => '/var/www/local', + ip => '127.0.0.1', + port => '8888', + } + apache::listen { '*:80': } + apache::vhost { 'proxy.example.com': + docroot => '/var/www', + port => '80', + add_listen => false, + proxy_pass_match => { + 'path' => '/', + 'url' => 'http://localhost:8888/subdir/', + }, + } + host { 'proxy.example.com': ip => '127.0.0.1', } + file { ['/var/www/local', '/var/www/local/subdir']: ensure => directory, } + file { '/var/www/local/subdir/index.html': + ensure => file, + content => "Hello from localhost\\n", + } + }, :catch_failures => true) + end + + describe service($service_name) do + it { is_expected.to be_enabled } + it { is_expected.to be_running } + end + + it 'should get a response from the back end' do + shell("/usr/bin/curl --max-redirs 0 proxy.example.com:80") do |r| + expect(r.stdout).to eq("Hello from localhost\n") + expect(r.exit_code).to eq(0) + end + end + end + describe 'ip_based' do it 'applies cleanly' do pp = <<-EOS From 26b77592d86bc3f4fe9cc68277c844b000a8799d Mon Sep 17 00:00:00 2001 From: Matthias Kneer Date: Tue, 14 Apr 2015 14:08:48 +0200 Subject: [PATCH 2/2] - Changed rspec test for proxy_pass_match to be more precise --- spec/acceptance/vhost_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/acceptance/vhost_spec.rb b/spec/acceptance/vhost_spec.rb index 08594fa22..434607531 100644 --- a/spec/acceptance/vhost_spec.rb +++ b/spec/acceptance/vhost_spec.rb @@ -139,7 +139,7 @@ class { 'apache': } describe file("#{$vhost_dir}/25-proxy.example.com.conf") do it { is_expected.to contain '' } it { is_expected.to contain "ServerName proxy.example.com" } - it { is_expected.to contain "ProxyPassMatch" } + it { is_expected.to contain "ProxyPassMatch\s+/foo http://backend-foo/" } it { is_expected.to contain "ProxyPreserveHost On" } it { is_expected.to contain "ProxyErrorOverride On" } it { is_expected.not_to contain "" }