(self, file_server, site)
| 12 | @pytest.mark.usefixtures("resetTempSettings") |
| 13 | class TestFileRequest: |
| 14 | def testGetFile(self, file_server, site): |
| 15 | file_server.ip_incoming = {} # Reset flood protection |
| 16 | client = ConnectionServer(file_server.ip, 1545) |
| 17 | |
| 18 | connection = client.getConnection(file_server.ip, 1544) |
| 19 | file_server.sites[site.address] = site |
| 20 | |
| 21 | # Normal request |
| 22 | response = connection.request("getFile", {"site": site.address, "inner_path": "content.json", "location": 0}) |
| 23 | assert b"sign" in response["body"] |
| 24 | |
| 25 | response = connection.request("getFile", {"site": site.address, "inner_path": "content.json", "location": 0, "file_size": site.storage.getSize("content.json")}) |
| 26 | assert b"sign" in response["body"] |
| 27 | |
| 28 | # Invalid file |
| 29 | response = connection.request("getFile", {"site": site.address, "inner_path": "invalid.file", "location": 0}) |
| 30 | assert "File read error" in response["error"] |
| 31 | |
| 32 | # Location over size |
| 33 | response = connection.request("getFile", {"site": site.address, "inner_path": "content.json", "location": 1024 * 1024}) |
| 34 | assert "File read error" in response["error"] |
| 35 | |
| 36 | # Stream from parent dir |
| 37 | response = connection.request("getFile", {"site": site.address, "inner_path": "../users.json", "location": 0}) |
| 38 | assert "File read exception" in response["error"] |
| 39 | |
| 40 | # Invalid site |
| 41 | response = connection.request("getFile", {"site": "", "inner_path": "users.json", "location": 0}) |
| 42 | assert "Unknown site" in response["error"] |
| 43 | |
| 44 | response = connection.request("getFile", {"site": ".", "inner_path": "users.json", "location": 0}) |
| 45 | assert "Unknown site" in response["error"] |
| 46 | |
| 47 | # Invalid size |
| 48 | response = connection.request("getFile", {"site": site.address, "inner_path": "content.json", "location": 0, "file_size": 1234}) |
| 49 | assert "File size does not match" in response["error"] |
| 50 | |
| 51 | # Invalid path |
| 52 | for path in ["../users.json", "./../users.json", "data/../content.json", ".../users.json"]: |
| 53 | for sep in ["/", "\\"]: |
| 54 | response = connection.request("getFile", {"site": site.address, "inner_path": path.replace("/", sep), "location": 0}) |
| 55 | assert response["error"] == 'File read exception' |
| 56 | |
| 57 | connection.close() |
| 58 | client.stop() |
| 59 | |
| 60 | def testStreamFile(self, file_server, site): |
| 61 | file_server.ip_incoming = {} # Reset flood protection |
nothing calls this directly
no test coverage detected