Skip to content

Commit

Permalink
Ensure username passed by REMOTE_USER can contain '@'
Browse files Browse the repository at this point in the history
The external authentication support allows the domain to be passed
as part of the REMOTE_USER name, by using the '@' as a delineator,
but did not handle the case when the actual username itself also
contained the '@' character.

Fixes bug 1213842

Change-Id: Idffa42fe9c70818c71379669dfcd17d3113738a3
  • Loading branch information
henrynash committed Aug 20, 2013
1 parent 0b2a160 commit c70a784
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
7 changes: 4 additions & 3 deletions keystone/auth/plugins/external.py
Expand Up @@ -57,16 +57,17 @@ def authenticate(self, context, auth_info, auth_context):
auth_context is an in-out variable that will be updated with the
username from the REMOTE_USER environment variable.
If REMOTE_USER contains an `@` assume that the substring before the @
is the username, and the substring after the @ is the domain name.
If REMOTE_USER contains an `@` assume that the substring before the
rightmost `@` is the username, and the substring after the @ is the
domain name.
"""
try:
REMOTE_USER = context['REMOTE_USER']
except KeyError:
msg = _('No authenticated user')
raise exception.Unauthorized(msg)
try:
names = REMOTE_USER.split('@')
names = REMOTE_USER.rsplit('@', 1)
username = names.pop(0)
if names:
domain_name = names[0]
Expand Down
13 changes: 12 additions & 1 deletion keystone/tests/test_v3_auth.py
Expand Up @@ -856,7 +856,18 @@ def test_remote_user_with_realm(self):
api = auth.controllers.Auth()
context = {'REMOTE_USER': '%s@%s' %
(self.user['name'], self.domain['name'])}
auth_info = auth.controllers.AuthInfo(None, auth_data)
auth_info = auth.controllers.AuthInfo(context, auth_data)
auth_context = {'extras': {}, 'method_names': []}
api.authenticate(context, auth_info, auth_context)
self.assertEqual(auth_context['user_id'], self.user['id'])

# Now test to make sure the user name can, itself, contain the
# '@' character.
user = {'name': 'myname@mydivision'}
self.identity_api.update_user(self.user['id'], user)
context = {'REMOTE_USER': '%s@%s' %
(user['name'], self.domain['name'])}
auth_info = auth.controllers.AuthInfo(context, auth_data)
auth_context = {'extras': {}, 'method_names': []}
api.authenticate(context, auth_info, auth_context)
self.assertEqual(auth_context['user_id'], self.user['id'])
Expand Down

0 comments on commit c70a784

Please sign in to comment.