Navigation Menu

Skip to content

Commit

Permalink
Implementation of tenant,user,role list functions for ldap
Browse files Browse the repository at this point in the history
Bug 983304

Defines functions for the retrival and return of the tenant, user and
role objects in ldap.  They will return in whatever order LDAP provides
them.

Additional fix for pep8 whitespace violation.

Additional change to add some minimal unit tests for the new functions
Tests have successfully run against a live LDAP server

Change-Id: I368ae4097bb9bcdaab7bca0ccc2f9204d58f69d8
  • Loading branch information
dyarnell authored and Adam Young committed Sep 10, 2012
1 parent 832ce92 commit 235c4ce
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
9 changes: 9 additions & 0 deletions keystone/identity/backends/ldap/core.py
Expand Up @@ -116,6 +116,9 @@ def get_tenant(self, tenant_id):
except exception.NotFound:
raise exception.TenantNotFound(tenant_id=tenant_id)

def get_tenants(self):
return self.tenant.get_all()

def get_tenant_by_name(self, tenant_name):
try:
return self.tenant.get_by_name(tenant_name)
Expand All @@ -131,6 +134,9 @@ def _get_user(self, user_id):
def get_user(self, user_id):
return _filter_user(self._get_user(user_id))

def list_users(self):
return self.user.get_all()

def get_user_by_name(self, user_name):
try:
return _filter_user(self.user.get_by_name(user_name))
Expand All @@ -152,6 +158,9 @@ def get_role(self, role_id):
except exception.NotFound:
raise exception.RoleNotFound(role_id=role_id)

def list_roles(self):
return self.role.get_all()

# These should probably be part of the high-level API
# When this happens, then change TenantAPI.add_user to not ignore
# ldap.TYPE_OR_VALUE_EXISTS
Expand Down
31 changes: 31 additions & 0 deletions tests/test_backend.py
Expand Up @@ -16,6 +16,7 @@

import datetime
import uuid
import default_fixtures

from keystone import exception
from keystone.openstack.common import timeutils
Expand Down Expand Up @@ -608,6 +609,36 @@ def test_update_user_invalid_name_fails(self):
'fake1',
user)

def test_list_users(self):
users = self.identity_api.list_users()
for test_user in default_fixtures.USERS:
user_id = test_user['id']
found = False
for user in users:
if user['id'] == user_id:
found = True
self.assertTrue('found')

def test_list_roles(self):
roles = self.identity_api.list_roles()
for test_role in default_fixtures.ROLES:
role_id = test_role['id']
found = False
for role in roles:
if role['id'] == role_id:
found = True
self.assertTrue('found')

def test_get_tenants(self):
tenants = self.identity_api.get_tenants()
for test_tenant in default_fixtures.TENANTS:
tenant_id = test_tenant['id']
found = False
for tenant in tenants:
if tenant['id'] == tenant_id:
found = True
self.assertTrue('found')


class TokenTests(object):
def test_token_crud(self):
Expand Down

0 comments on commit 235c4ce

Please sign in to comment.