nova/nova/tests/consoleauth/test_consoleauth.py
Clark Boylan 2ce5fee0d6 Remove sleep in test_consoleauth.
test_consoleauth:ConsoleauthTestCase.test_tokens_expire called
time.sleep(1.1) in order to test that tokens with a TTL of 1 second
expire after one second. Problem is time.sleep() may return before the
entire sleep period is complete. Remove the sleep and instead use Oslo's
timeutils to override the time and advance it by one second to check
that expired tokens do expire.

Part of blueprint grizzly-testtools

Change-Id: Iae0e678fb12a76757523dc7dbccb4da98cef85e6
2012-12-13 10:19:02 -08:00

62 lines
2.0 KiB
Python

# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2012 OpenStack LLC.
# Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""
Tests for Consoleauth Code.
"""
import fixtures
import time
from nova.consoleauth import manager
from nova import context
from nova.openstack.common import log as logging
from nova.openstack.common import timeutils
from nova import test
LOG = logging.getLogger(__name__)
class TimeOverride(fixtures.Fixture):
"""Fixture to start and remove time override."""
def setUp(self):
super(TimeOverride, self).setUp()
timeutils.set_time_override()
self.addCleanup(timeutils.clear_time_override)
class ConsoleauthTestCase(test.TestCase):
"""Test Case for consoleauth."""
def setUp(self):
super(ConsoleauthTestCase, self).setUp()
self.manager = manager.ConsoleAuthManager()
self.context = context.get_admin_context()
def test_tokens_expire(self):
"""Test that tokens expire correctly."""
self.useFixture(TimeOverride())
token = 'mytok'
self.flags(console_token_ttl=1)
self.manager.authorize_console(self.context, token, 'novnc',
'127.0.0.1', 'host', '')
self.assertTrue(self.manager.check_token(self.context, token))
timeutils.advance_time_seconds(1)
self.assertFalse(self.manager.check_token(self.context, token))