]> git.bitcoin.ninja Git - youtube-dl/commitdiff
[test/test_socks] Test with local SOCKS servers
authorYen Chi Hsuan <yan12125@gmail.com>
Thu, 5 May 2016 09:09:13 +0000 (17:09 +0800)
committerYen Chi Hsuan <yan12125@gmail.com>
Tue, 10 May 2016 06:51:38 +0000 (14:51 +0800)
.gitignore
.travis.yml
devscripts/install_srelay.sh [new file with mode: 0755]
test/test_socks.py

index 0e7128551e5624b427447a182b16dc66c75ba5a8..d5f216b5f0dcfb1ad5af0a72c6b8d7b01073f837 100644 (file)
@@ -36,3 +36,4 @@ test/local_parameters.json
 youtube-dl.zsh
 .idea
 .idea/*
+tmp/
index cc21fae8f41ca567a2367d3515f981d8ec0af759..9989958451d2c8f55d1161822f775a94556d6f67 100644 (file)
@@ -7,6 +7,9 @@ python:
   - "3.4"
   - "3.5"
 sudo: false
+install:
+  - bash ./devscripts/install_srelay.sh
+  - export PATH=$PATH:$(pwd)/tmp/srelay-0.4.8b6
 script: nosetests test --verbose
 notifications:
   email:
diff --git a/devscripts/install_srelay.sh b/devscripts/install_srelay.sh
new file mode 100755 (executable)
index 0000000..33ce8a3
--- /dev/null
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+mkdir -p tmp && cd tmp
+wget -N http://downloads.sourceforge.net/project/socks-relay/socks-relay/srelay-0.4.8/srelay-0.4.8b6.tar.gz
+tar zxvf srelay-0.4.8b6.tar.gz
+cd srelay-0.4.8b6
+./configure
+make
index 92574c6fdbfe3b8172df11188691270e9a4314df..dc9b8d276f05bdae7b6647d498a02c201e525db8 100644 (file)
@@ -8,11 +8,20 @@ import sys
 import unittest
 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
 
-from test.helper import (FakeYDL, get_params)
-from youtube_dl.compat import compat_urllib_request
+import random
+import subprocess
 
+from test.helper import (
+    FakeYDL,
+    get_params,
+)
+from youtube_dl.compat import (
+    compat_str,
+    compat_urllib_request,
+)
 
-class TestSocks(unittest.TestCase):
+
+class TestMultipleSocks(unittest.TestCase):
     @staticmethod
     def _check_params(attrs):
         params = get_params()
@@ -67,5 +76,32 @@ class TestSocks(unittest.TestCase):
             params['secondary_server_ip'])
 
 
+class TestSocks(unittest.TestCase):
+    def setUp(self):
+        self.port = random.randint(49152, 65535)
+        self.server_process = subprocess.Popen([
+            'srelay', '-f', '-i', '127.0.0.1:%d' % self.port],
+            stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+
+    def tearDown(self):
+        self.server_process.terminate()
+        self.server_process.communicate()
+
+    def _get_ip(self, protocol):
+        ydl = FakeYDL({
+            'proxy': '%s://127.0.0.1:%d' % (protocol, self.port),
+        })
+        return ydl.urlopen('http://yt-dl.org/ip').read().decode('utf-8')
+
+    def test_socks4(self):
+        self.assertTrue(isinstance(self._get_ip('socks4'), compat_str))
+
+    def test_socks4a(self):
+        self.assertTrue(isinstance(self._get_ip('socks4a'), compat_str))
+
+    def test_socks5(self):
+        self.assertTrue(isinstance(self._get_ip('socks5'), compat_str))
+
+
 if __name__ == '__main__':
     unittest.main()