diff options
| author | termie <github@anarkystic.com> | 2011-11-03 14:11:36 -0700 |
|---|---|---|
| committer | termie <github@anarkystic.com> | 2011-11-03 14:11:36 -0700 |
| commit | 4c8a5ac747aa6165bfa1a3f30e93491f0cda730a (patch) | |
| tree | 53bcfa7b429d6703997ceb142b0cbfe2f1bc4e34 | |
| parent | b514897be6fc1334b7cfc4d29137563286c2912c (diff) | |
add some failing tests
| -rw-r--r-- | keystonelight/backends/kvs.py | 8 | ||||
| -rw-r--r-- | tests/test_backend_kvs.py | 46 |
2 files changed, 54 insertions, 0 deletions
diff --git a/keystonelight/backends/kvs.py b/keystonelight/backends/kvs.py index a9221124..3d1f53c4 100644 --- a/keystonelight/backends/kvs.py +++ b/keystonelight/backends/kvs.py @@ -12,10 +12,18 @@ class KvsIdentity(object): def __init__(self, options, db=None): if db is None: db = INMEMDB + elif type(db) is type({}): + db = DictKvs(db) self.db = db # Public interface def authenticate(self, user_id=None, tenant_id=None, password=None): + """Authenticate based on a user, tenant and password. + + Expects the user object to have a password field and the tenant to be + in the list of tenants on the user. + + """ user_ref = self.get_user(user_id) tenant_ref = None extras_ref = None diff --git a/tests/test_backend_kvs.py b/tests/test_backend_kvs.py new file mode 100644 index 00000000..b67cf575 --- /dev/null +++ b/tests/test_backend_kvs.py @@ -0,0 +1,46 @@ + +from keystonelight import models +from keystonelight import test +from keystonelight.backends import kvs + + +class KvsIdentity(test.TestCase): + def setUp(self): + super(KvsIdentity, self).setUp() + options = self.appconfig('default') + self.identity_api = kvs.KvsIdentity(options=options, db={}) + self._load_fixtures() + + def _load_fixtures(self): + self.tenant_bar = self.identity_api._create_tenant( + 'bar', + models.Tenant(id='bar', name='BAR')) + self.user_foo = self.identity_api._create_user( + 'foo', + models.User(id='foo', + name='FOO', + password='foo2', + tenants=[self.tenant_bar['id']])) + + + def test_authenticate_bad_user(self): + self.assertRaises(AssertionError, + self.identity_api.authenticate, + user_id=self.user_foo['id'] + 'WRONG', + tenant_id=self.tenant_bar['id'], + password=self.user_foo['password']) + + def test_authenticate_bad_password(self): + self.assertRaises(AssertionError, + self.identity_api.authenticate, + user_id=self.user_foo['id'], + tenant_id=self.tenant_bar['id'], + password=self.user_foo['password'] + 'WRONG') + + + def test_authenticate_invalid_tenant(self): + self.assertRaises(AssertionError, + self.identity_api.authenticate, + user_id=self.user_foo['id'], + tenant_id=self.tenant_bar['id'] + 'WRONG', + password=self.user_foo['password']) |
