Commit 45c2762d authored by Łukasz Nowak's avatar Łukasz Nowak

rapid-cdn: Avoid needless trailing slash sent to backend

Cover a case of not adding needless trailing / while accessing a backend from
top level of the URL.

As / are stripped while parsing the url, expose the situation that even if
url ends with a /, it won't be sent for top level access.

Here is the mapping of configured URL, path accessed on the CDN side and path
sent to the backend:

 * backend/index.html   frontend/     index.html
 * backend/index.html   frontend/a    index.html/a
 * backend/index.html   frontend/a/   index.html/a/
 * backend/index.html/  frontend/     index.html
 * backend/index.html/  frontend/a    index.html/a
 * backend/index.html/  frontend/a/   index.html/a/
parent 1b100a57
Pipeline #30790 failed with stage
in 0 seconds
...@@ -50,7 +50,7 @@ md5sum = d56e2cfab274cbbbe5b387f2f6e417df ...@@ -50,7 +50,7 @@ md5sum = d56e2cfab274cbbbe5b387f2f6e417df
[template-backend-haproxy-configuration] [template-backend-haproxy-configuration]
_update_hash_filename_ = templates/backend-haproxy.cfg.in _update_hash_filename_ = templates/backend-haproxy.cfg.in
md5sum = 6457064905f818f21e3733eb4278a580 md5sum = 629f4cc34dd7512eb61f10eac4e62d7a
[template-empty] [template-empty]
_update_hash_filename_ = templates/empty.in _update_hash_filename_ = templates/empty.in
......
...@@ -128,7 +128,7 @@ backend {{ slave_instance['slave_reference'] }}-{{ scheme }} ...@@ -128,7 +128,7 @@ backend {{ slave_instance['slave_reference'] }}-{{ scheme }}
{{ active_check_option }} {{ active_check_option }}
{%- endfor %} {%- endfor %}
{%- if path %} {%- if path %}
http-request set-path {{ path }}%[path] http-request set-path {{ path }}%[path,regsub('^/$','')]
{%- endif %} {%- endif %}
{%- endif %} {%- endif %}
{%- endif %} {%- endif %}
...@@ -175,7 +175,7 @@ backend {{ slave_instance['slave_reference'] }}-{{ scheme }}-failover ...@@ -175,7 +175,7 @@ backend {{ slave_instance['slave_reference'] }}-{{ scheme }}-failover
timeout server {{ slave_instance['request-timeout'] }}s timeout server {{ slave_instance['request-timeout'] }}s
retries {{ slave_instance['backend-connect-retries'] }} retries {{ slave_instance['backend-connect-retries'] }}
{%- if path %} {%- if path %}
http-request set-path {{ path }}%[path] http-request set-path {{ path }}%[path,regsub('^/$','')]
{%- endif %} {%- endif %}
{%- endif %} {%- endif %}
{%- endif %} {%- endif %}
......
...@@ -1654,6 +1654,12 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin): ...@@ -1654,6 +1654,12 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
# authenticating to http backend shall be no-op # authenticating to http backend shall be no-op
'authenticate-to-backend': True, 'authenticate-to-backend': True,
}, },
'url-trailing-slash-absent': {
'url': cls.backend_url + 'index.html',
},
'url-trailing-slash-present': {
'url': cls.backend_url + 'index.html/',
},
'url-netloc-list': { 'url-netloc-list': {
'url': cls.backend_url, 'url': cls.backend_url,
'url-netloc-list': '%(ip)s:%(port_a)s %(ip)s:%(port_b)s' % { 'url-netloc-list': '%(ip)s:%(port_a)s %(ip)s:%(port_b)s' % {
...@@ -2123,9 +2129,9 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin): ...@@ -2123,9 +2129,9 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
'monitor-base-url': 'https://[%s]:8401' % self.master_ipv6, 'monitor-base-url': 'https://[%s]:8401' % self.master_ipv6,
'backend-client-caucase-url': 'http://[%s]:8990' % self.master_ipv6, 'backend-client-caucase-url': 'http://[%s]:8990' % self.master_ipv6,
'domain': 'example.com', 'domain': 'example.com',
'accepted-slave-amount': '62', 'accepted-slave-amount': '64',
'rejected-slave-amount': '0', 'rejected-slave-amount': '0',
'slave-amount': '62', 'slave-amount': '64',
'rejected-slave-dict': { 'rejected-slave-dict': {
}, },
'warning-slave-dict': { 'warning-slave-dict': {
...@@ -2462,6 +2468,30 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin): ...@@ -2462,6 +2468,30 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
j['Incoming Headers']['x-forwarded-for'] j['Incoming Headers']['x-forwarded-for']
) )
def test_url_trailing_slash_absent(self):
parameter_dict = self.assertSlaveBase('url-trailing-slash-absent')
self.assertEqual(
fakeHTTPSResult(parameter_dict['domain'], '').json()['Path'],
'/index.html')
self.assertEqual(
fakeHTTPSResult(parameter_dict['domain'], 'path').json()['Path'],
'/index.html/path')
self.assertEqual(
fakeHTTPSResult(parameter_dict['domain'], 'path/').json()['Path'],
'/index.html/path/')
def test_url_trailing_slash_present(self):
parameter_dict = self.assertSlaveBase('url-trailing-slash-present')
self.assertEqual(
fakeHTTPSResult(parameter_dict['domain'], '').json()['Path'],
'/index.html')
self.assertEqual(
fakeHTTPSResult(parameter_dict['domain'], 'path').json()['Path'],
'/index.html/path')
self.assertEqual(
fakeHTTPSResult(parameter_dict['domain'], 'path/').json()['Path'],
'/index.html/path/')
def test_url_netloc_list(self): def test_url_netloc_list(self):
parameter_dict = self.assertSlaveBase('url-netloc-list') parameter_dict = self.assertSlaveBase('url-netloc-list')
result = fakeHTTPSResult(parameter_dict['domain'], 'path') result = fakeHTTPSResult(parameter_dict['domain'], 'path')
......
...@@ -182,6 +182,12 @@ T-2/var/log/httpd/_type-zope_frontend_log ...@@ -182,6 +182,12 @@ T-2/var/log/httpd/_type-zope_frontend_log
T-2/var/log/httpd/_url-netloc-list_access_log T-2/var/log/httpd/_url-netloc-list_access_log
T-2/var/log/httpd/_url-netloc-list_backend_log T-2/var/log/httpd/_url-netloc-list_backend_log
T-2/var/log/httpd/_url-netloc-list_frontend_log T-2/var/log/httpd/_url-netloc-list_frontend_log
T-2/var/log/httpd/_url-trailing-slash-absent_access_log
T-2/var/log/httpd/_url-trailing-slash-absent_backend_log
T-2/var/log/httpd/_url-trailing-slash-absent_frontend_log
T-2/var/log/httpd/_url-trailing-slash-present_access_log
T-2/var/log/httpd/_url-trailing-slash-present_backend_log
T-2/var/log/httpd/_url-trailing-slash-present_frontend_log
T-2/var/log/httpd/_url_https-url_access_log T-2/var/log/httpd/_url_https-url_access_log
T-2/var/log/httpd/_url_https-url_backend_log T-2/var/log/httpd/_url_https-url_backend_log
T-2/var/log/httpd/_url_https-url_frontend_log T-2/var/log/httpd/_url_https-url_frontend_log
......
...@@ -182,6 +182,12 @@ T-2/var/log/httpd/_type-zope_frontend_log ...@@ -182,6 +182,12 @@ T-2/var/log/httpd/_type-zope_frontend_log
T-2/var/log/httpd/_url-netloc-list_access_log T-2/var/log/httpd/_url-netloc-list_access_log
T-2/var/log/httpd/_url-netloc-list_backend_log T-2/var/log/httpd/_url-netloc-list_backend_log
T-2/var/log/httpd/_url-netloc-list_frontend_log T-2/var/log/httpd/_url-netloc-list_frontend_log
T-2/var/log/httpd/_url-trailing-slash-absent_access_log
T-2/var/log/httpd/_url-trailing-slash-absent_backend_log
T-2/var/log/httpd/_url-trailing-slash-absent_frontend_log
T-2/var/log/httpd/_url-trailing-slash-present_access_log
T-2/var/log/httpd/_url-trailing-slash-present_backend_log
T-2/var/log/httpd/_url-trailing-slash-present_frontend_log
T-2/var/log/httpd/_url_https-url_access_log T-2/var/log/httpd/_url_https-url_access_log
T-2/var/log/httpd/_url_https-url_backend_log T-2/var/log/httpd/_url_https-url_backend_log
T-2/var/log/httpd/_url_https-url_frontend_log T-2/var/log/httpd/_url_https-url_frontend_log
......
...@@ -182,6 +182,12 @@ T-2/var/log/httpd/_type-zope_frontend_log ...@@ -182,6 +182,12 @@ T-2/var/log/httpd/_type-zope_frontend_log
T-2/var/log/httpd/_url-netloc-list_access_log T-2/var/log/httpd/_url-netloc-list_access_log
T-2/var/log/httpd/_url-netloc-list_backend_log T-2/var/log/httpd/_url-netloc-list_backend_log
T-2/var/log/httpd/_url-netloc-list_frontend_log T-2/var/log/httpd/_url-netloc-list_frontend_log
T-2/var/log/httpd/_url-trailing-slash-absent_access_log
T-2/var/log/httpd/_url-trailing-slash-absent_backend_log
T-2/var/log/httpd/_url-trailing-slash-absent_frontend_log
T-2/var/log/httpd/_url-trailing-slash-present_access_log
T-2/var/log/httpd/_url-trailing-slash-present_backend_log
T-2/var/log/httpd/_url-trailing-slash-present_frontend_log
T-2/var/log/httpd/_url_https-url_access_log T-2/var/log/httpd/_url_https-url_access_log
T-2/var/log/httpd/_url_https-url_backend_log T-2/var/log/httpd/_url_https-url_backend_log
T-2/var/log/httpd/_url_https-url_frontend_log T-2/var/log/httpd/_url_https-url_frontend_log
......
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