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 ...@@ -26,11 +26,11 @@ md5sum = 23237969bbd9e974ac674b2052e8d67c
[template-caddy-replicate] [template-caddy-replicate]
filename = instance-apache-replicate.cfg.in filename = instance-apache-replicate.cfg.in
md5sum = dac4ed5b4c95b6905f48bab8769ca236 md5sum = e2d9c782835ea9816539ce7b4f924ca9
[template-slave-list] [template-slave-list]
_update_hash_filename_ = templates/apache-custom-slave-list.cfg.in _update_hash_filename_ = templates/apache-custom-slave-list.cfg.in
md5sum = 6349bf609716ef77a1c0af0ad6cdc312 md5sum = e142dad44db1a25d46a31661aa2f075f
[template-replicate-publish-slave-information] [template-replicate-publish-slave-information]
_update_hash_filename_ = templates/replicate-publish-slave-information.cfg.in _update_hash_filename_ = templates/replicate-publish-slave-information.cfg.in
......
...@@ -137,16 +137,17 @@ context = ...@@ -137,16 +137,17 @@ context =
{% endfor %} {% endfor %}
{% do slave.__setitem__('server-alias', ' '.join(slave_server_alias_unclashed)) %} {% do slave.__setitem__('server-alias', ' '.join(slave_server_alias_unclashed)) %}
{% endif %} {% endif %}
{% if slave.get('url') %} {% for url_key in ['url', 'https-url'] %}
{% if subprocess_module.call([caddy_backend_url_validator, '' ~ slave['url']]) == 1 or not validators.url('' ~ slave['url']) %} {% if slave.get(url_key) %}
{% do slave_error_list.append('slave url %r invalid' % (slave['url'],)) %} {% 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 %} {% endif %}
{% endif %} {% if subprocess_module.call([caddy_backend_url_validator, url]) == 1 or not validators.url(url) %}
{% if slave.get('https-url') %} {% do slave_error_list.append('slave %s %r invalid' % (url_key, 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'],)) %}
{% endif %} {% endif %}
{% endif %} {% endif %}
{% endfor %}
{% if 'ssl_proxy_ca_crt' in slave %} {% if 'ssl_proxy_ca_crt' in slave %}
{% set ssl_proxy_ca_crt = slave.get('ssl_proxy_ca_crt', '') %} {% set ssl_proxy_ca_crt = slave.get('ssl_proxy_ca_crt', '') %}
{% set check_popen = popen([parameter_dict['openssl'], 'x509', '-noout']) %} {% set check_popen = popen([parameter_dict['openssl'], 'x509', '-noout']) %}
......
...@@ -49,7 +49,7 @@ create = true ...@@ -49,7 +49,7 @@ create = true
{%- for slave_instance in slave_instance_list %} {%- for slave_instance in slave_instance_list %}
{#- prepare backend parameters #} {#- prepare backend parameters #}
{%- for key, prefix in [('url', 'http_backend'), ('https-url', 'https_backend')] %} {%- 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} %} {%- 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) %} {%- do slave_instance.__setitem__(prefix, info_dict) %}
{%- endfor %} {%- endfor %}
......
...@@ -1127,7 +1127,9 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin): ...@@ -1127,7 +1127,9 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
'empty': { 'empty': {
}, },
'Url': { '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 # authenticating to http backend shall be no-op
'authenticate-to-backend': True, 'authenticate-to-backend': True,
}, },
...@@ -1562,7 +1564,11 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin): ...@@ -1562,7 +1564,11 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
'rejected-slave-amount': '0', 'rejected-slave-amount': '0',
'slave-amount': '56', 'slave-amount': '56',
'rejected-slave-dict': { 'rejected-slave-dict': {
} },
'warning-slave-dict': {
'_Url': [
"slave url ' %(backend)s ' has been converted to '%(backend)s'" % {
'backend': self.backend_url}]}
} }
self.assertEqual( 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