mirror of
				https://github.com/9001/copyparty.git
				synced 2025-11-04 05:43:17 +00:00 
			
		
		
		
	quick upload test too
This commit is contained in:
		@@ -103,7 +103,7 @@ class TestHttpCli(unittest.TestCase):
 | 
				
			|||||||
                durl = furl.rsplit("/", 1)[0] if "/" in furl else ""
 | 
					                durl = furl.rsplit("/", 1)[0] if "/" in furl else ""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                # file download
 | 
					                # file download
 | 
				
			||||||
                ret = self.curl(furl)
 | 
					                h, ret = self.curl(furl)
 | 
				
			||||||
                res = "ok " + fp in ret
 | 
					                res = "ok " + fp in ret
 | 
				
			||||||
                print("[{}] {} {} = {}".format(fp, rok, wok, res))
 | 
					                print("[{}] {} {} = {}".format(fp, rok, wok, res))
 | 
				
			||||||
                if rok != res:
 | 
					                if rok != res:
 | 
				
			||||||
@@ -111,7 +111,7 @@ class TestHttpCli(unittest.TestCase):
 | 
				
			|||||||
                    self.fail()
 | 
					                    self.fail()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                # file browser: html
 | 
					                # file browser: html
 | 
				
			||||||
                ret = self.curl(durl)
 | 
					                h, ret = self.curl(durl)
 | 
				
			||||||
                res = "'{}'".format(self.fn) in ret
 | 
					                res = "'{}'".format(self.fn) in ret
 | 
				
			||||||
                print(res)
 | 
					                print(res)
 | 
				
			||||||
                if rok != res:
 | 
					                if rok != res:
 | 
				
			||||||
@@ -120,7 +120,7 @@ class TestHttpCli(unittest.TestCase):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                # file browser: json
 | 
					                # file browser: json
 | 
				
			||||||
                url = durl + "?ls"
 | 
					                url = durl + "?ls"
 | 
				
			||||||
                ret = self.curl(url)
 | 
					                h, ret = self.curl(url)
 | 
				
			||||||
                res = '"{}"'.format(self.fn) in ret
 | 
					                res = '"{}"'.format(self.fn) in ret
 | 
				
			||||||
                print(res)
 | 
					                print(res)
 | 
				
			||||||
                if rok != res:
 | 
					                if rok != res:
 | 
				
			||||||
@@ -142,9 +142,7 @@ class TestHttpCli(unittest.TestCase):
 | 
				
			|||||||
                tar_ng = [x[0] for x in tar if not x[1]]
 | 
					                tar_ng = [x[0] for x in tar if not x[1]]
 | 
				
			||||||
                self.assertEqual([], tar_ng)
 | 
					                self.assertEqual([], tar_ng)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                if durl.split("/")[-1] not in self.can_read:
 | 
					                if durl.split("/")[-1] in self.can_read:
 | 
				
			||||||
                    continue
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    ref = [x for x in vfiles if self.in_dive(top + "/" + durl, x)]
 | 
					                    ref = [x for x in vfiles if self.in_dive(top + "/" + durl, x)]
 | 
				
			||||||
                    for f in ref:
 | 
					                    for f in ref:
 | 
				
			||||||
                        print("{}: {}".format("ok" if f in tar_ok else "NG", f))
 | 
					                        print("{}: {}".format("ok" if f in tar_ok else "NG", f))
 | 
				
			||||||
@@ -152,6 +150,11 @@ class TestHttpCli(unittest.TestCase):
 | 
				
			|||||||
                    tar_ok.sort()
 | 
					                    tar_ok.sort()
 | 
				
			||||||
                    self.assertEqual(ref, tar_ok)
 | 
					                    self.assertEqual(ref, tar_ok)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                # stash
 | 
				
			||||||
 | 
					                h, ret = self.put(url)
 | 
				
			||||||
 | 
					                res = h.startswith("HTTP/1.1 200 ")
 | 
				
			||||||
 | 
					                self.assertEqual(res, wok)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def can_rw(self, fp):
 | 
					    def can_rw(self, fp):
 | 
				
			||||||
        # lowest non-neutral folder declares permissions
 | 
					        # lowest non-neutral folder declares permissions
 | 
				
			||||||
        expect = fp.split("/")[:-1]
 | 
					        expect = fp.split("/")[:-1]
 | 
				
			||||||
