From: Vladislav Kuzmin Date: Mon, 2 Sep 2013 12:19:50 +0000 (+0400) Subject: Increase test coverage for cinder.utils X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=0802e199640c9a15707b33b71235c226ad511144;p=openstack-build%2Fcinder-build.git Increase test coverage for cinder.utils Add new tests for: check_ssh_injection() create_channel() Change-Id: I0349d87023567b16d6600f5b38fd1daff5cbbdc8 --- diff --git a/cinder/tests/test_utils.py b/cinder/tests/test_utils.py index 2e7ed8dbe..3ccdf817e 100644 --- a/cinder/tests/test_utils.py +++ b/cinder/tests/test_utils.py @@ -454,6 +454,34 @@ class GenericUtilsTestCase(test.TestCase): h2 = hashlib.sha1(data).hexdigest() self.assertEquals(h1, h2) + def test_check_ssh_injection(self): + cmd_list = ['ssh', '-D', 'my_name@name_of_remote_computer'] + self.assertEqual(utils.check_ssh_injection(cmd_list), None) + + def test_check_ssh_injection_on_error(self): + with_space = ['shh', 'my_name@ name_of_remote_computer'] + with_danger_char = ['||', 'my_name@name_of_remote_computer'] + self.assertRaises(exception.SSHInjectionThreat, + utils.check_ssh_injection, + with_space) + self.assertRaises(exception.SSHInjectionThreat, + utils.check_ssh_injection, + with_danger_char) + + def test_create_channel(self): + client = paramiko.SSHClient() + channel = paramiko.Channel(123) + self.mox.StubOutWithMock(client, 'invoke_shell') + self.mox.StubOutWithMock(channel, 'resize_pty') + + client.invoke_shell().AndReturn(channel) + channel.resize_pty(600, 800) + + self.mox.ReplayAll() + utils.create_channel(client, 600, 800) + + self.mox.VerifyAll() + class MonkeyPatchTestCase(test.TestCase): """Unit test for utils.monkey_patch()."""