def test_parse_does_not_raise_exception_when_xml_metadata_does_not_have_display_names( self, ): # Arrange metadata_parser = SAMLMetadataParser() # Act parsing_results = metadata_parser.parse( fixtures.CORRECT_XML_WITH_ONE_IDP_METADATA_WITHOUT_DISPLAY_NAMES) # Assert assert 1 == len(parsing_results) [parsing_result] = parsing_results assert True == isinstance(parsing_result, SAMLMetadataParsingResult) assert True == isinstance(parsing_result.provider, SAMLIdentityProviderMetadata) assert True == isinstance(parsing_result.xml_node, onelogin.saml2.xmlparser.RestrictedElement) assert (SAMLIdentityProviderMetadata( entity_id=fixtures.IDP_1_ENTITY_ID, ui_info=SAMLUIInfo(), organization=SAMLOrganization(), name_id_format=fixtures.NAME_ID_FORMAT_1, sso_service=SAMLService(fixtures.IDP_1_SSO_URL, fixtures.IDP_1_SSO_BINDING), want_authn_requests_signed=False, signing_certificates=[ fixtures.strip_certificate(fixtures.SIGNING_CERTIFICATE) ], encryption_certificates=[ fixtures.strip_certificate(fixtures.ENCRYPTION_CERTIFICATE) ], ) == parsing_result.provider)
def test_parse_correctly_parses_one_idp_metadata(self): # Arrange metadata_parser = SAMLMetadataParser() # Act parsing_results = metadata_parser.parse( fixtures.CORRECT_XML_WITH_IDP_1) # Assert assert 1 == len(parsing_results) [parsing_result] = parsing_results assert True == isinstance(parsing_result, SAMLMetadataParsingResult) assert True == isinstance(parsing_result.provider, SAMLIdentityProviderMetadata) assert True == isinstance(parsing_result.xml_node, onelogin.saml2.xmlparser.RestrictedElement) assert (SAMLIdentityProviderMetadata( entity_id=fixtures.IDP_1_ENTITY_ID, ui_info=SAMLUIInfo( [ SAMLLocalizedMetadataItem( fixtures.IDP_1_UI_INFO_EN_DISPLAY_NAME, "en"), SAMLLocalizedMetadataItem( fixtures.IDP_1_UI_INFO_ES_DISPLAY_NAME, "es"), ], [ SAMLLocalizedMetadataItem( fixtures.IDP_1_UI_INFO_DESCRIPTION, "en") ], [ SAMLLocalizedMetadataItem( fixtures.IDP_1_UI_INFO_INFORMATION_URL, "en") ], [ SAMLLocalizedMetadataItem( fixtures.IDP_1_UI_INFO_PRIVACY_STATEMENT_URL, "en") ], [ SAMLLocalizedMetadataItem(fixtures.IDP_1_UI_INFO_LOGO_URL, "en") ], ), organization=SAMLOrganization( [ SAMLLocalizedMetadataItem( fixtures.IDP_1_ORGANIZATION_EN_ORGANIZATION_NAME, "en"), SAMLLocalizedMetadataItem( fixtures.IDP_1_ORGANIZATION_ES_ORGANIZATION_NAME, "es"), ], [ SAMLLocalizedMetadataItem( fixtures. IDP_1_ORGANIZATION_EN_ORGANIZATION_DISPLAY_NAME, "en", ), SAMLLocalizedMetadataItem( fixtures. IDP_1_ORGANIZATION_ES_ORGANIZATION_DISPLAY_NAME, "es", ), ], [ SAMLLocalizedMetadataItem( fixtures.IDP_1_ORGANIZATION_EN_ORGANIZATION_URL, "en"), SAMLLocalizedMetadataItem( fixtures.IDP_1_ORGANIZATION_ES_ORGANIZATION_URL, "es"), ], ), name_id_format=fixtures.NAME_ID_FORMAT_1, sso_service=SAMLService(fixtures.IDP_1_SSO_URL, fixtures.IDP_1_SSO_BINDING), want_authn_requests_signed=False, signing_certificates=[ fixtures.strip_certificate(fixtures.SIGNING_CERTIFICATE) ], encryption_certificates=[ fixtures.strip_certificate(fixtures.ENCRYPTION_CERTIFICATE) ], ) == parsing_result.provider)
SERVICE_PROVIDER_WITH_CERTIFICATE = SAMLServiceProviderMetadata( fixtures.SP_ENTITY_ID, SAMLUIInfo(), SAMLOrganization(), SAMLNameIDFormat.UNSPECIFIED.value, SAMLService(fixtures.SP_ACS_URL, fixtures.SP_ACS_BINDING), certificate=fixtures.SIGNING_CERTIFICATE, private_key=fixtures.PRIVATE_KEY, ) IDENTITY_PROVIDERS = [ SAMLIdentityProviderMetadata( fixtures.IDP_1_ENTITY_ID, SAMLUIInfo(), SAMLOrganization(), SAMLNameIDFormat.UNSPECIFIED.value, SAMLService(fixtures.IDP_1_SSO_URL, fixtures.IDP_1_SSO_BINDING), ), SAMLIdentityProviderMetadata( fixtures.IDP_2_ENTITY_ID, SAMLUIInfo(), SAMLOrganization(), SAMLNameIDFormat.UNSPECIFIED.value, SAMLService(fixtures.IDP_2_SSO_URL, fixtures.IDP_2_SSO_BINDING), ), ] class TestSAMLConfiguration(DatabaseTest): def setup_method(self):
from tests.api.saml import fixtures from tests.api.saml.controller_test import ControllerTest SERVICE_PROVIDER = SAMLServiceProviderMetadata( fixtures.SP_ENTITY_ID, SAMLUIInfo(), SAMLOrganization(), SAMLNameIDFormat.UNSPECIFIED.value, SAMLService(fixtures.SP_ACS_URL, fixtures.SP_ACS_BINDING), ) IDENTITY_PROVIDERS = [ SAMLIdentityProviderMetadata( fixtures.IDP_1_ENTITY_ID, SAMLUIInfo(), SAMLOrganization(), SAMLNameIDFormat.UNSPECIFIED.value, SAMLService(fixtures.IDP_1_SSO_URL, fixtures.IDP_1_SSO_BINDING), signing_certificates=[fixtures.SIGNING_CERTIFICATE], ), SAMLIdentityProviderMetadata( fixtures.IDP_2_ENTITY_ID, SAMLUIInfo(), SAMLOrganization(), SAMLNameIDFormat.UNSPECIFIED.value, SAMLService(fixtures.IDP_2_SSO_URL, fixtures.IDP_2_SSO_BINDING), ), ] def create_patron_data_mock(): patron_data_mock = create_autospec(spec=PatronData)
IDENTITY_PROVIDER_WITH_DISPLAY_NAME = SAMLIdentityProviderMetadata( fixtures.IDP_2_ENTITY_ID, SAMLUIInfo( display_names=[ SAMLLocalizedMetadataItem(fixtures.IDP_1_UI_INFO_EN_DISPLAY_NAME, "en"), SAMLLocalizedMetadataItem(fixtures.IDP_1_UI_INFO_ES_DISPLAY_NAME, "es"), ], descriptions=[ SAMLLocalizedMetadataItem(fixtures.IDP_1_UI_INFO_DESCRIPTION, "en"), SAMLLocalizedMetadataItem(fixtures.IDP_1_UI_INFO_DESCRIPTION, "es"), ], information_urls=[ SAMLLocalizedMetadataItem(fixtures.IDP_1_UI_INFO_INFORMATION_URL, "en"), SAMLLocalizedMetadataItem(fixtures.IDP_1_UI_INFO_INFORMATION_URL, "es"), ], privacy_statement_urls=[ SAMLLocalizedMetadataItem( fixtures.IDP_1_UI_INFO_PRIVACY_STATEMENT_URL, "en"), SAMLLocalizedMetadataItem( fixtures.IDP_1_UI_INFO_PRIVACY_STATEMENT_URL, "es"), ], logo_urls=[ SAMLLocalizedMetadataItem(fixtures.IDP_1_UI_INFO_LOGO_URL, "en"), SAMLLocalizedMetadataItem(fixtures.IDP_1_UI_INFO_LOGO_URL, "es"), ], ), SAMLOrganization(), SAMLNameIDFormat.UNSPECIFIED.value, SAMLService(fixtures.IDP_2_SSO_URL, fixtures.IDP_2_SSO_BINDING), )