[FIX] auth_totp: unbound request with xmlrpc
Enable TOTP on your account and create yourself an API key. Connect in xmlrpc using that API key. Traceback `request` is not bound. Fixes: odoo/documentation#6919 See also: #147475 closes odoo/odoo#146270 Signed-off-by: Julien Castiaux (juc) <juc@odoo.com>
This commit is contained in:
@@ -16,11 +16,8 @@ from ..controllers.home import Home
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@tagged('post_install', '-at_install')
|
||||
class TestTOTP(HttpCaseWithUserDemo):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
class TestTOTPMixin:
|
||||
def install_totphook(self):
|
||||
totp = None
|
||||
# might be possible to do client-side using `crypto.subtle` instead of
|
||||
# this horror show, but requires working on 64b integers, & BigInt is
|
||||
@@ -47,6 +44,13 @@ class TestTOTP(HttpCaseWithUserDemo):
|
||||
del Home.totp_hook
|
||||
self.env.registry.clear_cache('routing')
|
||||
|
||||
|
||||
@tagged('post_install', '-at_install')
|
||||
class TestTOTP(HttpCaseWithUserDemo, TestTOTPMixin):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.install_totphook()
|
||||
|
||||
def test_totp(self):
|
||||
# TODO: Make this work if no demo data + hr installed
|
||||
if not loaded_demo_data(self.env):
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
{
|
||||
'name': 'Tests flow of API keys',
|
||||
'category': 'Tools',
|
||||
'depends': ['web_tour'],
|
||||
'depends': ['web_tour', 'auth_totp'],
|
||||
'assets': {
|
||||
'web.assets_tests': [
|
||||
# inside .
|
||||
|
||||
@@ -56,7 +56,7 @@ registry.category("web_tour.tours").add('apikeys_tour_setup', {
|
||||
$('button:contains("Done")').click();
|
||||
}
|
||||
}, {
|
||||
content: "check that our key is present",
|
||||
content: "check that our key is present (FIXME: requires HR to be installed)",
|
||||
trigger: '[name=api_key_ids] td:contains("my key")',
|
||||
run() {},
|
||||
}]});
|
||||
|
||||
@@ -4,12 +4,13 @@ import json
|
||||
from odoo import api
|
||||
from odoo.tests import tagged, get_db_name, loaded_demo_data
|
||||
from odoo.addons.base.tests.common import HttpCaseWithUserDemo
|
||||
from odoo.addons.auth_totp.tests.test_totp import TestTOTPMixin
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@tagged('post_install', '-at_install')
|
||||
class TestAPIKeys(HttpCaseWithUserDemo):
|
||||
class TestAPIKeys(HttpCaseWithUserDemo, TestTOTPMixin):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
@@ -44,3 +45,16 @@ class TestAPIKeys(HttpCaseWithUserDemo):
|
||||
"the key should be usable as a way to perform RPC calls"
|
||||
)
|
||||
self.start_tour('/web', 'apikeys_tour_teardown', login='demo')
|
||||
|
||||
def test_apikeys_totp(self):
|
||||
# TODO: Make this work if no demo data + hr installed
|
||||
if not loaded_demo_data(self.env):
|
||||
_logger.warning("This test relies on demo data. To be rewritten independently of demo data for accurate and reliable results.")
|
||||
return
|
||||
db = get_db_name()
|
||||
self.install_totphook()
|
||||
self.start_tour('/web', 'apikeys_tour_setup', login='demo')
|
||||
self.start_tour('/web', 'totp_tour_setup', login='demo')
|
||||
[(_, [key], [])] = self.messages # pylint: disable=unbalanced-tuple-unpacking
|
||||
uid = self.xmlrpc_common.authenticate(db, 'demo', key, {})
|
||||
self.assertEqual(uid, self.env.ref('base.user_demo').id)
|
||||
|
||||
Reference in New Issue
Block a user