[FIX] auth_totp,auth_signup: Make tests demo data independent

Part-of: odoo/odoo#146649
This commit is contained in:
Yannick Tivisse
2023-12-18 23:32:05 +00:00
parent b1537a0868
commit 2aa2d2655c
4 changed files with 45 additions and 12 deletions
+5 -4
View File
@@ -4,11 +4,12 @@
from unittest.mock import patch
import odoo
from odoo.tests import HttpCase
from odoo import http
from odoo.addons.base.tests.common import HttpCaseWithUserPortal, HttpCaseWithUserDemo
from odoo.exceptions import AccessError
class TestAuthSignupFlow(HttpCase):
class TestAuthSignupFlow(HttpCaseWithUserPortal, HttpCaseWithUserDemo):
def setUp(self):
super(TestAuthSignupFlow, self).setUp()
@@ -55,10 +56,10 @@ class TestAuthSignupFlow(HttpCase):
self.assertTrue(mail, "The new user must be informed of his registration")
def test_compute_signup_url(self):
user = self.env.ref('base.user_demo')
user = self.user_demo
user.groups_id -= self.env.ref('base.group_partner_manager')
partner = self.env.ref('base.partner_demo_portal')
partner = self.partner_portal
partner.signup_prepare()
with self.assertRaises(AccessError):
+21 -5
View File
@@ -1,3 +1,4 @@
import logging
import json
import time
from xmlrpc.client import Fault
@@ -5,18 +6,21 @@ from xmlrpc.client import Fault
from passlib.totp import TOTP
from odoo import http
from odoo.addons.base.tests.common import HttpCaseWithUserDemo
from odoo.exceptions import AccessDenied
from odoo.service import common as auth, model
from odoo.tests import tagged, HttpCase, get_db_name
from odoo.tests import tagged, get_db_name, loaded_demo_data
from odoo.tools import mute_logger
from ..controllers.home import Home
_logger = logging.getLogger(__name__)
@tagged('post_install', '-at_install')
class TestTOTP(HttpCase):
class TestTOTP(HttpCaseWithUserDemo):
def setUp(self):
super().setUp()
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
@@ -44,6 +48,10 @@ class TestTOTP(HttpCase):
self.env.registry.clear_cache('routing')
def test_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
# 1. Enable 2FA
self.start_tour('/web', 'totp_tour_setup', login='demo')
@@ -56,7 +64,7 @@ class TestTOTP(HttpCase):
self.xmlrpc_common.authenticate(get_db_name(), 'demo', 'demo', {'interactive': True}),
'Trying to fake the auth type should not work'
)
uid = self.env.ref('base.user_demo').id
uid = self.user_demo.id
with self.assertRaisesRegex(Fault, r'Access Denied'):
self.xmlrpc_object.execute_kw(
get_db_name(), uid, 'demo',
@@ -74,7 +82,7 @@ class TestTOTP(HttpCase):
# 6. Check that rpc is now re-allowed
uid = self.xmlrpc_common.authenticate(get_db_name(), 'demo', 'demo', {})
self.assertEqual(uid, self.env.ref('base.user_demo').id)
self.assertEqual(uid, self.user_demo.id)
[r] = self.xmlrpc_object.execute_kw(
get_db_name(), uid, 'demo',
'res.users', 'read', [uid, ['login']]
@@ -83,6 +91,10 @@ class TestTOTP(HttpCase):
def test_totp_administration(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
self.start_tour('/web', 'totp_tour_setup', login='demo')
self.start_tour('/web', 'totp_admin_disables', login='admin')
self.start_tour('/', 'totp_login_disabled', login=None)
@@ -93,6 +105,10 @@ class TestTOTP(HttpCase):
Ensure we don't leak the session info from an half-logged-in
user.
"""
# 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
self.start_tour('/web', 'totp_tour_setup', login='demo')
self.url_open('/web/session/logout')
+9 -1
View File
@@ -1,13 +1,21 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.tests import tagged
import logging
from odoo.tests import tagged, loaded_demo_data
from odoo.addons.auth_totp.tests.test_totp import TestTOTP
_logger = logging.getLogger(__name__)
@tagged('post_install', '-at_install')
class TestTOTPInvite(TestTOTP):
def test_totp_administration(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
self.start_tour('/web', 'totp_admin_invite', login='admin')
self.start_tour('/web', 'totp_admin_self_invite', login='admin')
+10 -2
View File
@@ -1,18 +1,26 @@
import logging
import time
from passlib.totp import TOTP
from odoo import http
from odoo.tests import tagged, HttpCase
from odoo.addons.auth_totp.controllers.home import Home
from odoo.addons.base.tests.common import HttpCaseWithUserPortal
from odoo.tests import tagged, loaded_demo_data
_logger = logging.getLogger(__name__)
@tagged('post_install', '-at_install')
class TestTOTPortal(HttpCase):
class TestTOTPortal(HttpCaseWithUserPortal):
"""
Largely replicates TestTOTP
"""
def test_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
totp = None
# test endpoint as doing totp on the client side is not really an option
# (needs sha1 and hmac + BE packing of 64b integers)