1
+ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
1
2
import base64
3
+ import html
2
4
import os
5
+ from unittest .mock import patch
3
6
4
7
from odoo .exceptions import AccessDenied , UserError , ValidationError
5
8
from odoo .tests import HttpCase , tagged
@@ -85,6 +88,21 @@ def test_ensure_provider_appears_on_login(self):
85
88
self .assertIn ("Login with Authentic" , response .text )
86
89
self .assertIn (self .url_saml_request , response .text )
87
90
91
+ def test_ensure_provider_appears_on_login_with_redirect_param (self ):
92
+ """Test that SAML provider is listed in the login page keeping the redirect"""
93
+ response = self .url_open (
94
+ "/web/login?redirect=%2Fweb%23action%3D37%26model%3Dir.module.module%26view"
95
+ "_type%3Dkanban%26menu_id%3D5"
96
+ )
97
+ self .assertIn ("Login with Authentic" , response .text )
98
+ self .assertIn (
99
+ "/auth_saml/get_auth_request?pid={}&redirect=%2Fweb%23action%3D37%26mod"
100
+ "el%3Dir.module.module%26view_type%3Dkanban%26menu_id%3D5" .format (
101
+ self .saml_provider .id
102
+ ),
103
+ response .text ,
104
+ )
105
+
88
106
def test_ensure_metadata_present (self ):
89
107
response = self .url_open (
90
108
"/auth_saml/metadata?p=%d&d=%s"
@@ -96,7 +114,7 @@ def test_ensure_metadata_present(self):
96
114
97
115
def test_ensure_get_auth_request_redirects (self ):
98
116
response = self .url_open (
99
- "/auth_saml/get_auth_request?pid=%d" % ( self .saml_provider .id ) ,
117
+ "/auth_saml/get_auth_request?pid=%d" % self .saml_provider .id ,
100
118
allow_redirects = False ,
101
119
)
102
120
self .assertTrue (response .ok )
@@ -160,14 +178,15 @@ def test_login_with_saml(self):
160
178
self .assertEqual (200 , response .status_code )
161
179
unpacked_response = response ._unpack ()
162
180
163
- (_database , login , token ) = (
181
+ (database , login , token ) = (
164
182
self .env ["res.users" ]
165
183
.sudo ()
166
184
.auth_saml (
167
185
self .saml_provider .id , unpacked_response .get ("SAMLResponse" ), None
168
186
)
169
187
)
170
188
189
+ self .assertEqual (database , self .env .cr .dbname )
171
190
self .assertEqual (login , self .user .login )
172
191
173
192
# We should not be able to log in with the wrong token
@@ -273,3 +292,46 @@ def test_disallow_user_admin_can_have_password(self):
273
292
).value = "False"
274
293
# Test base.user_admin exception
275
294
self .env .ref ("base.user_admin" ).password = "nNRST4j*->sEatNGg._!"
295
+
296
+ def test_db_filtering (self ):
297
+ # change filter to only allow our db.
298
+ with patch ("odoo.http.db_filter" , new = lambda * args , ** kwargs : []):
299
+ self .add_provider_to_user ()
300
+
301
+ redirect_url = self .saml_provider ._get_auth_request ()
302
+ response = self .idp .fake_login (redirect_url )
303
+ unpacked_response = response ._unpack ()
304
+
305
+ for key in unpacked_response :
306
+ unpacked_response [key ] = html .unescape (unpacked_response [key ])
307
+ response = self .url_open ("/auth_saml/signin" , data = unpacked_response )
308
+ self .assertFalse (response .ok )
309
+ self .assertIn (response .status_code , [400 , 404 ])
310
+
311
+ def test_redirect_after_login (self ):
312
+ """Test that providing a redirect will be kept after SAML login."""
313
+ self .add_provider_to_user ()
314
+
315
+ redirect_url = self .saml_provider ._get_auth_request (
316
+ {
317
+ "r" : "%2Fweb%23action%3D37%26model%3Dir.module.module%26view_type%3Dkanban%26menu_id%3D5"
318
+ }
319
+ )
320
+ response = self .idp .fake_login (redirect_url )
321
+ unpacked_response = response ._unpack ()
322
+
323
+ for key in unpacked_response :
324
+ unpacked_response [key ] = html .unescape (unpacked_response [key ])
325
+ response = self .url_open (
326
+ "/auth_saml/signin" ,
327
+ data = unpacked_response ,
328
+ allow_redirects = True ,
329
+ timeout = 300 ,
330
+ )
331
+ self .assertTrue (response .ok )
332
+ self .assertEqual (response .status_code , 200 )
333
+ self .assertEqual (
334
+ response .url ,
335
+ self .base_url ()
336
+ + "/web#action=37&model=ir.module.module&view_type=kanban&menu_id=5" ,
337
+ )
0 commit comments