diff options
author | Jenkins <jenkins@review.openstack.org> | 2013-04-23 19:37:35 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2013-04-23 19:37:35 +0000 |
commit | c59514eca02b0eef55648f418abcba8fd8bc7d70 (patch) | |
tree | bb30c277061cde538aa32a9aeadfbbb44ceb5485 | |
parent | 1ff01cc64764ada3ca38c95b321156f1b0df8530 (diff) | |
parent | 6dadf73305c0a3d779dd625a8349b4a7341df18d (diff) | |
download | nova-c59514eca02b0eef55648f418abcba8fd8bc7d70.tar.gz nova-c59514eca02b0eef55648f418abcba8fd8bc7d70.tar.xz nova-c59514eca02b0eef55648f418abcba8fd8bc7d70.zip |
Merge "Encode consoleauth token in utf-8 to make it a str"
-rw-r--r-- | nova/consoleauth/manager.py | 2 | ||||
-rw-r--r-- | nova/tests/consoleauth/test_consoleauth.py | 61 |
2 files changed, 53 insertions, 10 deletions
diff --git a/nova/consoleauth/manager.py b/nova/consoleauth/manager.py index 80a6d447f..26bdcd1d4 100644 --- a/nova/consoleauth/manager.py +++ b/nova/consoleauth/manager.py @@ -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): diff --git a/nova/tests/consoleauth/test_consoleauth.py b/nova/tests/consoleauth/test_consoleauth.py index 41bec05e1..ae5a6102c 100644 --- a/nova/tests/consoleauth/test_consoleauth.py +++ b/nova/tests/consoleauth/test_consoleauth.py @@ -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.""" |