@@ -178,14 +181,21 @@ class TestHttpCli(unittest.TestCase):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        return True
 | 
					        return True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def put(self, url):
 | 
				
			||||||
 | 
					        buf = "PUT /{0} HTTP/1.1\r\nCookie: cppwd=o\r\nConnection: close\r\nContent-Length: {1}\r\n\r\nok {0}\n"
 | 
				
			||||||
 | 
					        buf = buf.format(url, len(url) + 4).encode("utf-8")
 | 
				
			||||||
 | 
					        conn = tu.VHttpConn(self.args, self.auth, self.log, buf)
 | 
				
			||||||
 | 
					        HttpCli(conn).run()
 | 
				
			||||||
 | 
					        return conn.s._reply.decode("utf-8").split("\r\n\r\n", 1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def curl(self, url, binary=False):
 | 
					    def curl(self, url, binary=False):
 | 
				
			||||||
        conn = tu.VHttpConn(self.args, self.auth, self.log, hdr(url))
 | 
					        conn = tu.VHttpConn(self.args, self.auth, self.log, hdr(url))
 | 
				
			||||||
        HttpCli(conn).run()
 | 
					        HttpCli(conn).run()
 | 
				
			||||||
        if binary:
 | 
					        if binary:
 | 
				
			||||||
            h, b = conn.s._reply.split(b"\r\n\r\n", 1)
 | 
					            h, b = conn.s._reply.split(b"\r\n\r\n", 1)
 | 
				
			||||||
            return h, b
 | 
					            return [h.decode("utf-8"), b]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return conn.s._reply.decode("utf-8")
 | 
					        return conn.s._reply.decode("utf-8").split("\r\n\r\n", 1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def log(self, src, msg, c=0):
 | 
					    def log(self, src, msg, c=0):
 | 
				
			||||||
        # print(repr(msg))
 | 
					        # print(repr(msg))
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -53,6 +53,11 @@ def get_ramdisk():
 | 
				
			|||||||
        return ret
 | 
					        return ret
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class NullBroker(object):
 | 
				
			||||||
 | 
					    def put(*args):
 | 
				
			||||||
 | 
					        pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class VSock(object):
 | 
					class VSock(object):
 | 
				
			||||||
    def __init__(self, buf):
 | 
					    def __init__(self, buf):
 | 
				
			||||||
        self._query = buf
 | 
					        self._query = buf
 | 
				
			||||||
@@ -71,6 +76,8 @@ class VSock(object):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
class VHttpSrv(object):
 | 
					class VHttpSrv(object):
 | 
				
			||||||
    def __init__(self):
 | 
					    def __init__(self):
 | 
				
			||||||
 | 
					        self.broker = NullBroker()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        aliases = ["splash", "browser", "browser2", "msg", "md", "mde"]
 | 
					        aliases = ["splash", "browser", "browser2", "msg", "md", "mde"]
 | 
				
			||||||
        self.j2 = {x: J2_FILES for x in aliases}
 | 
					        self.j2 = {x: J2_FILES for x in aliases}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -86,5 +93,5 @@ class VHttpConn(object):
 | 
				
			|||||||
        self.log_src = "a"
 | 
					        self.log_src = "a"
 | 
				
			||||||
        self.hsrv = VHttpSrv()
 | 
					        self.hsrv = VHttpSrv()
 | 
				
			||||||
        self.nbyte = 0
 | 
					        self.nbyte = 0
 | 
				
			||||||
 | 
					        self.workload = 0
 | 
				
			||||||
        self.t0 = time.time()
 | 
					        self.t0 = time.time()
 | 
				
			||||||
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user