From 0802e199640c9a15707b33b71235c226ad511144 Mon Sep 17 00:00:00 2001
From: Vladislav Kuzmin <vkuzmin@mirantis.com>
Date: Mon, 2 Sep 2013 16:19:50 +0400
Subject: [PATCH] Increase test coverage for cinder.utils

Add new tests for:
        check_ssh_injection()
        create_channel()

Change-Id: I0349d87023567b16d6600f5b38fd1daff5cbbdc8
---
 cinder/tests/test_utils.py | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

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()."""
-- 
2.45.2