Commit 409a6823 authored by Łukasz Nowak's avatar Łukasz Nowak

caddy-frontend: Correctly support backend urls with whitespaces

parent c6fbeaeb
......@@ -26,11 +26,11 @@ md5sum = 23237969bbd9e974ac674b2052e8d67c
[template-caddy-replicate]
filename = instance-apache-replicate.cfg.in
md5sum = dac4ed5b4c95b6905f48bab8769ca236
md5sum = e2d9c782835ea9816539ce7b4f924ca9
[template-slave-list]
_update_hash_filename_ = templates/apache-custom-slave-list.cfg.in
md5sum = 6349bf609716ef77a1c0af0ad6cdc312
md5sum = e142dad44db1a25d46a31661aa2f075f
[template-replicate-publish-slave-information]
_update_hash_filename_ = templates/replicate-publish-slave-information.cfg.in
......
......@@ -137,16 +137,17 @@ context =
{% endfor %}
{% do slave.__setitem__('server-alias', ' '.join(slave_server_alias_unclashed)) %}
{% endif %}
{% if slave.get('url') %}
{% if subprocess_module.call([caddy_backend_url_validator, '' ~ slave['url']]) == 1 or not validators.url('' ~ slave['url']) %}
{% do slave_error_list.append('slave url %r invalid' % (slave['url'],)) %}
{% endif %}
{% endif %}
{% if slave.get('https-url') %}
{% if subprocess_module.call([caddy_backend_url_validator, '' ~ slave['https-url']]) == 1 or not validators.url('' ~ slave['https-url']) %}
{% do slave_error_list.append('slave https-url %r invalid' % (slave['https-url'],)) %}
{% for url_key in ['url', 'https-url'] %}
{% if slave.get(url_key) %}
{% set url = (slave[url_key] or '').strip() %}
{% if url != slave[url_key] %}
{% do slave_warning_list.append('slave %s %r has been converted to %r' % (url_key, slave[url_key], url)) %}
{% endif %}
{% if subprocess_module.call([caddy_backend_url_validator, url]) == 1 or not validators.url(url) %}
{% do slave_error_list.append('slave %s %r invalid' % (url_key, url)) %}
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
{% if 'ssl_proxy_ca_crt' in slave %}
{% set ssl_proxy_ca_crt = slave.get('ssl_proxy_ca_crt', '') %}
{% set check_popen = popen([parameter_dict['openssl'], 'x509', '-noout']) %}
......
......@@ -49,7 +49,7 @@ create = true
{%- for slave_instance in slave_instance_list %}
{#- prepare backend parameters #}
{%- for key, prefix in [('url', 'http_backend'), ('https-url', 'https_backend')] %}
{%- set parsed = urlparse_module.urlparse(slave_instance.get(key, '')) %}
{%- set parsed = urlparse_module.urlparse(slave_instance.get(key, '').strip()) %}
{%- set info_dict = {'scheme': parsed.scheme, 'hostname': parsed.hostname, 'port': parsed.port or DEFAULT_PORT[parsed.scheme], 'path': parsed.path, 'fragment': parsed.fragment} %}
{%- do slave_instance.__setitem__(prefix, info_dict) %}
{%- endfor %}
......
......@@ -1127,7 +1127,9 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
'empty': {
},
'Url': {
'url': cls.backend_url,
# make URL "incorrect", with whitespace, nevertheless it shall be
# correctly handled
'url': ' ' + cls.backend_url + ' ',
# authenticating to http backend shall be no-op
'authenticate-to-backend': True,
},
......@@ -1562,7 +1564,11 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
'rejected-slave-amount': '0',
'slave-amount': '56',
'rejected-slave-dict': {
}
},
'warning-slave-dict': {
'_Url': [
"slave url ' %(backend)s ' has been converted to '%(backend)s'" % {
'backend': self.backend_url}]}
}
self.assertEqual(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment