Files
odoo_source/addons/website/tests/test_http_endpoint.py
T
Jeremy Kersten 2c4556efd1 [IMP] http_routing: support redirect of double slash in middle of path
Move code to support only the redirect from url containing double '/' in
the middle of the path.
Keep same behavior than v15 and default Apache behavior.

domain.com//shop/product/1 -> 404
domain.com/shop//product/1 -> 301 -> /shop/product/1

opw-3063387

closes odoo/odoo#106137

X-original-commit: fdd6bf9942e2807b6d1460dba1ca5f61404c7b06
Signed-off-by: Julien Castiaux <juc@odoo.com>
Signed-off-by: Jérémy Kersten <jke@odoo.com>
2022-11-21 11:50:26 +01:00

40 lines
1.4 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.tests import HttpCase
import werkzeug
class TestHttpEndPoint(HttpCase):
def test_can_clear_routing_map_during_render(self):
"""
The routing map might be cleared while rendering a qweb view.
For example, if an asset bundle is regenerated the old one is unlinked,
which causes a cache clearing.
This test ensures that the rendering still works, even in this case.
"""
homepage_view = self.env['ir.ui.view'].search([
('website_id', '=', self.env.ref('website.default_website').id),
('key', '=', 'website.homepage'),
])
self.env['ir.ui.view'].create({
'name': 'Add cache clear to Home',
'type': 'qweb',
'mode': 'extension',
'inherit_id': homepage_view.id,
'arch_db': """
<t t-call="website.layout" position="before">
<t t-esc="website.env['ir.http']._clear_routing_map()"/>
</t>
""",
})
r = self.url_open('/')
r.raise_for_status()
def test_redirect_double_slash(self):
res = self.url_open('/test_http//greeting', allow_redirects=False)
self.assertEqual(res.status_code, 301)
self.assertEqual(werkzeug.urls.url_parse(res.headers.get('Location', '')).path, '/test_http/greeting')