Skip to content

Commit

Permalink
💚 Fix existing tests
Browse files Browse the repository at this point in the history
The amount of get_metadata calls is changed because we directly check the
metadata file now instead of fetching a potentially unconfigured
source.

Additionally, .env overrides for the CSP_FORM_ACTION setting can cause
weird local test failures, so we pin that setting the tests that make
assertions against the response header.
  • Loading branch information
sergei-maertens committed Nov 9, 2023
1 parent 671d284 commit bbb1a09
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
10 changes: 9 additions & 1 deletion src/openforms/config/tests/test_csp_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ def test_middleware_applies_cspsetting_models(self):


class CreateCSPFormActionFromConfigTests(TestCase):
@classmethod
def setUpTestData(cls):
super().setUpTestData()

# looks like there may be left over (migration) data from non-transaction testcases
DigidConfiguration.objects.all().delete()
EherkenningConfiguration.objects.all().delete()

def setUp(self):
super().setUp()

Expand All @@ -62,7 +70,7 @@ def test_no_ogone_nor_digid_eherkenning_config(self):

self.assertFalse(CSPSetting.objects.exists())

def test_config_records_exists_but_are_incomplete(self):
def test_config_records_exist_but_are_incomplete(self):
OgoneMerchant.objects.create(
endpoint_preset="", # not realistic, but the DB allows it
endpoint_custom="",
Expand Down
10 changes: 6 additions & 4 deletions src/openforms/contrib/digid_eherkenning/tests/test_csp_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_csp_updates_for_digid(self, get_metadata):

csp_updated = CSPSetting.objects.get()

self.assertEqual(get_metadata.call_count, 4)
self.assertEqual(get_metadata.call_count, 2)
self.assertFalse(CSPSetting.objects.filter(id=csp_added.id))
self.assertEqual(csp_updated.content_object, self.config)
self.assertEqual(csp_updated.directive, CSPDirective.FORM_ACTION)
Expand All @@ -95,6 +95,7 @@ def test_csp_updates_for_digid(self, get_metadata):
@patch(
"onelogin.saml2.idp_metadata_parser.OneLogin_Saml2_IdPMetadataParser.get_metadata"
)
@override_settings(CSP_FORM_ACTION=["'self'"])
def test_response_headers_contain_form_action_values_in_digid(self, get_metadata):
form = FormFactory.create(authentication_backends=["digid"])
form_definition = FormDefinitionFactory.create(login_required=True)
Expand All @@ -114,7 +115,7 @@ def test_response_headers_contain_form_action_values_in_digid(self, get_metadata
# redirect_to_digid_login
response = self.client.get(login_url, {"next": form_url}, follow=True)

self.assertEqual(get_metadata.call_count, 2)
self.assertEqual(get_metadata.call_count, 1)
self.assertIn(
"form-action "
"'self' "
Expand Down Expand Up @@ -188,7 +189,7 @@ def test_csp_updates_for_eherkenning(self, get_metadata):

csp_updated = CSPSetting.objects.get()

self.assertEqual(get_metadata.call_count, 4)
self.assertEqual(get_metadata.call_count, 2)
self.assertFalse(CSPSetting.objects.filter(id=csp_added.id))
self.assertEqual(csp_added.directive, CSPDirective.FORM_ACTION)
self.assertEqual(
Expand All @@ -200,6 +201,7 @@ def test_csp_updates_for_eherkenning(self, get_metadata):
@patch(
"onelogin.saml2.idp_metadata_parser.OneLogin_Saml2_IdPMetadataParser.get_metadata"
)
@override_settings(CSP_FORM_ACTION=["'self'"])
def test_response_headers_contain_form_action_values_in_eherkenning(
self, get_metadata
):
Expand All @@ -225,7 +227,7 @@ def test_response_headers_contain_form_action_values_in_eherkenning(
# redirect_to_eherkenning_login
response = self.client.get(login_url, {"next": form_url}, follow=True)

self.assertEqual(get_metadata.call_count, 2)
self.assertEqual(get_metadata.call_count, 1)
self.assertIn(
"form-action "
"'self' "
Expand Down
4 changes: 3 additions & 1 deletion src/openforms/payments/contrib/ogone/tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@


@override_settings(
CORS_ALLOW_ALL_ORIGINS=False, CORS_ALLOWED_ORIGINS=["http://foo.bar"]
CORS_ALLOW_ALL_ORIGINS=False,
CORS_ALLOWED_ORIGINS=["http://foo.bar"],
CSP_FORM_ACTION=["'self'"],
)
class OgoneTests(TestCase):
maxDiff = None
Expand Down

0 comments on commit bbb1a09

Please sign in to comment.