mirror of
https://github.com/bringout/oca-ocb-security.git
synced 2026-04-26 01:02:06 +02:00
19.0 vanilla
This commit is contained in:
parent
20ddc1b4a3
commit
c0efcc53f5
1162 changed files with 125577 additions and 105287 deletions
|
|
@ -1,10 +1,6 @@
|
|||
import logging
|
||||
import time
|
||||
|
||||
from passlib.totp import TOTP
|
||||
|
||||
from odoo import http
|
||||
from odoo.addons.auth_totp.controllers.home import Home
|
||||
from odoo.addons.auth_totp.tests.test_totp import TestTOTPMixin
|
||||
from odoo.addons.base.tests.common import HttpCaseWithUserPortal
|
||||
from odoo.tests import tagged
|
||||
|
||||
|
|
@ -12,35 +8,12 @@ _logger = logging.getLogger(__name__)
|
|||
|
||||
|
||||
@tagged('post_install', '-at_install')
|
||||
class TestTOTPortal(HttpCaseWithUserPortal):
|
||||
class TestTOTPortal(HttpCaseWithUserPortal, TestTOTPMixin):
|
||||
"""
|
||||
Largely replicates TestTOTP
|
||||
"""
|
||||
def test_totp(self):
|
||||
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)
|
||||
def totp_hook(self, secret=None):
|
||||
nonlocal totp
|
||||
if totp is None:
|
||||
totp = TOTP(secret)
|
||||
if secret:
|
||||
return totp.generate().token
|
||||
else:
|
||||
# on check, take advantage of window because previous token has been
|
||||
# "burned" so we can't generate the same, but tour is so fast
|
||||
# we're pretty certainly within the same 30s
|
||||
return totp.generate(time.time() + 30).token
|
||||
# because not preprocessed by ControllerType metaclass
|
||||
totp_hook.routing_type = 'json'
|
||||
# patch Home to add test endpoint
|
||||
Home.totp_hook = http.route('/totphook', type='json', auth='none')(totp_hook)
|
||||
self.env['ir.http']._clear_routing_map()
|
||||
# remove endpoint and destroy routing map
|
||||
@self.addCleanup
|
||||
def _cleanup():
|
||||
del Home.totp_hook
|
||||
self.env['ir.http']._clear_routing_map()
|
||||
self.install_totphook()
|
||||
|
||||
self.start_tour('/my/security', 'totportal_tour_setup', login='portal')
|
||||
# also disables totp otherwise we can't re-login
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue