From a9a66ae7a750e507a0dda4bc9b2f9f62b9cd98a2 Mon Sep 17 00:00:00 2001
From: Stef T <stelford@internap.com>
Date: Thu, 4 Oct 2012 16:20:23 -0400
Subject: [PATCH] Raises Exception on improper Auth Configuration

Addresses bug 1061848.

Basically, this bug comes about from not properly
setting up the auth_system for novaclient. In this
case, an exception of EndPointNotFound is flung.

Change-Id: I12533aefd9d0425dd83e2e4c63f4dd5ff6faae71
---
 novaclient/client.py       |  2 ++
 tests/test_auth_plugins.py | 24 ++++++++++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/novaclient/client.py b/novaclient/client.py
index 8f2e6254f..2def04aa4 100644
--- a/novaclient/client.py
+++ b/novaclient/client.py
@@ -95,6 +95,8 @@ class HTTPClient(httplib2.Http):
         self.projectid = projectid
         if not auth_url and auth_system and auth_system != 'keystone':
             auth_url = get_auth_system_url(auth_system)
+            if not auth_url:
+                raise exceptions.EndpointNotFound()
         self.auth_url = auth_url.rstrip('/')
         self.version = 'v1.1'
         self.region_name = region_name
diff --git a/tests/test_auth_plugins.py b/tests/test_auth_plugins.py
index e0a3b4f17..8b58da787 100644
--- a/tests/test_auth_plugins.py
+++ b/tests/test_auth_plugins.py
@@ -157,3 +157,27 @@ class AuthPluginTest(utils.TestCase):
             self.assertEquals(cs.client.auth_url, "http://faked/v2.0")
 
         test_auth_call()
+
+    def test_auth_system_raises_exception_when_missing_auth_url(self):
+        class MockAuthUrlEntrypoint(pkg_resources.EntryPoint):
+            def load(self):
+                return self.auth_url
+
+            def auth_url(self):
+                return None
+
+        def mock_iter_entry_points(_type):
+            return [MockAuthUrlEntrypoint("fakewithauthurl",
+                                          "fakewithauthurl.plugin",
+                                          ["auth_url"])]
+
+        @mock.patch.object(pkg_resources, "iter_entry_points",
+                           mock_iter_entry_points)
+        def test_auth_call():
+            with self.assertRaises(exceptions.EndpointNotFound):
+                cs = client.Client("username", "password", "project_id",
+                                   auth_system="fakewithauthurl",
+                                   no_cache=True)
+
+        test_auth_call()
+