Merge "clearer error when authenticate called without auth_url"

This commit is contained in:
Jenkins
2013-08-26 19:39:51 +00:00
committed by Gerrit Code Review
4 changed files with 18 additions and 0 deletions

View File

@@ -173,6 +173,8 @@ class Client(httpclient.HTTPClient):
to a tenant. to a tenant.
""" """
headers = {} headers = {}
if auth_url is None:
raise ValueError("Cannot authenticate without a valid auth_url")
url = auth_url + "/tokens" url = auth_url + "/tokens"
if token: if token:
headers['X-Auth-Token'] = token headers['X-Auth-Token'] = token

View File

@@ -170,6 +170,8 @@ class Client(httpclient.HTTPClient):
project_id=None, project_name=None, project_domain_id=None, project_id=None, project_name=None, project_domain_id=None,
project_domain_name=None, token=None, trust_id=None): project_domain_name=None, token=None, trust_id=None):
headers = {} headers = {}
if auth_url is None:
raise ValueError("Cannot authenticate without a valid auth_url")
url = auth_url + "/auth/tokens" url = auth_url + "/auth/tokens"
body = {'auth': {'identity': {}}} body = {'auth': {'identity': {}}}
ident = body['auth']['identity'] ident = body['auth']['identity']

View File

@@ -3,6 +3,7 @@ import mock
import requests import requests
from keystoneclient import exceptions
from keystoneclient.v2_0 import client from keystoneclient.v2_0 import client
from tests import utils from tests import utils
from tests.v2_0 import client_fixtures from tests.v2_0 import client_fixtures
@@ -90,3 +91,9 @@ class KeystoneClientTest(utils.TestCase):
self.assertIsNone(new_client.password) self.assertIsNone(new_client.password)
self.assertEqual(new_client.management_url, self.assertEqual(new_client.management_url,
'http://admin:35357/v2.0') 'http://admin:35357/v2.0')
def test_init_err_no_auth_url(self):
self.assertRaises(exceptions.AuthorizationFailure,
client.Client,
username='exampleuser',
password='password')

View File

@@ -3,6 +3,7 @@ import mock
import requests import requests
from keystoneclient import exceptions
from keystoneclient.v3 import client from keystoneclient.v3 import client
from tests import utils from tests import utils
@@ -140,3 +141,9 @@ class KeystoneClientTest(utils.TestCase):
self.assertEqual(c.auth_ref.trust_id, 'fe0aef') self.assertEqual(c.auth_ref.trust_id, 'fe0aef')
self.assertTrue(c.auth_ref.trust_scoped) self.assertTrue(c.auth_ref.trust_scoped)
self.assertEquals(c.auth_user_id, '0ca8f6') 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')