Merge "Fix root_url bug when using a slash"

This commit is contained in:
Zuul 2018-05-02 19:06:56 +00:00 committed by Gerrit Code Review
commit 58113f9297
4 changed files with 40 additions and 9 deletions

View File

@ -128,6 +128,13 @@ class horizon::wsgi::apache (
require => Package['horizon'],
}
# NOTE(tobasco): If root_url is set to '/' the paths in the apache
# configuration will be wrong (double slashes) so we fix that here.
if $root_url == '/' {
$root_url_real = ''
} else {
$root_url_real = $root_url
}
if $listen_ssl {
include ::apache::mod::ssl
@ -147,7 +154,7 @@ class horizon::wsgi::apache (
}
} else {
case $root_url {
case $root_url_real {
'': {
$ensure_ssl_vhost = 'absent'
$redirect_match = "^${::horizon::params::root_url}\$"
@ -156,7 +163,7 @@ class horizon::wsgi::apache (
default: {
$ensure_ssl_vhost = 'absent'
$redirect_match = '^/$'
$redirect_url = $root_url
$redirect_url = $root_url_real
}
}
}
@ -189,9 +196,9 @@ class horizon::wsgi::apache (
require => [ File[$::horizon::params::logdir], Package['horizon'] ],
}
$script_url = $root_url ? {
$script_url = $root_url_real ? {
'' => '/',
default => $root_url,
default => $root_url_real,
}
$wsgi_daemon_process_options = merge(
@ -213,7 +220,7 @@ class horizon::wsgi::apache (
error_log_file => 'horizon_error.log',
priority => $priority,
aliases => [{
alias => "${root_url}/static",
alias => "${root_url_real}/static",
path => "${root_path}/static",
}],
port => $http_port,
@ -240,8 +247,8 @@ class horizon::wsgi::apache (
}
ensure_resource('apache::vhost', $vhost_conf_name, merge ($default_vhost_conf, $extra_params, {
redirectmatch_regexp => $root_url ? { '' => undef, '/' => undef, default => $redirect_match },
redirectmatch_dest => $root_url ? { '' => undef, '/' => undef, default => $redirect_url },
redirectmatch_regexp => $root_url_real ? { '' => undef, '/' => undef, default => $redirect_match },
redirectmatch_dest => $root_url_real ? { '' => undef, '/' => undef, default => $redirect_url },
}))
ensure_resource('apache::vhost', $vhost_ssl_conf_name, merge ($default_vhost_conf, $extra_params, {
access_log_file => 'horizon_ssl_access.log',
@ -252,8 +259,8 @@ class horizon::wsgi::apache (
ensure => $ensure_ssl_vhost,
wsgi_daemon_process => 'horizon-ssl',
wsgi_process_group => 'horizon-ssl',
redirectmatch_regexp => $root_url ? { '' => undef, '/' => undef, default => '^/$' },
redirectmatch_dest => $root_url ? { '' => undef, '/' => undef, default => $root_url },
redirectmatch_regexp => $root_url_real ? { '' => undef, '/' => undef, default => '^/$' },
redirectmatch_dest => $root_url_real ? { '' => undef, '/' => undef, default => $root_url_real },
}))
}

View File

@ -0,0 +1,6 @@
---
fixes:
- |
Fixed a bug where passing a '/' as root_url would cause faulty paths in
local_settings.py and apache configuration. You can now set it to '/' and
the module will fix the correct root url for you.

View File

@ -202,9 +202,17 @@ describe 'horizon::wsgi::apache' do
before do
params.merge!({
:root_url => '/',
:root_path => '/tmp/horizon'
})
end
it 'configures apache with correct root url' do
is_expected.to contain_apache__vhost('horizon_vhost').with(
'aliases' => [{'alias' => '/static', 'path' => '/tmp/horizon/static'}],
'wsgi_script_aliases' => { '/' => '/usr/share/openstack-dashboard/openstack_dashboard/wsgi/django.wsgi' },
)
end
it 'should not configure redirectmatch' do
is_expected.to_not contain_apache__vhost('horizon_vhost').with(
'redirectmatch_regexp' => '^/$',

View File

@ -15,15 +15,25 @@ TEMPLATE_DEBUG = DEBUG
# should end with a slash.
#LOGIN_URL = WEBROOT + 'auth/login/'
#LOGOUT_URL = WEBROOT + 'auth/logout/'
<% if @root_url == '/' %>
WEBROOT = '/'
LOGIN_URL = '/auth/login/'
LOGOUT_URL = '/auth/logout/'
<% else %>
WEBROOT = '<%= @root_url %>/'
LOGIN_URL = '<%= @root_url %>/auth/login/'
LOGOUT_URL = '<%= @root_url %>/auth/logout/'
<% end %>
# LOGIN_REDIRECT_URL can be used as an alternative for
# HORIZON_CONFIG.user_home, if user_home is not set.
# Do not set it to '/home/', as this will cause circular redirect loop
#LOGIN_REDIRECT_URL = WEBROOT
<% if @root_url == '/' %>
LOGIN_REDIRECT_URL = '/'
<% else %>
LOGIN_REDIRECT_URL = '<%= @root_url %>/'
<% end %>
# Required for Django 1.5.
# If horizon is running in production (DEBUG is False), set this