55import os .path as osp
66import urllib
77from copy import deepcopy
8+ from unittest import SkipTest
89from unittest .mock import patch
910
1011import responses
@@ -49,7 +50,7 @@ def setUp(self):
4950 }
5051 )
5152 self .url_saml_request = (
52- "/auth_saml/get_auth_request?pid=%d" % self .saml_provider .id
53+ f "/auth_saml/get_auth_request?pid={ self .saml_provider .id } "
5354 )
5455
5556 self .idp = FakeIDP ([self .saml_provider ._metadata_string ()])
@@ -102,8 +103,7 @@ def test_ensure_provider_appears_on_login(self):
102103 def test_ensure_provider_appears_on_login_with_redirect_param (self ):
103104 """Test that SAML provider is listed in the login page keeping the redirect"""
104105 response = self .url_open (
105- "/web/login?redirect=%2Fweb%23action%3D37%26model%3Dir.module.module%26view"
106- "_type%3Dkanban%26menu_id%3D5"
106+ "/web/login?redirect=%2Fweb%23action%3D37%26model%3Dir.module.module%26view_type%3Dkanban%26menu_id%3D5"
107107 )
108108 self .assertIn ("Login with Authentic" , response .text )
109109 self .assertIn (
@@ -184,16 +184,15 @@ def test_get_config_for_provider(self):
184184
185185 def test_ensure_metadata_present (self ):
186186 response = self .url_open (
187- "/auth_saml/metadata?p=%d&d=%s"
188- % (self .saml_provider .id , self .env .cr .dbname )
187+ f"/auth_saml/metadata?p={ self .saml_provider .id } &d={ self .env .cr .dbname } "
189188 )
190189
191190 self .assertTrue (response .ok )
192191 self .assertTrue ("xml" in response .headers .get ("Content-Type" ))
193192
194193 def test_ensure_get_auth_request_redirects (self ):
195194 response = self .url_open (
196- "/auth_saml/get_auth_request?pid=%d" % self .saml_provider .id ,
195+ f "/auth_saml/get_auth_request?pid={ self .saml_provider .id } " ,
197196 allow_redirects = False ,
198197 )
199198 self .assertTrue (response .ok )
@@ -460,17 +459,20 @@ def test_disallow_user_password_when_changing_settings(self):
460459 def test_fragment_to_query_string_no_kw (self ):
461460 """Test the case where no keyword arguments are passed."""
462461 response = self .decorated_function (self )
463- expected_html = """<html><head><script>
462+ expected_html = b """<html><head><script>
464463 var l = window.location;
465464 var q = l.hash.substring(1);
466- var r = '/' + l.search;
465+ var r = l.pathname + l.search;
467466 if(q.length !== 0) {
468467 var s = l.search ? (l.search === '?' ? '' : '&') : '?';
469468 r = l.pathname + l.search + s + q;
470469 }
470+ if (r == l.pathname) {
471+ r = '/';
472+ }
471473 window.location = r;
472474 </script></head><body></body></html>"""
473- self .assertEqual (response .strip () , expected_html . strip () )
475+ self .assertEqual (response .data , expected_html )
474476
475477 def test_fragment_to_query_string_with_kw (self ):
476478 """Test the case where keyword arguments are passed."""
@@ -648,9 +650,13 @@ def test_signin_no_relaystate_redirect(self):
648650
649651 def test_signin_redirect_mfa (self ):
650652 """Test redirect to mfa url"""
653+ if not self .env ["ir.module.module" ].search (
654+ [("name" , "=" , "auth_totp" ), ("state" , "=" , "installed" )]
655+ ):
656+ raise SkipTest ("auth_totp not installed" )
651657 self .add_provider_to_user ()
652658
653- redirect_url = self .saml_provider ._get_auth_request ({"a" : "action " })
659+ redirect_url = self .saml_provider ._get_auth_request ({"a" : "42 " })
654660 response = self .idp .fake_login (redirect_url )
655661 unpacked_response = response ._unpack ()
656662
@@ -668,7 +674,7 @@ def test_signin_redirect_mfa(self):
668674 self .assertTrue (response .ok )
669675 self .assertEqual (
670676 response .url ,
671- self .base_url () + "/web/login/totp?redirect=%2F%23action%3Daction " ,
677+ self .base_url () + "/web/login/totp?redirect=%2Fodoo%2Faction-42 " ,
672678 )
673679
674680 def test_action_redirect (self ):
@@ -690,7 +696,7 @@ def test_action_redirect(self):
690696 self .assertTrue (response .ok )
691697 self .assertEqual (
692698 response .url ,
693- self .base_url () + "/odoo# action= action" ,
699+ self .base_url () + "/odoo/ action- action" ,
694700 )
695701
696702 def test_menu_redirect (self ):
@@ -712,7 +718,7 @@ def test_menu_redirect(self):
712718 self .assertTrue (response .ok )
713719 self .assertEqual (
714720 response .url ,
715- self .base_url () + "/odoo# menu_id=12" ,
721+ self .base_url () + "/odoo? menu_id=12" ,
716722 )
717723
718724 @responses .activate
0 commit comments