mirror of
				https://github.com/yt-dlp/yt-dlp.git
				synced 2025-10-31 14:45:14 +00:00 
			
		
		
		
	[rh:curlcffi] Add support for curl_cffi
				
					
				
			Authored by: coletdjnz, Grub4K, pukkandan, bashonly Co-authored-by: Simon Sawicki <contact@grub4k.xyz> Co-authored-by: pukkandan <pukkandan.ytdlp@gmail.com> Co-authored-by: bashonly <bashonly@protonmail.com>
This commit is contained in:
		| @@ -286,8 +286,14 @@ def ctx(request): | ||||
|     return CTX_MAP[request.param]() | ||||
| 
 | ||||
| 
 | ||||
| @pytest.mark.parametrize( | ||||
|     'handler,ctx', [ | ||||
|         ('Urllib', 'http'), | ||||
|         ('Requests', 'http'), | ||||
|         ('Websockets', 'ws'), | ||||
|         ('CurlCFFI', 'http') | ||||
|     ], indirect=True) | ||||
| class TestSocks4Proxy: | ||||
|     @pytest.mark.parametrize('handler,ctx', [('Urllib', 'http'), ('Requests', 'http'), ('Websockets', 'ws')], indirect=True) | ||||
|     def test_socks4_no_auth(self, handler, ctx): | ||||
|         with handler() as rh: | ||||
|             with ctx.socks_server(Socks4ProxyHandler) as server_address: | ||||
| @@ -295,7 +301,6 @@ class TestSocks4Proxy: | ||||
|                     rh, proxies={'all': f'socks4://{server_address}'}) | ||||
|                 assert response['version'] == 4 | ||||
| 
 | ||||
|     @pytest.mark.parametrize('handler,ctx', [('Urllib', 'http'), ('Requests', 'http'), ('Websockets', 'ws')], indirect=True) | ||||
|     def test_socks4_auth(self, handler, ctx): | ||||
|         with handler() as rh: | ||||
|             with ctx.socks_server(Socks4ProxyHandler, user_id='user') as server_address: | ||||
| @@ -305,7 +310,6 @@ class TestSocks4Proxy: | ||||
|                     rh, proxies={'all': f'socks4://user:@{server_address}'}) | ||||
|                 assert response['version'] == 4 | ||||
| 
 | ||||
|     @pytest.mark.parametrize('handler,ctx', [('Urllib', 'http'), ('Requests', 'http'), ('Websockets', 'ws')], indirect=True) | ||||
|     def test_socks4a_ipv4_target(self, handler, ctx): | ||||
|         with ctx.socks_server(Socks4ProxyHandler) as server_address: | ||||
|             with handler(proxies={'all': f'socks4a://{server_address}'}) as rh: | ||||
| @@ -313,7 +317,6 @@ class TestSocks4Proxy: | ||||
|                 assert response['version'] == 4 | ||||
|                 assert (response['ipv4_address'] == '127.0.0.1') != (response['domain_address'] == '127.0.0.1') | ||||
| 
 | ||||
|     @pytest.mark.parametrize('handler,ctx', [('Urllib', 'http'), ('Requests', 'http'), ('Websockets', 'ws')], indirect=True) | ||||
|     def test_socks4a_domain_target(self, handler, ctx): | ||||
|         with ctx.socks_server(Socks4ProxyHandler) as server_address: | ||||
|             with handler(proxies={'all': f'socks4a://{server_address}'}) as rh: | ||||
| @@ -322,7 +325,6 @@ class TestSocks4Proxy: | ||||
|                 assert response['ipv4_address'] is None | ||||
|                 assert response['domain_address'] == 'localhost' | ||||
| 
 | ||||
|     @pytest.mark.parametrize('handler,ctx', [('Urllib', 'http'), ('Requests', 'http'), ('Websockets', 'ws')], indirect=True) | ||||
|     def test_ipv4_client_source_address(self, handler, ctx): | ||||
|         with ctx.socks_server(Socks4ProxyHandler) as server_address: | ||||
|             source_address = f'127.0.0.{random.randint(5, 255)}' | ||||
| @@ -333,7 +335,6 @@ class TestSocks4Proxy: | ||||
|                 assert response['client_address'][0] == source_address | ||||
|                 assert response['version'] == 4 | ||||
| 
 | ||||
