diff --git a/keystoneclient/v2_0/client.py b/keystoneclient/v2_0/client.py index b97aa6340..22c6199a5 100644 --- a/keystoneclient/v2_0/client.py +++ b/keystoneclient/v2_0/client.py @@ -173,6 +173,8 @@ class Client(httpclient.HTTPClient): to a tenant. """ headers = {} + if auth_url is None: + raise ValueError("Cannot authenticate without a valid auth_url") url = auth_url + "/tokens" if token: headers['X-Auth-Token'] = token diff --git a/keystoneclient/v3/client.py b/keystoneclient/v3/client.py index 1f4eebf42..3c60abad1 100644 --- a/keystoneclient/v3/client.py +++ b/keystoneclient/v3/client.py @@ -170,6 +170,8 @@ class Client(httpclient.HTTPClient): project_id=None, project_name=None, project_domain_id=None, project_domain_name=None, token=None, trust_id=None): headers = {} + if auth_url is None: + raise ValueError("Cannot authenticate without a valid auth_url") url = auth_url + "/auth/tokens" body = {'auth': {'identity': {}}} ident = body['auth']['identity'] diff --git a/tests/v2_0/test_client.py b/tests/v2_0/test_client.py index a7a3942f5..3a3505fe1 100644 --- a/tests/v2_0/test_client.py +++ b/tests/v2_0/test_client.py @@ -3,6 +3,7 @@ import mock import requests +from keystoneclient import exceptions from keystoneclient.v2_0 import client from tests import utils from tests.v2_0 import client_fixtures @@ -90,3 +91,9 @@ class KeystoneClientTest(utils.TestCase): self.assertIsNone(new_client.password) self.assertEqual(new_client.management_url, 'http://admin:35357/v2.0') + + def test_init_err_no_auth_url(self): + self.assertRaises(exceptions.AuthorizationFailure, + client.Client, + username='exampleuser', + password='password') diff --git a/tests/v3/test_client.py b/tests/v3/test_client.py index c798765c2..e11ce3bde 100644 --- a/tests/v3/test_client.py +++ b/tests/v3/test_client.py @@ -3,6 +3,7 @@ import mock import requests +from keystoneclient import exceptions from keystoneclient.v3 import client from tests import utils @@ -140,3 +141,9 @@ class KeystoneClientTest(utils.TestCase): self.assertEqual(c.auth_ref.trust_id, 'fe0aef') self.assertTrue(c.auth_ref.trust_scoped) self.assertEquals(c.auth_user_id, '0ca8f6') + + def test_init_err_no_auth_url(self): + self.assertRaises(exceptions.AuthorizationFailure, + client.Client, + username='exampleuser', + password='password')