Skip to content

Commit

Permalink
Check if creds are present and not None
Browse files Browse the repository at this point in the history
Currently, KeystoneStrategy checks whether the required credentials are
present in the creds dict but it doesn't check whether they are valid or
not.

This patch checks whether the required creds are present and not None
otherwise a MissingCredentials exception will be raised.

Note: No need for checking parameters' values types since they'll be
instances of basestring once set otherwise they'll be None.

Fixes bug 1157765

Change-Id: I664a604c3cbf2fca60a88c4d887cd9a4b678c8a5
(cherry picked from commit 855162b)
  • Loading branch information
flaper87 committed Mar 26, 2013
1 parent c425cd5 commit 9f336df
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions glance/common/auth.py
Expand Up @@ -85,14 +85,14 @@ def check_auth_params(self):
# Ensure that supplied credential parameters are as required
for required in ('username', 'password', 'auth_url',
'strategy'):
if required not in self.creds:
if self.creds.get(required) is None:
raise exception.MissingCredentialError(required=required)
if self.creds['strategy'] != 'keystone':
raise exception.BadAuthStrategy(expected='keystone',
received=self.creds['strategy'])
# For v2.0 also check tenant is present
if self.creds['auth_url'].rstrip('/').endswith('v2.0'):
if 'tenant' not in self.creds:
if self.creds.get("tenant") is None:
raise exception.MissingCredentialError(required='tenant')

def authenticate(self):
Expand Down
13 changes: 12 additions & 1 deletion glance/tests/unit/test_auth.py
Expand Up @@ -145,7 +145,18 @@ def test_required_creds(self):
'username': 'user1',
'password': 'pass',
'auth_url': 'http://localhost/v2.0/'
} # v2.0: missing tenant
}, # v2.0: missing tenant
{
'username': None,
'password': 'pass',
'auth_url': 'http://localhost/v2.0/'
}, # None parameter
{
'username': 'user1',
'password': 'pass',
'auth_url': 'http://localhost/v2.0/',
'tenant': None
} # None tenant
]
for creds in bad_creds:
try:
Expand Down

0 comments on commit 9f336df

Please sign in to comment.