Skip to content

Commit

Permalink
Merge "Document & reduce potential for race condition (bug 921634)" i…
Browse files Browse the repository at this point in the history
…nto milestone-proposed
  • Loading branch information
Jenkins authored and openstack-gerrit committed Jan 26, 2012
2 parents fbd1af7 + 8cc0d36 commit a733e4a
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions keystone/test/unit/test_commands.py
Expand Up @@ -818,8 +818,20 @@ def test_delete_service(self):


class TestCreateTokenCommand(CommandTestCase):
tomorrow = (datetime.datetime.utcnow() +
datetime.timedelta(days=1)).strftime('%Y-%m-%dT%H:%M')
"""Creates tokens and validates their attributes.
This class has a known potential race condition, due to the expected
token expiration being 24 hours after token creation. If the
'create_token' command runs immediately before the minute rolls over,
and the test class produces a timestamp for the subsequent minute, the
test will fail.
"""

@staticmethod
def _get_tomorrow_str():
return (datetime.datetime.utcnow() +
datetime.timedelta(days=1)).strftime('%Y-%m-%dT%H:%M')

def test_no_args(self):
with self.assertRaises(SystemExit):
Expand All @@ -829,29 +841,31 @@ def test_create_unscoped_token(self):
user_id = self._create_user()
self.run_cmd(create_token, [
'--user-id', user_id])
tomorrow = TestCreateTokenCommand._get_tomorrow_str()
token_id = self.ob.read_lines()[0]
self.assertEqual(len(token_id), 32)

self.ob.clear()

self.run_cmd(list_tokens)
self.assertTableContainsRow(self.ob.read(), [token_id, user_id,
str(None), self.tomorrow])
str(None), tomorrow])

def test_create_scoped_token(self):
user_id = self._create_user()
tenant_id = self._create_tenant()
self.run_cmd(create_token, [
'--user-id', user_id,
'--tenant-id', tenant_id])
tomorrow = TestCreateTokenCommand._get_tomorrow_str()
token_id = self.ob.read_lines()[0]
self.assertEqual(len(token_id), 32)

self.ob.clear()

self.run_cmd(list_tokens)
self.assertTableContainsRow(self.ob.read(), [token_id, user_id,
tenant_id, self.tomorrow])
tenant_id, tomorrow])

def test_create_expired_token(self):
user_id = self._create_user()
Expand All @@ -874,13 +888,14 @@ def test_create_specific_token_id(self):
self.run_cmd(create_token, [
'--id', token_id,
'--user-id', user_id])
tomorrow = TestCreateTokenCommand._get_tomorrow_str()
self.assertEqual(token_id, self.ob.read_lines()[0])

self.ob.clear()

self.run_cmd(list_tokens)
self.assertTableContainsRow(self.ob.read(), [token_id, user_id,
str(None), self.tomorrow])
str(None), tomorrow])


class TestUpdateTokenCommand(CommandTestCase):
Expand Down

0 comments on commit a733e4a

Please sign in to comment.