-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bf1061c
commit 270fad9
Showing
3 changed files
with
209 additions
and
184 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
src/openforms/authentication/contrib/digid_eherkenning_oidc/tests/base.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from contextlib import contextmanager | ||
from functools import partial | ||
from pathlib import Path | ||
from unittest.mock import patch | ||
|
||
from django.apps import apps | ||
from django.test import override_settings | ||
|
||
from django_webtest import WebTest | ||
|
||
from openforms.utils.tests.vcr import OFVCRMixin | ||
|
||
TEST_FILES = (Path(__file__).parent / "data").resolve() | ||
|
||
KEYCLOAK_BASE_URL = "http://localhost:8080/realms/test/protocol/openid-connect" | ||
|
||
|
||
@contextmanager | ||
def mock_config(model: str, **overrides): | ||
""" | ||
Bundle all the required mocks. | ||
This context manager deliberately prevents the mocked things from being injected in | ||
the test method signature. | ||
""" | ||
defaults = { | ||
"enabled": True, | ||
"oidc_rp_client_id": "testid", | ||
"oidc_rp_client_secret": "7DB3KUAAizYCcmZufpHRVOcD0TOkNO3I", | ||
"oidc_rp_sign_algo": "RS256", | ||
"oidc_rp_scopes_list": ["openid"], | ||
"oidc_op_jwks_endpoint": f"{KEYCLOAK_BASE_URL}/certs", | ||
"oidc_op_authorization_endpoint": f"{KEYCLOAK_BASE_URL}/auth", | ||
"oidc_op_token_endpoint": f"{KEYCLOAK_BASE_URL}/token", | ||
"oidc_op_user_endpoint": f"{KEYCLOAK_BASE_URL}/userinfo", | ||
} | ||
field_values = {**defaults, **overrides} | ||
model_cls = apps.get_model("digid_eherkenning_oidc_generics", model) | ||
with ( | ||
# bypass django-solo queries + cache hits | ||
patch( | ||
f"digid_eherkenning_oidc_generics.models.{model}.get_solo", | ||
return_value=model_cls(**field_values), | ||
), | ||
# mock the state & nonce random value generation so we get predictable URLs to | ||
# match with VCR | ||
patch( | ||
"mozilla_django_oidc.views.get_random_string", | ||
return_value="not-a-random-string", | ||
), | ||
): | ||
yield | ||
|
||
|
||
mock_digid_config = partial( | ||
mock_config, | ||
model="OpenIDConnectPublicConfig", | ||
oidc_rp_scopes_list=["openid", "bsn"], | ||
) | ||
mock_eherkenning_config = partial( | ||
mock_config, | ||
model="OpenIDConnectEHerkenningConfig", | ||
oidc_rp_scopes_list=["openid", "kvk"], | ||
) | ||
|
||
|
||
@override_settings(CORS_ALLOW_ALL_ORIGINS=True, IS_HTTPS=True) | ||
class IntegrationTestsBase(OFVCRMixin, WebTest): | ||
VCR_TEST_FILES = TEST_FILES |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.