forked from huashengdun/webssh
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5dd08a7
commit acc3b47
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import unittest | ||
|
||
from handler import MixinHandler | ||
|
||
|
||
class RequestMock(object): | ||
|
||
def __init__(self): | ||
self.headers = {} | ||
|
||
def set_ip(self, ip): | ||
self.headers['X-Real-Ip'] = ip | ||
|
||
def set_port(self, port): | ||
self.headers['X-Real-Port'] = port | ||
|
||
|
||
class TestMixinHandler(unittest.TestCase): | ||
|
||
def test_get_real_client_addr(self): | ||
handler = MixinHandler() | ||
handler.request = RequestMock() | ||
self.assertIsNone(handler.get_real_client_addr()) | ||
|
||
ip = '127.0.0.1' | ||
handler.request.set_ip(ip) | ||
with self.assertLogs() as cm: | ||
handler.get_real_client_addr() | ||
self.assertEqual(cm.output, ['WARNING:root:Bad nginx configuration.']) | ||
|
||
handler.request.set_port('12345x') | ||
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)) |