Compare commits
	
		
			No commits in common. "2b138446d47728092abad96fd89e5b3777b963e4" and "e5f9b39025ea757af5eb59f40278de8a4ef696ec" have entirely different histories.
		
	
	
		
			2b138446d4
			...
			e5f9b39025
		
	
		
							
								
								
									
										12
									
								
								servefile
								
								
								
								
							
							
						
						
									
										12
									
								
								servefile
								
								
								
								
							|  | @ -1,4 +1,4 @@ | ||||||
| #!/usr/bin/env python | #!/usr/bin/python | ||||||
| # -*- coding: utf-8 -*- | # -*- coding: utf-8 -*- | ||||||
| 
 | 
 | ||||||
| # Licensed under GNU General Public License v3 or later | # Licensed under GNU General Public License v3 or later | ||||||
|  | @ -312,7 +312,7 @@ class DirListingHandler(FileBaseHandler): | ||||||
| 		path = self.getCleanPath() | 		path = self.getCleanPath() | ||||||
| 
 | 
 | ||||||
| 		# check if path is in current serving directory | 		# check if path is in current serving directory | ||||||
| 		currBaseDir = self.targetDir + os.path.sep | 		currBaseDir = os.path.abspath(self.targetDir) + os.path.sep | ||||||
| 		requestPath = os.path.normpath(os.path.join(currBaseDir, path)) + os.path.sep | 		requestPath = os.path.normpath(os.path.join(currBaseDir, path)) + os.path.sep | ||||||
| 		if not requestPath.startswith(currBaseDir): | 		if not requestPath.startswith(currBaseDir): | ||||||
| 			self.send_response(301) | 			self.send_response(301) | ||||||
|  | @ -849,9 +849,9 @@ class ServeFile(): | ||||||
| 
 | 
 | ||||||
| 			# filter out ips we are not listening on | 			# filter out ips we are not listening on | ||||||
| 			if not self.listenIPv6: | 			if not self.listenIPv6: | ||||||
| 				ips = [ip for ip in ips if '.' in ip] | 				ips = filter(lambda ip: ":" not in ip, ips) | ||||||
| 			if not self.listenIPv4: | 			if not self.listenIPv4: | ||||||
| 				ips = [ip for ip in ips if ':' in ip] | 				ips = filter(lambda ip: "." not in ip, ips) | ||||||
| 
 | 
 | ||||||
| 			return ips | 			return ips | ||||||
| 		return None | 		return None | ||||||
|  | @ -1041,7 +1041,7 @@ class ServeFile(): | ||||||
| 					raise ServeFileException("Error: Could not create directory '%s' for uploads, %r" % (self.target, str(e))) | 					raise ServeFileException("Error: Could not create directory '%s' for uploads, %r" % (self.target, str(e))) | ||||||
| 			else: | 			else: | ||||||
| 				raise ServeFileException("Error: Upload directory already exists and is a file.") | 				raise ServeFileException("Error: Upload directory already exists and is a file.") | ||||||
| 			FilePutter.targetDir = os.path.abspath(self.target) | 			FilePutter.targetDir = self.target | ||||||
| 			FilePutter.maxUploadSize = self.maxUploadSize | 			FilePutter.maxUploadSize = self.maxUploadSize | ||||||
| 			handler = FilePutter | 			handler = FilePutter | ||||||
| 		elif self.serveMode == self.MODE_LISTDIR: | 		elif self.serveMode == self.MODE_LISTDIR: | ||||||
|  | @ -1050,7 +1050,7 @@ class ServeFile(): | ||||||
| 			if not os.path.isdir(self.target): | 			if not os.path.isdir(self.target): | ||||||
| 				raise ServeFileException("Error: '%s' is not a directory." % (self.target,)) | 				raise ServeFileException("Error: '%s' is not a directory." % (self.target,)) | ||||||
| 			handler = DirListingHandler | 			handler = DirListingHandler | ||||||
| 			handler.targetDir = os.path.abspath(self.target) | 			handler.targetDir = self.target | ||||||
| 
 | 
 | ||||||
