Skip to content

Commit c0156e7

Browse files
committed
fixup improve coverage with signature errors
1 parent ed616d7 commit c0156e7

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

auth_saml/tests/fake_idp.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,14 @@ def authn_request_endpoint(self, req, binding, relay_state):
165165
)
166166

167167
return DummyResponse(**_dict)
168+
169+
170+
class UnsignedFakeIDP(FakeIDP):
171+
172+
def create_authn_response(
173+
self,
174+
*args,
175+
**kwargs,
176+
):
177+
kwargs["sign_assertion"] = False
178+
return super().create_authn_response(*args, **kwargs)

auth_saml/tests/test_pysaml.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
from unittest.mock import patch
88

99
import responses
10+
from saml2.sigver import SignatureError
1011

1112
from odoo.exceptions import AccessDenied, UserError, ValidationError
1213
from odoo.tests import HttpCase, tagged
14+
from odoo.tools import mute_logger
1315

14-
from .fake_idp import CONFIG, FakeIDP
16+
from .fake_idp import CONFIG, FakeIDP, UnsignedFakeIDP
1517

1618

1719
@tagged("saml", "post_install", "-at_install")
@@ -452,3 +454,35 @@ def test_login_with_saml_metadata_key_changed(self):
452454
body=up_to_date_metadata,
453455
)
454456
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

Comments
 (0)