Merge "Encode consoleauth token in utf-8 to make it a str"

This commit is contained in:
Jenkins
2013-04-23 19:37:35 +00:00
committed by Gerrit Code Review
2 changed files with 53 additions and 10 deletions

View File

@@ -118,7 +118,7 @@ class ConsoleAuthManager(manager.Manager):
def delete_tokens_for_instance(self, context, instance_uuid):
tokens = self._get_tokens_for_instance(instance_uuid)
for token in tokens:
self.mc.delete(token)
self.mc.delete(token.encode('UTF-8'))
self.mc.delete(instance_uuid.encode('UTF-8'))
def get_backdoor_port(self, context):

View File

@@ -20,6 +20,7 @@ Tests for Consoleauth Code.
"""
import mox
from nova.consoleauth import manager
from nova import context
from nova.openstack.common import timeutils
@@ -37,7 +38,7 @@ class ConsoleauthTestCase(test.TestCase):
def test_tokens_expire(self):
# Test that tokens expire correctly.
self.useFixture(test.TimeOverride())
token = 'mytok'
token = u'mytok'
self.flags(console_token_ttl=1)
self._stub_validate_console_port(True)
@@ -58,8 +59,8 @@ class ConsoleauthTestCase(test.TestCase):
fake_validate_console_port)
def test_multiple_tokens_for_instance(self):
tokens = ["token" + str(i) for i in xrange(10)]
instance = "12345"
tokens = [u"token" + str(i) for i in xrange(10)]
instance = u"12345"
self._stub_validate_console_port(True)
@@ -72,8 +73,8 @@ class ConsoleauthTestCase(test.TestCase):
self.assertTrue(self.manager.check_token(self.context, token))
def test_delete_tokens_for_instance(self):
instance = "12345"
tokens = ["token" + str(i) for i in xrange(10)]
instance = u"12345"
tokens = [u"token" + str(i) for i in xrange(10)]
for token in tokens:
self.manager.authorize_console(self.context, token, 'novnc',
'127.0.0.1', '8080', 'host',
@@ -87,20 +88,20 @@ class ConsoleauthTestCase(test.TestCase):
self.assertFalse(self.manager.check_token(self.context, token))
def test_wrong_token_has_port(self):
token = 'mytok'
token = u'mytok'
self._stub_validate_console_port(False)
self.manager.authorize_console(self.context, token, 'novnc',
'127.0.0.1', '8080', 'host',
instance_uuid='instance')
instance_uuid=u'instance')
self.assertFalse(self.manager.check_token(self.context, token))
def test_console_no_instance_uuid(self):
self.manager.authorize_console(self.context, "token", 'novnc',
self.manager.authorize_console(self.context, u"token", 'novnc',
'127.0.0.1', '8080', 'host',
instance_uuid=None)
self.assertFalse(self.manager.check_token(self.context, "token"))
self.assertFalse(self.manager.check_token(self.context, u"token"))
def test_get_backdoor_port(self):
self.manager.backdoor_port = 59697
@@ -108,6 +109,48 @@ class ConsoleauthTestCase(test.TestCase):
self.assertEqual(port, self.manager.backdoor_port)
class ControlauthMemcacheEncodingTestCase(test.TestCase):
def setUp(self):
super(ControlauthMemcacheEncodingTestCase, self).setUp()
self.manager = manager.ConsoleAuthManager()
self.context = context.get_admin_context()
self.u_token = u"token"
self.u_instance = u"instance"
def test_authorize_console_encoding(self):
self.mox.StubOutWithMock(self.manager.mc, "set")
self.mox.StubOutWithMock(self.manager.mc, "get")
self.manager.mc.set(mox.IsA(str), mox.IgnoreArg(), mox.IgnoreArg()
).AndReturn(True)
self.manager.mc.get(mox.IsA(str)).AndReturn(None)
self.manager.mc.set(mox.IsA(str), mox.IgnoreArg()).AndReturn(True)
self.mox.ReplayAll()
self.manager.authorize_console(self.context, self.u_token, 'novnc',
'127.0.0.1', '8080', 'host',
self.u_instance)
def test_check_token_encoding(self):
self.mox.StubOutWithMock(self.manager.mc, "get")
self.manager.mc.get(mox.IsA(str)).AndReturn(None)
self.mox.ReplayAll()
self.manager.check_token(self.context, self.u_token)
def test_delete_tokens_for_instance_encoding(self):
self.mox.StubOutWithMock(self.manager.mc, "delete")
self.mox.StubOutWithMock(self.manager.mc, "get")
self.manager.mc.get(mox.IsA(str)).AndReturn('["token"]')
self.manager.mc.delete(mox.IsA(str)).AndReturn(True)
self.manager.mc.delete(mox.IsA(str)).AndReturn(True)
self.mox.ReplayAll()
self.manager.delete_tokens_for_instance(self.context, self.u_instance)
class CellsConsoleauthTestCase(ConsoleauthTestCase):
"""Test Case for consoleauth w/ cells enabled."""