From f0341e5d292b38083219442af95ac699fe50416b Mon Sep 17 00:00:00 2001 From: Douglas Hall Date: Wed, 17 Jan 2018 13:55:56 -0500 Subject: [PATCH] ENT-851 TPA Registry.get should return None if passed None. --- common/djangoapps/third_party_auth/provider.py | 2 ++ common/djangoapps/third_party_auth/tests/test_provider.py | 3 +++ 2 files changed, 5 insertions(+) diff --git a/common/djangoapps/third_party_auth/provider.py b/common/djangoapps/third_party_auth/provider.py index 93f2ff0044..cb6ce1c6c0 100644 --- a/common/djangoapps/third_party_auth/provider.py +++ b/common/djangoapps/third_party_auth/provider.py @@ -71,6 +71,8 @@ class Registry(object): @classmethod def get(cls, provider_id): """Gets provider by provider_id string if enabled, else None.""" + if not provider_id: + return None if '-' not in provider_id: # Check format - see models.py:ProviderConfig raise ValueError("Invalid provider_id. Expect something like oa2-google") try: diff --git a/common/djangoapps/third_party_auth/tests/test_provider.py b/common/djangoapps/third_party_auth/tests/test_provider.py index 8fe42a9bf6..71c489ea57 100644 --- a/common/djangoapps/third_party_auth/tests/test_provider.py +++ b/common/djangoapps/third_party_auth/tests/test_provider.py @@ -168,6 +168,9 @@ class RegistryTest(testutil.TestCase): self.configure_google_provider(enabled=True) self.assertNotIn(facebook_provider, provider.Registry.get_enabled_by_backend_name('google-oauth2')) + def test_get_returns_none_if_provider_id_is_none(self): + self.assertIsNone(provider.Registry.get(None)) + def test_get_returns_none_if_provider_not_enabled(self): linkedin_provider_id = "oa2-linkedin-oauth2" # At this point there should be no configuration entries at all so no providers should be enabled