]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Increase test coverage for cinder.utils
authorVladislav Kuzmin <vkuzmin@mirantis.com>
Mon, 2 Sep 2013 12:19:50 +0000 (16:19 +0400)
committerVladislav Kuzmin <vkuzmin@mirantis.com>
Tue, 3 Sep 2013 09:31:01 +0000 (13:31 +0400)
Add new tests for:
        check_ssh_injection()
        create_channel()

Change-Id: I0349d87023567b16d6600f5b38fd1daff5cbbdc8

cinder/tests/test_utils.py

index 2e7ed8dbe270e01551a342044dd4509bc20a9d66..3ccdf817e630952e197e3af275703ac914571813 100644 (file)
@@ -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()."""