|
7 | 7 | from unittest.mock import patch |
8 | 8 |
|
9 | 9 | import responses |
| 10 | +from saml2.sigver import SignatureError |
10 | 11 |
|
11 | 12 | from odoo.exceptions import AccessDenied, UserError, ValidationError |
12 | 13 | from odoo.tests import HttpCase, tagged |
| 14 | +from odoo.tools import mute_logger |
13 | 15 |
|
14 | | -from .fake_idp import CONFIG, FakeIDP |
| 16 | +from .fake_idp import CONFIG, FakeIDP, UnsignedFakeIDP |
15 | 17 |
|
16 | 18 |
|
17 | 19 | @tagged("saml", "post_install", "-at_install") |
@@ -452,3 +454,35 @@ def test_login_with_saml_metadata_key_changed(self): |
452 | 454 | body=up_to_date_metadata, |
453 | 455 | ) |
454 | 456 | self.test_login_with_saml() |
| 457 | + |
| 458 | + @responses.activate |
| 459 | + def test_login_with_saml_unsigned_response(self): |
| 460 | + self.add_provider_to_user() |
| 461 | + self.saml_provider.idp_metadata_url = "http://localhost:8000/metadata" |
| 462 | + unsigned_idp = UnsignedFakeIDP([self.saml_provider._metadata_string()]) |
| 463 | + redirect_url = self.saml_provider._get_auth_request() |
| 464 | + self.assertIn("http://localhost:8000/sso/redirect?SAMLRequest=", redirect_url) |
| 465 | + |
| 466 | + response = unsigned_idp.fake_login(redirect_url) |
| 467 | + self.assertEqual(200, response.status_code) |
| 468 | + unpacked_response = response._unpack() |
| 469 | + |
| 470 | + responses.add( |
| 471 | + responses.GET, |
| 472 | + "http://localhost:8000/metadata", |
| 473 | + status=200, |
| 474 | + content_type="text/xml", |
| 475 | + body=self.saml_provider.idp_metadata, |
| 476 | + ) |
| 477 | + with ( |
| 478 | + self.assertRaises(SignatureError), |
| 479 | + mute_logger("saml2.entity"), |
| 480 | + mute_logger("saml2.client_base"), |
| 481 | + ): |
| 482 | + (database, login, token) = ( |
| 483 | + self.env["res.users"] |
| 484 | + .sudo() |
| 485 | + .auth_saml( |
| 486 | + self.saml_provider.id, unpacked_response.get("SAMLResponse"), None |
| 487 | + ) |
| 488 | + ) |
0 commit comments