summaryrefslogtreecommitdiff
path: root/addons/auth_totp_portal/tests
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/auth_totp_portal/tests
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/auth_totp_portal/tests')
-rw-r--r--addons/auth_totp_portal/tests/__init__.py1
-rw-r--r--addons/auth_totp_portal/tests/test_tour.py44
2 files changed, 45 insertions, 0 deletions
diff --git a/addons/auth_totp_portal/tests/__init__.py b/addons/auth_totp_portal/tests/__init__.py
new file mode 100644
index 00000000..f49429ef
--- /dev/null
+++ b/addons/auth_totp_portal/tests/__init__.py
@@ -0,0 +1 @@
+from . import test_tour
diff --git a/addons/auth_totp_portal/tests/test_tour.py b/addons/auth_totp_portal/tests/test_tour.py
new file mode 100644
index 00000000..242c9f0d
--- /dev/null
+++ b/addons/auth_totp_portal/tests/test_tour.py
@@ -0,0 +1,44 @@
+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
+
+
+@tagged('post_install', '-at_install')
+class TestTOTPortal(HttpCase):
+ """
+ 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.start_tour('/my/security', 'totportal_tour_setup', login='portal')
+ # also disables totp otherwise we can't re-login
+ self.start_tour('/', 'totportal_login_enabled', login=None)
+ self.start_tour('/', 'totportal_login_disabled', login=None)