| 		if self.auth: | 		if self.auth: | ||||||
| 			# do authentication | 			# do authentication | ||||||
|  |  | ||||||
|  | @ -2,7 +2,6 @@ import io | ||||||
| import os | import os | ||||||
| import pytest | import pytest | ||||||
| import requests | import requests | ||||||
| import socket |  | ||||||
| import subprocess | import subprocess | ||||||
| import tarfile | import tarfile | ||||||
| import time | import time | ||||||
|  | @ -10,12 +9,6 @@ import urllib3 | ||||||
| 
 | 
 | ||||||
| # crudly written to learn more about pytest and to have a base for refactoring | # crudly written to learn more about pytest and to have a base for refactoring | ||||||
| 
 | 
 | ||||||
| try: |  | ||||||
|     ConnectionRefusedError |  | ||||||
|     connrefused_exc = ConnectionRefusedError |  | ||||||
| except NameError: |  | ||||||
|     connrefused_exc = socket.error |  | ||||||
| 
 |  | ||||||
| 
 | 
 | ||||||
| @pytest.fixture | @pytest.fixture | ||||||
| def run_servefile(): | def run_servefile(): | ||||||
|  | @ -125,18 +118,6 @@ def test_specify_port(run_servefile, datadir): | ||||||
|     check_download(data, fname='testfile', port=8081) |     check_download(data, fname='testfile', port=8081) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def test_ipv4_only(run_servefile, datadir): |  | ||||||
|     data = "NOOT NOOT" |  | ||||||
|     p = datadir({'testfile': data}) / 'testfile' |  | ||||||
|     run_servefile([str(p), '-4']) |  | ||||||
| 
 |  | ||||||
|     check_download(data, fname='testfile', host='127.0.0.1') |  | ||||||
| 
 |  | ||||||
|     sock = socket.socket(socket.AF_INET6) |  | ||||||
|     with pytest.raises(connrefused_exc): |  | ||||||
|         sock.connect(("::1", 8080)) |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| def test_big_download(run_servefile, datadir): | def test_big_download(run_servefile, datadir): | ||||||
|     # test with about 10 mb of data |     # test with about 10 mb of data | ||||||
|     data = "x" * (10 * 1024 ** 2) |     data = "x" * (10 * 1024 ** 2) | ||||||
|  | @ -186,33 +167,6 @@ def test_serve_directory(run_servefile, datadir): | ||||||
|     check_download('jup!', '/bar/thisisaverylongfilenamefortestingthatthisstillworksproperly') |     check_download('jup!', '/bar/thisisaverylongfilenamefortestingthatthisstillworksproperly') | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def test_serve_relative_directory(run_servefile, datadir): |  | ||||||
|     d = { |  | ||||||
|         'foo': {'kratzbaum': 'cat', 'I like Cats!': 'kitteh', '&&&&&&&': 'wheee'}, |  | ||||||
|         'bar': {'thisisaverylongfilenamefortestingthatthisstillworksproperly': 'jup!'}, |  | ||||||
|         'noot': 'still data in here', |  | ||||||
|         'bigfile': 'x' * (10 * 1024 ** 2), |  | ||||||
|     } |  | ||||||
|     p = datadir(d) |  | ||||||
|     run_servefile(['../', '-l'], cwd=os.path.join(str(p), 'foo')) |  | ||||||
| 
 |  | ||||||
|     # check if all files are in directory listing |  | ||||||
|     # (could be made more sophisticated with beautifulsoup) |  | ||||||
|     for path in '/', '/../': |  | ||||||
|         r = make_request(path) |  | ||||||
|         for k in d: |  | ||||||
|             assert k in r.text |  | ||||||
| 
 |  | ||||||
|     for fname, content in d['foo'].items(): |  | ||||||
|         check_download(content, '/foo/' + fname) |  | ||||||
| 
 |  | ||||||
|     r = make_request('/unknown') |  | ||||||
|     assert r.status_code == 404 |  | ||||||
| 
 |  | ||||||
|     # download |  | ||||||
|     check_download('jup!', '/bar/thisisaverylongfilenamefortestingthatthisstillworksproperly') |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| def test_upload(run_servefile, tmp_path): | def test_upload(run_servefile, tmp_path): | ||||||
|     data = ('this is my live now\n' |     data = ('this is my live now\n' | ||||||
|             'uploading strings to servers\n' |             'uploading strings to servers\n' | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue