~ubuntu-branches/ubuntu/quantal/nova/quantal-proposed

« back to all changes in this revision

Viewing changes to nova/tests/test_consoleauth.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-01-20 11:54:15 UTC
  • mto: This revision was merged to the branch mainline in revision 62.
  • Revision ID: package-import@ubuntu.com-20120120115415-h2ujma9o536o1ut6
Tags: upstream-2012.1~e3~20120120.12170
ImportĀ upstreamĀ versionĀ 2012.1~e3~20120120.12170

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
3
# Copyright 2012 OpenStack LLC.
 
4
# Administrator of the National Aeronautics and Space Administration.
 
5
# All Rights Reserved.
 
6
#
 
7
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
8
#    not use this file except in compliance with the License. You may obtain
 
9
#    a copy of the License at
 
10
#
 
11
#         http://www.apache.org/licenses/LICENSE-2.0
 
12
#
 
13
#    Unless required by applicable law or agreed to in writing, software
 
14
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
15
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
16
#    License for the specific language governing permissions and limitations
 
17
#    under the License.
 
18
"""
 
19
Tests for Consoleauth Code.
 
20
 
 
21
"""
 
22
 
 
23
import time
 
24
 
 
25
from nova import context
 
26
from nova import db
 
27
from nova import flags
 
28
from nova import log as logging
 
29
from nova import test
 
30
from nova import utils
 
31
from nova.consoleauth import manager
 
32
 
 
33
 
 
34
FLAGS = flags.FLAGS
 
35
LOG = logging.getLogger('nova.tests.consoleauth')
 
36
 
 
37
 
 
38
class ConsoleauthTestCase(test.TestCase):
 
39
    """Test Case for consoleauth."""
 
40
 
 
41
    def setUp(self):
 
42
        super(ConsoleauthTestCase, self).setUp()
 
43
        self.manager = utils.import_object(FLAGS.consoleauth_manager)
 
44
        self.context = context.get_admin_context()
 
45
        self.old_ttl = FLAGS.console_token_ttl
 
46
 
 
47
    def tearDown(self):
 
48
        super(ConsoleauthTestCase, self).tearDown()
 
49
        FLAGS.console_token_ttl = self.old_ttl
 
50
 
 
51
    def test_tokens_expire(self):
 
52
        """Test that tokens expire correctly."""
 
53
        token = 'mytok'
 
54
        FLAGS.console_token_ttl = 1
 
55
        self.manager.authorize_console(self.context, token, 'novnc',
 
56
                                       '127.0.0.1', 'host', '')
 
57
        self.assertTrue(self.manager.check_token(self.context, token))
 
58
        time.sleep(1.1)
 
59
        self.assertFalse(self.manager.check_token(self.context, token))