[FIX] http_routing: /r russian vs /r link tracker
Install website_links, create a link e.g. to http://example.com, install the russian language and translate the default website. Access the short link you created before-hand, 404 website page not found. Accessing a website starting with /r is ambiguous, is /r the link-tracker controller or is /r a russian lang alias (nearest lang algorithm)? The controller should be prioritary to the lang alias. This restore the behavior as it was before the httpocalyse. closes odoo/odoo#99555 X-original-commit: e8a1b4c0cdffb38e48ca980205a61c75c564dee8 Signed-off-by: Jérémy Kersten <jke@odoo.com> Signed-off-by: Julien Castiaux <juc@odoo.com>
This commit is contained in:
@@ -402,16 +402,19 @@ class IrHttp(models.AbstractModel):
|
||||
return super()._match(path)
|
||||
|
||||
# See /1, match a non website endpoint
|
||||
with contextlib.suppress(NotFound):
|
||||
try:
|
||||
rule, args = super()._match(path)
|
||||
routing = rule.endpoint.routing
|
||||
request.is_frontend = routing.get('website', False)
|
||||
request.is_frontend_multilang = request.is_frontend and routing.get('multilang', routing['type'] == 'http')
|
||||
if not request.is_frontend:
|
||||
return rule, args
|
||||
|
||||
_, url_lang_str, *rest = path.split('/', 2)
|
||||
path_no_lang = '/' + (rest[0] if rest else '')
|
||||
except NotFound:
|
||||
_, url_lang_str, *rest = path.split('/', 2)
|
||||
path_no_lang = '/' + (rest[0] if rest else '')
|
||||
else:
|
||||
url_lang_str = ''
|
||||
path_no_lang = path
|
||||
allow_redirect = request.httprequest.method != 'POST'
|
||||
|
||||
# There is no user on the environment yet but the following code
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import test_controller
|
||||
from . import test_ui
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.tests import tagged
|
||||
from odoo.tests.common import HttpCase
|
||||
|
||||
|
||||
@tagged('post_install', '-at_install')
|
||||
class TestWebsiteLinksRussian(HttpCase):
|
||||
"""
|
||||
The /r URL prefix is considered as an alias to /ru by the "nearest
|
||||
lang" algorithm of our http router (http_routing match). This test
|
||||
suite makes sure that there the link-tracker "/r" controller is not
|
||||
affected by any (wrong) /ru redirection.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.link = cls.env['link.tracker'].create({
|
||||
'url': cls.base_url() + '/web/health', # no-op route
|
||||
})
|
||||
|
||||
# Courtesy of website/tests/test_lang_url.py
|
||||
website = cls.env.ref('website.default_website')
|
||||
lang_en = cls.env.ref('base.lang_en')
|
||||
lang_ru = cls.env['res.lang']._activate_lang('ru_RU')
|
||||
website.language_ids = lang_en + lang_ru
|
||||
website.default_lang_id = lang_en
|
||||
|
||||
def test0_direct_link_tracker(self):
|
||||
res = self.url_open(f'/r/{self.link.code}', allow_redirects=False)
|
||||
res.raise_for_status()
|
||||
self.assertEqual(res.status_code, 301, "Should be link-tracking redirection")
|
||||
self.assertEqual(res.headers.get('Location'), self.link.url,
|
||||
"Should not be redirected to /ru")
|
||||
|
||||
def test1_russian_link_tracker(self):
|
||||
res = self.url_open(f'/r/r/{self.link.code}', allow_redirects=False)
|
||||
res.raise_for_status()
|
||||
self.assertEqual(res.status_code, 301, "Should be a lang alias redirection")
|
||||
self.assertEqual(res.headers.get('Location'), f'{self.base_url()}/ru/r/{self.link.code}',
|
||||
"Should be redirected to /ru as r is an alias for ru (russian)")
|
||||
|
||||
res = self.url_open(res.headers['Location'], allow_redirects=False)
|
||||
res.raise_for_status()
|
||||
self.assertEqual(res.status_code, 301, "Should be a link-tracking redirection")
|
||||
self.assertEqual(res.headers.get('Location'), self.link.url,
|
||||
"Should not be redirected to /ru")
|
||||
|
||||
def test2_russian_page(self):
|
||||
# This generate a new unused link
|
||||
no_link_code = self.env['link.tracker.code']._get_random_code_strings()[0]
|
||||
|
||||
view = self.env['ir.ui.view'].create({
|
||||
'name': 'Base',
|
||||
'type': 'qweb',
|
||||
'arch': '<div>Welcome to this webpage!</div>',
|
||||
'key': 'test.base_view',
|
||||
})
|
||||
self.env['website.page'].create({
|
||||
'url': f'/{no_link_code}',
|
||||
'view_id': view.id,
|
||||
'website_published': True,
|
||||
})
|
||||
|
||||
res = self.url_open(f'/r/{no_link_code}', allow_redirects=False)
|
||||
self.assertEqual(res.status_code, 404, "No link tracker exists for the requested code")
|
||||
Reference in New Issue
Block a user