diff --git a/exchangelib/autodiscover/protocol.py b/exchangelib/autodiscover/protocol.py index 473d793c..9d2ec777 100644 --- a/exchangelib/autodiscover/protocol.py +++ b/exchangelib/autodiscover/protocol.py @@ -1,3 +1,4 @@ +from ..properties import UserResponse from ..protocol import BaseProtocol from ..services import GetUserSettings from ..transport import get_autodiscover_authtype @@ -45,6 +46,11 @@ def get_user_settings(self, user, settings=None): "external_ews_url", "ews_supported_schemas", ] + for setting in settings: + if setting not in UserResponse.SETTINGS_MAP: + raise ValueError( + f"Setting {setting!r} is invalid. Valid options are: {sorted(UserResponse.SETTINGS_MAP.keys())}" + ) return GetUserSettings(protocol=self).get(users=[user], settings=settings) def dummy_xml(self): diff --git a/tests/test_autodiscover.py b/tests/test_autodiscover.py index b7f47c1f..670fb5a4 100644 --- a/tests/test_autodiscover.py +++ b/tests/test_autodiscover.py @@ -256,6 +256,14 @@ def test_get_user_settings(self, m): ad.discover() p = autodiscover_cache[ad._cache_key] + # Test invalid settings + with self.assertRaises(ValueError) as e: + p.get_user_settings(user=None, settings=["XXX"]) + self.assertIn( + "Setting 'XXX' is invalid. Valid options are:", + e.exception.args[0], + ) + # Test invalid email invalid_email = get_random_email() r = p.get_user_settings(user=invalid_email)