Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue with setup configuration tests #1168

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import tempfile
import urllib.error
from unittest import skip
from unittest.mock import patch
from uuid import UUID

from django.conf import settings
Expand Down Expand Up @@ -749,12 +748,12 @@ def test_is_configured(self):
DIGID_SLO=False,
)
class DigiDConfigurationTests(ClearCachesMixin, TestCase):
def test_configure(self):
with open(DIGID_XML_METADATA_PATH) as f:
with patch(
"onelogin.saml2.idp_metadata_parser.urllib2.urlopen", return_value=f
):
DigiDConfigurationStep().configure()
@requests_mock.Mocker()
def test_configure(self, m):
with open(DIGID_XML_METADATA_PATH, "rb") as f:
m.get("http://metadata.local/file.xml", content=f.read())

DigiDConfigurationStep().configure()

config = DigidConfiguration.get_solo()

Expand Down Expand Up @@ -796,6 +795,7 @@ def test_configure(self):
)
self.assertEqual(config.slo, False)

@requests_mock.Mocker()
@override_settings(
DIGID_WANT_ASSERTIONS_SIGNED=None,
DIGID_WANT_ASSERTIONS_ENCRYPTED=None,
Expand All @@ -807,12 +807,11 @@ def test_configure(self):
DIGID_REQUESTED_ATTRIBUTES=None,
DIGID_SLO=None,
)
def test_configure_use_defaults(self):
with open(DIGID_XML_METADATA_PATH) as f:
with patch(
"onelogin.saml2.idp_metadata_parser.urllib2.urlopen", return_value=f
):
DigiDConfigurationStep().configure()
def test_configure_use_defaults(self, m):
with open(DIGID_XML_METADATA_PATH, "rb") as f:
m.get("http://metadata.local/file.xml", content=f.read())

DigiDConfigurationStep().configure()

config = DigidConfiguration.get_solo()

Expand All @@ -829,16 +828,14 @@ def test_configure_use_defaults(self):
)
self.assertEqual(config.slo, True)

def test_configure_failure(self):
@requests_mock.Mocker()
def test_configure_failure(self, m):
exceptions = (urllib.error.HTTPError, urllib.error.URLError)
for exception in exceptions:
with self.subTest(exception=exception):
with patch(
"onelogin.saml2.idp_metadata_parser.urllib2.urlopen",
side_effect=exception,
):
with self.assertRaises(ConfigurationRunFailed):
DigiDConfigurationStep().configure()
m.get("http://metadata.local/file.xml", exc=exception)
with self.assertRaises(ConfigurationRunFailed):
DigiDConfigurationStep().configure()

config = DigidConfiguration.get_solo()

Expand All @@ -854,16 +851,15 @@ def test_configuration_check_ok(self, m):
def test_configuration_check_failures(self, m):
raise NotImplementedError

def test_is_configured(self):
@requests_mock.Mocker()
def test_is_configured(self, m):
config = DigiDConfigurationStep()

self.assertFalse(config.is_configured())

with open(DIGID_XML_METADATA_PATH) as f:
with patch(
"onelogin.saml2.idp_metadata_parser.urllib2.urlopen", return_value=f
):
config.configure()
with open(DIGID_XML_METADATA_PATH, "rb") as f:
m.get("http://metadata.local/file.xml", content=f.read())
config.configure()

self.assertTrue(config.is_configured())

Expand Down Expand Up @@ -906,12 +902,12 @@ def test_is_configured(self):
EHERKENNING_SERVICE_LANGUAGE="en",
)
class eHerkenningConfigurationTests(ClearCachesMixin, TestCase):
def test_configure(self):
with open(DIGID_XML_METADATA_PATH) as f:
with patch(
"onelogin.saml2.idp_metadata_parser.urllib2.urlopen", return_value=f
):
eHerkenningConfigurationStep().configure()
@requests_mock.Mocker()
def test_configure(self, m):
with open(DIGID_XML_METADATA_PATH, "rb") as f:
m.get("http://metadata.local/file.xml", content=f.read())

eHerkenningConfigurationStep().configure()

config = EherkenningConfiguration.get_solo()

Expand Down Expand Up @@ -976,6 +972,7 @@ def test_configure(self):
self.assertEqual(config.makelaar_id, "44444333332222211111")
self.assertEqual(config.service_language, "en")

@requests_mock.Mocker()
@override_settings(
EHERKENNING_WANT_ASSERTIONS_SIGNED=None,
EHERKENNING_WANT_ASSERTIONS_ENCRYPTED=None,
Expand All @@ -994,12 +991,11 @@ def test_configure(self):
EHERKENNING_NO_EIDAS=None,
EHERKENNING_SERVICE_LANGUAGE=None,
)
def test_configure_use_defaults(self):
with open(DIGID_XML_METADATA_PATH) as f:
with patch(
"onelogin.saml2.idp_metadata_parser.urllib2.urlopen", return_value=f
):
eHerkenningConfigurationStep().configure()
def test_configure_use_defaults(self, m):
with open(DIGID_XML_METADATA_PATH, "rb") as f:
m.get("http://metadata.local/file.xml", content=f.read())

eHerkenningConfigurationStep().configure()

config = EherkenningConfiguration.get_solo()

Expand All @@ -1020,16 +1016,14 @@ def test_configure_use_defaults(self):
self.assertEqual(config.no_eidas, False)
self.assertEqual(config.service_language, "nl")

def test_configure_failure(self):
@requests_mock.Mocker()
def test_configure_failure(self, m):
exceptions = (urllib.error.HTTPError, urllib.error.URLError)
for exception in exceptions:
with self.subTest(exception=exception):
with patch(
"onelogin.saml2.idp_metadata_parser.urllib2.urlopen",
side_effect=exception,
):
with self.assertRaises(ConfigurationRunFailed):
eHerkenningConfigurationStep().configure()
m.get("http://metadata.local/file.xml", exc=exception)
with self.assertRaises(ConfigurationRunFailed):
eHerkenningConfigurationStep().configure()

config = EherkenningConfiguration.get_solo()

Expand All @@ -1045,15 +1039,15 @@ def test_configuration_check_ok(self, m):
def test_configuration_check_failures(self, m):
raise NotImplementedError

def test_is_configured(self):
@requests_mock.Mocker()
def test_is_configured(self, m):
config = eHerkenningConfigurationStep()

self.assertFalse(config.is_configured())

with open(DIGID_XML_METADATA_PATH) as f:
with patch(
"onelogin.saml2.idp_metadata_parser.urllib2.urlopen", return_value=f
):
config.configure()
with open(DIGID_XML_METADATA_PATH, "rb") as f:
m.get("http://metadata.local/file.xml", content=f.read())

config.configure()

self.assertTrue(config.is_configured())
Loading