Skip to content

Commit

Permalink
Fix SAML tests
Browse files Browse the repository at this point in the history
  • Loading branch information
keithbauer committed Jul 22, 2024
1 parent 4007bd1 commit b41d937
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
9 changes: 7 additions & 2 deletions tests/saml/metadata/federations/test_loader.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
import requests_mock
from mock import MagicMock, create_autospec, patch

from api.saml.metadata.federations import incommon
Expand Down Expand Up @@ -28,13 +29,15 @@ def test_load_idp_metadata_raises_error_when_xml_is_incorrect(self, urlopen_mock
metadata_loader.load_idp_metadata(url)

@patch("urllib.request.urlopen")
def test_load_idp_metadata_correctly_loads_one_descriptor(self, urlopen_mock):
@patch("urllib.request.Request")
def test_load_idp_metadata_correctly_loads_one_descriptor(self, request_mock, urlopen_mock):
# Arrange
url = "http://md.incommon.org/InCommon/metadata.xml"
incorrect_xml = fixtures.CORRECT_XML_WITH_IDP_1
urlopen_response_mock = MagicMock()
urlopen_response_mock.read = MagicMock(return_value=incorrect_xml)
urlopen_mock.return_value = urlopen_response_mock
request_mock.return_value = url
metadata_loader = SAMLMetadataLoader()

# Act
Expand All @@ -45,13 +48,15 @@ def test_load_idp_metadata_correctly_loads_one_descriptor(self, urlopen_mock):
assert fixtures.CORRECT_XML_WITH_IDP_1 == xml_metadata

@patch("urllib.request.urlopen")
def test_load_idp_metadata_correctly_loads_multiple_descriptors(self, urlopen_mock):
@patch("urllib.request.Request")
def test_load_idp_metadata_correctly_loads_multiple_descriptors(self, request_mock, urlopen_mock):
# Arrange
url = "http://md.incommon.org/InCommon/metadata.xml"
incorrect_xml = fixtures.CORRECT_XML_WITH_MULTIPLE_IDPS
urlopen_response_mock = MagicMock()
urlopen_response_mock.read = MagicMock(return_value=incorrect_xml)
urlopen_mock.return_value = urlopen_response_mock
request_mock.return_value = url
metadata_loader = SAMLMetadataLoader()

# Act
Expand Down
8 changes: 4 additions & 4 deletions tests/saml/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def setup_method(self, _db=None, set_up_circulation_manager=True):
"links": [
{
"rel": "authenticate",
"href": "http://localhost/default/saml_authenticate?provider=SAML+2.0+Web+SSO&idp_entity_id=http%3A%2F%2Fidp2.hilbertteam.net%2Fidp%2Fshibboleth",
"href": "http://localhost/default/saml_authenticate?provider=SAML+2.0+Web+SSO&idp_entity_id=http://idp2.hilbertteam.net/idp/shibboleth",
"display_names": [
{
"value": fixtures.IDP_1_UI_INFO_EN_DISPLAY_NAME,
Expand Down Expand Up @@ -201,7 +201,7 @@ def setup_method(self, _db=None, set_up_circulation_manager=True):
"links": [
{
"rel": "authenticate",
"href": "http://localhost/default/saml_authenticate?provider=SAML+2.0+Web+SSO&idp_entity_id=http%3A%2F%2Fidp2.hilbertteam.net%2Fidp%2Fshibboleth",
"href": "http://localhost/default/saml_authenticate?provider=SAML+2.0+Web+SSO&idp_entity_id=http://idp2.hilbertteam.net/idp/shibboleth",
"display_names": [
{
"value": fixtures.IDP_1_ORGANIZATION_EN_ORGANIZATION_DISPLAY_NAME,
Expand Down Expand Up @@ -232,7 +232,7 @@ def setup_method(self, _db=None, set_up_circulation_manager=True):
"links": [
{
"rel": "authenticate",
"href": "http://localhost/default/saml_authenticate?provider=SAML+2.0+Web+SSO&idp_entity_id=http%3A%2F%2Fidp1.hilbertteam.net%2Fidp%2Fshibboleth",
"href": "http://localhost/default/saml_authenticate?provider=SAML+2.0+Web+SSO&idp_entity_id=http://idp1.hilbertteam.net/idp/shibboleth",
"display_names": [
{
"value": SAMLConfiguration.IDP_DISPLAY_NAME_DEFAULT_TEMPLATE.format(
Expand All @@ -248,7 +248,7 @@ def setup_method(self, _db=None, set_up_circulation_manager=True):
},
{
"rel": "authenticate",
"href": "http://localhost/default/saml_authenticate?provider=SAML+2.0+Web+SSO&idp_entity_id=http%3A%2F%2Fidp1.hilbertteam.net%2Fidp%2Fshibboleth",
"href": "http://localhost/default/saml_authenticate?provider=SAML+2.0+Web+SSO&idp_entity_id=http://idp1.hilbertteam.net/idp/shibboleth",
"display_names": [
{
"value": SAMLConfiguration.IDP_DISPLAY_NAME_DEFAULT_TEMPLATE.format(
Expand Down

0 comments on commit b41d937

Please sign in to comment.