Skip to content

Commit

Permalink
♻️[#114] implement suggested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Coperh committed Dec 2, 2024
1 parent d8ac68e commit 2321306
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
16 changes: 7 additions & 9 deletions mozilla_django_oidc_db/setup_configuration/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,21 @@ def get_endpoint_endpoint_model(endpoint_data):
class AdminOIDCConfigurationModel(ConfigurationModel):

# Change default to True
enabled: bool | None = DjangoModelRef(OpenIDConnectConfig, "enabled", default=True)
enabled: bool = DjangoModelRef(OpenIDConnectConfig, "enabled", default=True)

# Json
claim_mapping: dict | None = DjangoModelRef(OpenIDConnectConfig, "claim_mapping")
claim_mapping: dict = DjangoModelRef(OpenIDConnectConfig, "claim_mapping")

# Arrays are overridden to make the typing simpler (the underlying Django field is an ArrayField, which is non-standard)
username_claim: list[str] | None = DjangoModelRef(
OpenIDConnectConfig, "username_claim"
)
groups_claim: list[str] | None = DjangoModelRef(OpenIDConnectConfig, "groups_claim")
superuser_group_names: list[str] | None = DjangoModelRef(
username_claim: list[str] = DjangoModelRef(OpenIDConnectConfig, "username_claim")
groups_claim: list[str] = DjangoModelRef(OpenIDConnectConfig, "groups_claim")
superuser_group_names: list[str] = DjangoModelRef(
OpenIDConnectConfig, "superuser_group_names"
)
default_groups: list[str] | None = DjangoModelRef(
default_groups: list[str] = DjangoModelRef(
OpenIDConnectConfig, "superuser_group_names"
)
oidc_rp_scopes_list: list[str] | None = DjangoModelRef(
oidc_rp_scopes_list: list[str] = DjangoModelRef(
OpenIDConnectConfig, "oidc_rp_scopes_list"
)

Expand Down
39 changes: 25 additions & 14 deletions tests/setupconfig/test_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,25 +148,36 @@ def test_configure_use_discovery_endpoint(discovery_endpoint_config_yml):


@pytest.mark.django_db
def test_configure_discovery_failure(requests_mock, discovery_endpoint_config_yml):
mock_kwargs = (
@pytest.mark.parametrize(
"mock_kwargs",
(
{"exc": requests.ConnectTimeout},
{"exc": requests.ConnectionError},
{"status_code": 404},
{"status_code": 403},
{"status_code": 500},
),
ids=[
"Connection Timeout",
"Connection Error",
"Status 404",
"Status 403",
"Status 500",
],
)
def test_configure_discovery_failure(
requests_mock, discovery_endpoint_config_yml, mock_kwargs
):
requests_mock.get(
f"{KEYCLOAK_BASE_URL}.well-known/openid-configuration",
**mock_kwargs,
)
for mock_config in mock_kwargs:
requests_mock.get(
f"{KEYCLOAK_BASE_URL}.well-known/openid-configuration",
**mock_config,
)

with pytest.raises(ConfigurationRunFailed):
execute_single_step(
AdminOIDCConfigurationStep, yaml_source=discovery_endpoint_config_yml
)
with pytest.raises(ConfigurationRunFailed):
execute_single_step(
AdminOIDCConfigurationStep, yaml_source=discovery_endpoint_config_yml
)

config = OpenIDConnectConfig.get_solo()
assert not config.enabled
assert config.oidc_op_discovery_endpoint == ""
config = OpenIDConnectConfig.get_solo()
assert not config.enabled
assert config.oidc_op_discovery_endpoint == ""

0 comments on commit 2321306

Please sign in to comment.