|     @pytest.mark.parametrize('handler,ctx', [('Urllib', 'http'), ('Requests', 'http'), ('Websockets', 'ws')], indirect=True) | ||||
|     @pytest.mark.parametrize('reply_code', [ | ||||
|         Socks4CD.REQUEST_REJECTED_OR_FAILED, | ||||
|         Socks4CD.REQUEST_REJECTED_CANNOT_CONNECT_TO_IDENTD, | ||||
| @@ -345,7 +346,6 @@ class TestSocks4Proxy: | ||||
|                 with pytest.raises(ProxyError): | ||||
|                     ctx.socks_info_request(rh) | ||||
| 
 | ||||
|     @pytest.mark.parametrize('handler,ctx', [('Urllib', 'http'), ('Requests', 'http'), ('Websockets', 'ws')], indirect=True) | ||||
|     def test_ipv6_socks4_proxy(self, handler, ctx): | ||||
|         with ctx.socks_server(Socks4ProxyHandler, bind_ip='::1') as server_address: | ||||
|             with handler(proxies={'all': f'socks4://{server_address}'}) as rh: | ||||
| @@ -354,7 +354,6 @@ class TestSocks4Proxy: | ||||
|                 assert response['ipv4_address'] == '127.0.0.1' | ||||
|                 assert response['version'] == 4 | ||||
| 
 | ||||
|     @pytest.mark.parametrize('handler,ctx', [('Urllib', 'http'), ('Requests', 'http'), ('Websockets', 'ws')], indirect=True) | ||||
|     def test_timeout(self, handler, ctx): | ||||
|         with ctx.socks_server(Socks4ProxyHandler, sleep=2) as server_address: | ||||
|             with handler(proxies={'all': f'socks4://{server_address}'}, timeout=0.5) as rh: | ||||
| @@ -362,9 +361,15 @@ class TestSocks4Proxy: | ||||
|                     ctx.socks_info_request(rh) | ||||
| 
 | ||||
| 
 | ||||
| @pytest.mark.parametrize( | ||||
|     'handler,ctx', [ | ||||
|         ('Urllib', 'http'), | ||||
|         ('Requests', 'http'), | ||||
|         ('Websockets', 'ws'), | ||||
|         ('CurlCFFI', 'http') | ||||
|     ], indirect=True) | ||||
| class TestSocks5Proxy: | ||||
| 
 | ||||
|     @pytest.mark.parametrize('handler,ctx', [('Urllib', 'http'), ('Requests', 'http'), ('Websockets', 'ws')], indirect=True) | ||||
|     def test_socks5_no_auth(self, handler, ctx): | ||||
|         with ctx.socks_server(Socks5ProxyHandler) as server_address: | ||||
|             with handler(proxies={'all': f'socks5://{server_address}'}) as rh: | ||||
| @@ -372,7 +377,6 @@ class TestSocks5Proxy: | ||||
|                 assert response['auth_methods'] == [0x0] | ||||
|                 assert response['version'] == 5 | ||||
| 
 | ||||
|     @pytest.mark.parametrize('handler,ctx', [('Urllib', 'http'), ('Requests', 'http'), ('Websockets', 'ws')], indirect=True) | ||||
|     def test_socks5_user_pass(self, handler, ctx): | ||||
|         with ctx.socks_server(Socks5ProxyHandler, auth=('test', 'testpass')) as server_address: | ||||
|             with handler() as rh: | ||||
| @@ -385,7 +389,6 @@ class TestSocks5Proxy: | ||||
|                 assert response['auth_methods'] == [Socks5Auth.AUTH_NONE, Socks5Auth.AUTH_USER_PASS] | ||||
|                 assert response['version'] == 5 | ||||
| 
 | ||||
|     @pytest.mark.parametrize('handler,ctx', [('Urllib', 'http'), ('Requests', 'http'), ('Websockets', 'ws')], indirect=True) | ||||
|     def test_socks5_ipv4_target(self, handler, ctx): | ||||
|         with ctx.socks_server(Socks5ProxyHandler) as server_address: | ||||
|             with handler(proxies={'all': f'socks5://{server_address}'}) as rh: | ||||
| @@ -393,7 +396,6 @@ class TestSocks5Proxy: | ||||
|                 assert response['ipv4_address'] == '127.0.0.1' | ||||
|                 assert response['version'] == 5 | ||||
| 
 | ||||
|     @pytest.mark.parametrize('handler,ctx', [('Urllib', 'http'), ('Requests', 'http'), ('Websockets', 'ws')], indirect=True) | ||||
|     def test_socks5_domain_target(self, handler, ctx): | ||||
|         with ctx.socks_server(Socks5ProxyHandler) as server_address: | ||||
|             with handler(proxies={'all': f'socks5://{server_address}'}) as rh: | ||||
| @@ -401,7 +403,6 @@ class TestSocks5Proxy: | ||||
|                 assert (response['ipv4_address'] == '127.0.0.1') != (response['ipv6_address'] == '::1') | ||||
|                 assert response['version'] == 5 | ||||
| 
 | ||||
|     @pytest.mark.parametrize('handler,ctx', [('Urllib', 'http'), ('Requests', 'http'), ('Websockets', 'ws')], indirect=True) | ||||
|     def test_socks5h_domain_target(self, handler, ctx): | ||||
|         with ctx.socks_server(Socks5ProxyHandler) as server_address: | ||||
|             with handler(proxies={'all': f'socks5h://{server_address}'}) as rh: | ||||
| @@ -410,7 +411,6 @@ class TestSocks5Proxy: | ||||
|                 assert response['domain_address'] == 'localhost' | ||||
|                 assert response['version'] == 5 | ||||
| 
 | ||||
|     @pytest.mark.parametrize('handler,ctx', [('Urllib', 'http'), ('Requests', 'http'), ('Websockets', 'ws')], indirect=True) | ||||
|     def test_socks5h_ip_target(self, handler, ctx): | ||||
|         with ctx.socks_server(Socks5ProxyHandler) as server_address: | ||||
|             with handler(proxies={'all': f'socks5h://{server_address}'}) as rh: | ||||
| @@ -419,7 +419,6 @@ class TestSocks5Proxy: | ||||
|                 assert response['domain_address'] is None | ||||
|                 assert response['version'] == 5 | ||||
| 
 | ||||
|     @pytest.mark.parametrize('handler,ctx', [('Urllib', 'http'), ('Requests', 'http'), ('Websockets', 'ws')], indirect=True) | ||||
|     def test_socks5_ipv6_destination(self, handler, ctx): | ||||
|         with ctx.socks_server(Socks5ProxyHandler) as server_address: | ||||
|             with handler(proxies={'all': f'socks5://{server_address}'}) as rh: | ||||
| @@ -427,7 +426,6 @@ class TestSocks5Proxy: | ||||
|                 assert response['ipv6_address'] == '::1' | ||||
|                 assert response['version'] == 5 | ||||
| 
 | ||||
|     @pytest.mark.parametrize('handler,ctx', [('Urllib', 'http'), ('Requests', 'http'), ('Websockets', 'ws')], indirect=True) | ||||
|     def test_ipv6_socks5_proxy(self, handler, ctx): | ||||
|         with ctx.socks_server(Socks5ProxyHandler, bind_ip='::1') as server_address: | ||||
|             with handler(proxies={'all': f'socks5://{server_address}'}) as rh: | ||||
| @@ -438,7 +436,6 @@ class TestSocks5Proxy: | ||||
| 
 | ||||
|     # XXX: is there any feasible way of testing IPv6 source addresses? | ||||
|     # Same would go for non-proxy source_address test... | ||||
|     @pytest.mark.parametrize('handler,ctx', [('Urllib', 'http'), ('Requests', 'http'), ('Websockets', 'ws')], indirect=True) | ||||
|     def test_ipv4_client_source_address(self, handler, ctx): | ||||
|         with ctx.socks_server(Socks5ProxyHandler) as server_address: | ||||
|             source_address = f'127.0.0.{random.randint(5, 255)}' | ||||
| @@ -448,7 +445,6 @@ class TestSocks5Proxy: | ||||
|                 assert response['client_address'][0] == source_address | ||||
|                 assert response['version'] == 5 | ||||
| 
 | ||||
|     @pytest.mark.parametrize('handler,ctx', [('Urllib', 'http'), ('Requests', 'http'), ('Websockets', 'ws')], indirect=True) | ||||
|     @pytest.mark.parametrize('reply_code', [ | ||||
|         Socks5Reply.GENERAL_FAILURE, | ||||
|         Socks5Reply.CONNECTION_NOT_ALLOWED, | ||||
| @@ -465,7 +461,6 @@ class TestSocks5Proxy: | ||||
|                 with pytest.raises(ProxyError): | ||||
|                     ctx.socks_info_request(rh) | ||||
| 
 | ||||
|     @pytest.mark.parametrize('handler,ctx', [('Urllib', 'http'), ('Websockets', 'ws')], indirect=True) | ||||
|     def test_timeout(self, handler, ctx): | ||||
|         with ctx.socks_server(Socks5ProxyHandler, sleep=2) as server_address: | ||||
|             with handler(proxies={'all': f'socks5://{server_address}'}, timeout=1) as rh: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 coletdjnz
					coletdjnz