webssh

Web based ssh client https://github.com/huashengdun/webssh webssh.huashengdun.org/
git clone http://git.hanabi.in/repos/webssh.git
Log | Files | Refs | README | LICENSE

commit 42ac3daf87d5c4cf2961c147dca8ab2fd1a6d9e7
parent acc3b47ec6d29e2e65525deaabff234a695e5bb4
Author: Sheng <webmaster0115@gmail.com>
Date:   Tue, 24 Apr 2018 10:23:45 +0800

Updated test_handler.py

Diffstat:
Mtests/test_handler.py | 21+++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/tests/test_handler.py b/tests/test_handler.py @@ -1,4 +1,5 @@ import unittest +import sys from handler import MixinHandler @@ -17,11 +18,26 @@ class RequestMock(object): class TestMixinHandler(unittest.TestCase): - def test_get_real_client_addr(self): + def test_get_real_client_addr_without_nginx_config(self): handler = MixinHandler() handler.request = RequestMock() self.assertIsNone(handler.get_real_client_addr()) + def test_get_real_client_addr_with_correct_nginx_config(self): + handler = MixinHandler() + handler.request = RequestMock() + + ip = '127.0.0.1' + handler.request.set_ip(ip) + handler.request.set_port('12345') + self.assertEqual(handler.get_real_client_addr(), (ip, 12345)) + + @unittest.skipIf(sys.version_info < (3,), + reason='assertLogs not supported in Python 2') + def test_get_real_client_addr_with_bad_nginx_config(self): + handler = MixinHandler() + handler.request = RequestMock() + ip = '127.0.0.1' handler.request.set_ip(ip) with self.assertLogs() as cm: @@ -32,6 +48,3 @@ class TestMixinHandler(unittest.TestCase): with self.assertLogs() as cm: handler.get_real_client_addr() self.assertEqual(cm.output, ['WARNING:root:Bad nginx configuration.']) - - handler.request.set_port('12345') - self.assertEqual(handler.get_real_client_addr(), (ip, 12345))