From 4991a601c6cbd6ec95c6cdd0ee156aeb5e5129df Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 23 Sep 2013 06:25:27 +0000 Subject: [PATCH] support proxy authentication in http.py and tests --- test/http.py | 30 +++++++++++++++++++++++++----- test/setup_transfer.cpp | 2 +- test/test_transfer.cpp | 1 - 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/test/http.py b/test/http.py index 9037bc109..b9b0ce479 100644 --- a/test/http.py +++ b/test/http.py @@ -81,19 +81,32 @@ Qual a diferença entre um proxy Elite, Anónimo e Transparente? """ -import socket, thread, select, sys +import socket, thread, select, sys, base64 __version__ = '0.1.0 Draft 1' BUFLEN = 8192 VERSION = 'Python Proxy/'+__version__ HTTPVER = 'HTTP/1.1' +username = None +password = None + class ConnectionHandler: def __init__(self, connection, address, timeout): self.client = connection self.client_buffer = '' self.timeout = timeout self.method, self.path, self.protocol = self.get_base_header() + global username + global password + if username != None: + auth = base64.b64encode(username + ':' + password) + if not 'Proxy-Authorization: Basic ' + auth in self.client_buffer: + print 'failed authentication: %s' % self.client_buffer + self.client.send(HTTPVER+' 401 Authentication Failed\n'+ + 'Proxy-agent: %s\n\n'%VERSION) + self.client.close() + return try: if self.method=='CONNECT': self.method_CONNECT() @@ -112,12 +125,13 @@ class ConnectionHandler: def get_base_header(self): while 1: self.client_buffer += self.client.recv(BUFLEN) - end = self.client_buffer.find('\n') + end = self.client_buffer.find('\r\n\r\n') if end!=-1: break - print '%s'%self.client_buffer[:end]#debug - data = (self.client_buffer[:end+1]).split() - self.client_buffer = self.client_buffer[end+1:] + line_end = self.client_buffer.find('\n') + print '%s'%self.client_buffer[:line_end]#debug + data = (self.client_buffer[:line_end+1]).split() + self.client_buffer = self.client_buffer[line_end+1:] return data def method_CONNECT(self): @@ -191,6 +205,12 @@ if __name__ == '__main__': if sys.argv[i] == '--port': listen_port = int(sys.argv[i+1]) i += 1 + elif sys.argv[i] == '--username': + username = sys.argv[i+1] + i += 1 + elif sys.argv[i] == '--password': + password = sys.argv[i+1] + i += 1 else: if sys.argv[i] != '--help': print('unknown option "%s"' % sys.argv[i]) print('usage: http.py [--port ]') diff --git a/test/setup_transfer.cpp b/test/setup_transfer.cpp index cd6bbd52c..b58a19799 100644 --- a/test/setup_transfer.cpp +++ b/test/setup_transfer.cpp @@ -419,7 +419,7 @@ int start_proxy(int proxy_type) break; case proxy_settings::http_pw: type = "http"; - auth = " AUTHORIZER=-list{testuser:testpass}"; + auth = " --username testuser --password testpass"; cmd = "python ../http.py"; break; } diff --git a/test/test_transfer.cpp b/test/test_transfer.cpp index b4e48bd17..be91d5762 100644 --- a/test/test_transfer.cpp +++ b/test/test_transfer.cpp @@ -636,7 +636,6 @@ int test_main() && !defined _GLIBCXX_DEBUG // test rate only makes sense in release mode test_rate(); - return 0; #endif // test with all kinds of proxies