Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmursa-dev committed Dec 10, 2024
1 parent 7ef632b commit 395218b
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
oidc_db_config_enable: true
oidc_db_config_admin_auth:
items:
- identifier: admin-oidc
oidc_rp_client_id: client-id
oidc_rp_client_secret:
endpoint_config:
oidc_op_authorization_endpoint: https://example.com/realms/test/protocol/openid-connect/auth
oidc_op_token_endpoint: https://example.com/realms/test/protocol/openid-connect/token
oidc_op_user_endpoint: https://example.com/realms/test/protocol/openid-connect/userinfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
oidc_db_config_enable: true
oidc_db_config_admin_auth:
items:
- identifier: admin-oidc
oidc_rp_client_id: client-id
oidc_rp_client_secret: secret
endpoint_config:
oidc_op_authorization_endpoint: https://example.com/realms/test/protocol/openid-connect/auth
oidc_op_token_endpoint: https://example.com/realms/test/protocol/openid-connect/token
oidc_op_user_endpoint: https://example.com/realms/test/protocol/openid-connect/userinfo
73 changes: 73 additions & 0 deletions src/objecttypes/setup_configuration/tests/test_oidc_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
from pathlib import Path

from django.test import TestCase

from django_setup_configuration.exceptions import ConfigurationException
from django_setup_configuration.test_utils import build_step_config_from_sources
from mozilla_django_oidc_db.models import OpenIDConnectConfig
from mozilla_django_oidc_db.setup_configuration.steps import AdminOIDCConfigurationStep

DIR_FILES = (Path(__file__).parent / "files/oidc").resolve()


class AdminOIDCConfigurationTests(TestCase):

def setUp(self):
OpenIDConnectConfig.clear_cache()

def test_valid_setup_default(self):
config = OpenIDConnectConfig.get_solo()
self.assertFalse(config.enabled)

setup_config = build_step_config_from_sources(
AdminOIDCConfigurationStep,
str(DIR_FILES / "valid_setup.yaml"),
)
step = AdminOIDCConfigurationStep()
step.execute(setup_config)

config = OpenIDConnectConfig.get_solo()

self.assertTrue(config.enabled)
self.assertEqual(config.oidc_rp_client_id, "client-id")
self.assertEqual(config.oidc_rp_client_secret, "secret")
self.assertEqual(
config.oidc_op_authorization_endpoint,
"https://example.com/realms/test/protocol/openid-connect/auth",
)
self.assertEqual(
config.oidc_op_token_endpoint,
"https://example.com/realms/test/protocol/openid-connect/token",
)
self.assertEqual(
config.oidc_op_user_endpoint,
"https://example.com/realms/test/protocol/openid-connect/userinfo",
)

def test_invalid_setup_default(self):

config = OpenIDConnectConfig.get_solo()
self.assertFalse(config.enabled)

with self.assertRaises(ConfigurationException) as command_error:
setup_config = build_step_config_from_sources(
AdminOIDCConfigurationStep,
str(DIR_FILES / "invalid_setup.yaml"),
)
step = AdminOIDCConfigurationStep()
step.execute(setup_config)

self.assertTrue(
"Input should be a valid string" in str(command_error.exception)
)

config = OpenIDConnectConfig.get_solo()

self.assertFalse(config.enabled)
self.assertEqual(config.oidc_rp_client_id, "")
self.assertEqual(config.oidc_rp_client_secret, "")
self.assertEqual(config.oidc_op_authorization_endpoint, "")
self.assertEqual(config.oidc_op_token_endpoint, "")
self.assertEqual(config.oidc_op_user_endpoint, "")

self.assertFalse(OpenIDConnectConfig.get_solo().enabled)

0 comments on commit 395218b

Please sign in to comment.