Skip to content

Commit

Permalink
Merge pull request #1100 from mat1010/MODULES-1932-proxy_pass_match-fix
Browse files Browse the repository at this point in the history
Change proxy_pass_match to use the proxy template
  • Loading branch information
igalic committed Apr 14, 2015
2 parents 355f6fa + 26b7759 commit 2858f98
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
3 changes: 2 additions & 1 deletion manifests/vhost.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
68 changes: 68 additions & 0 deletions spec/acceptance/vhost_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<VirtualHost \*:80>' }
it { is_expected.to contain "ServerName proxy.example.com" }
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 "<Proxy \*>" }
end
end

context 'new vhost on port 80' do
it 'should configure two apache vhosts' do
pp = <<-EOS
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2858f98

Please sign in to comment.