import base64 from unittest.mock import patch from django.test.client import Client import pytest @pytest.fixture def client(): client = Client(HTTP_HOST="example.com") return client @pytest.fixture def saml_settings(settings): settings.SOCIALACCOUNT_PROVIDERS = { "saml": { "APPS": [ { "client_id": "org", "provider_id": "urn:dev-123.us.auth0.com", "settings": { "attribute_mapping": { "uid": "http://schemas.auth0.com/clientID", "email_verified": "http://schemas.auth0.com/email_verified", "email": "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress", }, "idp": { "name": "Test IdP", "entity_id": "urn:dev-123.us.auth0.com", "sso_url": "https://dev-123.us.auth0.com/samlp/456", "slo_url": "https://dev-123.us.auth0.com/samlp/456", "x509cert": "", }, "advanced": { "strict": False, }, }, } ] } } @pytest.fixture def acs_saml_response(): xml = """ urn:dev-123.us.auth0.com urn:dev-123.us.auth0.com 123 If7dFg... MIIDHTCC... google-oauth2|108204123456789 https://allauth.org/accounts/org/metadata/ urn:oasis:names:tc:SAML:2.0:ac:classes:unspecified google-oauth2|108204123456789 john.doe@email.org John John john.doe@email.org google-oauth2 google-oauth2 true dummysamluid Wed Jun 28 2023 17:53:49 GMT+0000 (Coordinated Universal Time) true en john.doe https://lh3.googleusercontent.com/a/AAcHTtfZ0fEyL3BKP1Hk2v1bNwpJd6ckIeo6jSExlkVjMXaIpsY=s96-c Sat Jul 08 2023 06:13:07 GMT+0000 (Coordinated Universal Time) view-profile manage-account-links """ return base64.b64encode(xml.encode("utf8")).decode("utf8") @pytest.fixture def sls_saml_request(): xml = "" return base64.b64encode(xml.encode("utf8")).decode("utf8") @pytest.fixture def mocked_signature_validation(): with patch("onelogin.saml2.utils.OneLogin_Saml2_Utils.validate_sign") as mock: mock.return_value = True yield