-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[maykinmedia/objects-api#480] Create tests
- Loading branch information
1 parent
7ef632b
commit 395218b
Showing
3 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
src/objecttypes/setup_configuration/tests/files/oidc/invalid_setup.yaml
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,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 |
10 changes: 10 additions & 0 deletions
10
src/objecttypes/setup_configuration/tests/files/oidc/valid_setup.yaml
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,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
73
src/objecttypes/setup_configuration/tests/test_oidc_config.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,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) |