Skip to content

Commit

Permalink
Add test for extra fields not allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
ZohebShaikh committed Jan 22, 2025
1 parent a2ca1cc commit 211fb69
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions tests/unit_tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ def test_auth_from_env_throws_when_not_available():
# Eagerly throws an exception, will fail during initial loading
with pytest.raises(KeyError):
BasicAuthentication(username="${BAZ}", password="baz") # type: ignore
with pytest.raises(KeyError):
BasicAuthentication(username="${baz}", passcode="baz") # type: ignore


def is_subset(subset: Mapping[str, Any], superset: Mapping[str, Any]) -> bool:
Expand Down Expand Up @@ -364,3 +362,17 @@ def test_oauth_config_model_post_init(
assert oidc_config.issuer == oidc_well_known["issuer"]
assert oidc_config.jwks_uri == oidc_well_known["jwks_uri"]
assert oidc_config.end_session_endpoint == oidc_well_known["end_session_endpoint"]


def test_extra_fields_are_forbidden_for_application_config(tmp_path: Path):
for model_field in ApplicationConfig.model_fields.keys():
# Skip auth_token_path as it cannot have extra fields
if model_field == "auth_token_path":
continue
with tmp_path.joinpath("config.yaml").open("w") as file:
yaml.dump({model_field: {"foo": "foo"}}, file)

loader = ConfigLoader(ApplicationConfig)
loader.use_values_from_yaml(tmp_path.joinpath("config.yaml"))
with pytest.raises(InvalidConfigError, match="extra_forbidden"):
loader.load()

0 comments on commit 211fb69

Please sign in to comment.