def setUp(self): # print "setUp" if EXTERNAL_SERVER_ADDRESS: # self.server_thread = None self.client = davclient.DAVClient(EXTERNAL_SERVER_ADDRESS) else: # self.server_thread = WsgiDAVServerThread() # self.server_thread.start() # # let server start the loop, otherwise shutdown might lock # time.sleep(.1) self.client = davclient.DAVClient("http://localhost:8080/") self.client.set_basic_auth("tester", "secret")
def testLocking(self): """Locking.""" client1 = self.client client2 = davclient.DAVClient(SERVER_ADDRESS, logger="DAVClient2") client2.set_basic_auth("tester2", "secret2") self._prepareTree0() # --- Check with deoth-infinity lock ---------------------------------- # LOCK-infinity parent collection and try to access members locks = client1.set_lock("/test/a", owner="test-bench", locktype="write", lockscope="exclusive", depth="infinity") client1.checkResponse(200) assert len(locks) == 1, "LOCK failed" token = locks[0] # Unlock with correct token, but other principal: expect '403 # Forbidden' client2.unlock("/test/a", token) client2.checkResponse(403) # Check that commonly protected operations fail self._checkCommonLock(client2) # Check operations that are only protected when /test/a is locked # with depth-infinity locks = client2.set_lock("/test/a/b/c", owner="test-bench", locktype="write", lockscope="exclusive", depth="0") client2.checkResponse(423) locks = client2.set_lock("/test/a/b/d", owner="test-bench", locktype="write", lockscope="exclusive", depth="infinity") client2.checkResponse(423) locks = client2.set_lock("/test/a/b/c", owner="test-bench", locktype="write", lockscope="exclusive", depth="0") client2.checkResponse(423) # client1 can LOCK /a and /a/b/d at the same time, but must # provide both tokens in order to access a/b/d # TODO: correct? # locks = client1.set_lock("/test/a/b/d", # owner="test-bench", # locktype="write", # lockscope="exclusive", # depth="0") # client1.checkResponse(200) # assert len(locks) == 1, "Locking inside below locked collection failed" # tokenABD = locks[0] # --- Check with depth-0 lock ----------------------------------------- # LOCK-0 parent collection and try to access members client1.unlock("/test/a", token) client1.checkResponse(204) locks = client1.set_lock("/test/a", owner="test-bench", locktype="write", lockscope="exclusive", depth="0") client1.checkResponse(200) assert len(locks) == 1, "LOCK failed" token = locks[0] # Check that commonly protected operations fail self._checkCommonLock(client2) # These operations are allowed with depth-0 # Modifying member properties is allowed client2.proppatch("/test/a/c", set_props=[("{testns:}testname", "testval")]) client2.checkMultiStatusResponse(200) # Modifying a member without creating a new resource is allowed client2.put("/test/a/c", b"data") client2.checkResponse(204) # Modifying non-internal member resources is allowed client2.put("/test/a/b/f", b"data") client2.checkResponse(201) client2.mkcol("/test/a/b/g") client2.checkResponse(201) client2.move("/test/a/b/g", "/test/a/b/g2") client2.checkResponse(201) client2.delete("/test/a/b/g2") client2.checkResponse(204) # --- Check root access, when a child is locked ----------------------- client1.unlock("/test/a", token) client1.checkResponse(204) locks = client1.set_lock("/test/a/b/d", owner="test-bench", locktype="write", lockscope="exclusive", depth="0") client1.checkResponse(200) assert len(locks) == 1, "LOCK failed" token = locks[0] # LOCK /a/b/d, then DELETE /a/b/ # --> Must delete all but a/b/d (expect 423 Locked inside Multistatus) client2.delete("/test/a/b") # print client2.response.body client2.checkMultiStatusResponse(423)
def setUp(self): self.client = davclient.DAVClient(SERVER_ADDRESS, logger=True) self.client.set_basic_auth("tester", "secret")
def _bench_script(opts): # print("Scriptes benchmarks") # print("_bench_script(), {}...".format(opts)) from tests import davclient server_url = opts.get("external_server") or "http://localhost:8080/" client = davclient.DAVClient(server_url) client.set_basic_auth("tester", "secret") # Prepare file content data_1k = b"." * 1000 # Prepare big file with 10 MB lines = [] line = "." * (1000 - 6 - len("\n")) for i in compat.xrange(10 * 1000): lines.append("%04i: %s\n" % (i, line)) data_10m = "".join(lines) data_10m = compat.to_bytes(data_10m) with Timing("Setup fixture"): _setup_fixture(opts, client) # PUT files with Timing("1000 x PUT 1 kB", 1000, "{:>6.1f} req/sec", 1, "{:>7,.3f} MB/sec"): for _ in compat.xrange(1000): client.put("/test/file1.txt", data_1k) client.check_response() with Timing("10 x PUT 10 MB", 10, "{:>6.1f} req/sec", 100, "{:>7,.3f} MB/sec"): for _ in compat.xrange(10): client.put("/test/bigfile.txt", data_10m) client.check_response() with Timing("1000 x GET 1 kB", 1000, "{:>6.1f} req/sec", 1, "{:>7,.3f} MB/sec"): for _ in compat.xrange(1000): body = client.get("/test/file1.txt") client.check_response() with Timing("10 x GET 10 MB", 10, "{:>6.1f} req/sec", 100, "{:>7,.3f} MB/sec"): for _ in compat.xrange(10): body = client.get("/test/bigfile.txt") # noqa F841 client.check_response() with Timing("10 x COPY 10 MB", 10, "{:>6.1f} req/sec", 100, "{:>7,.3f} MB/sec"): for _ in compat.xrange(10): client.copy( "/test/bigfile.txt", "/test/bigfile-copy.txt", depth="infinity", overwrite=True, ) client.check_response() with Timing("100 x MOVE 10 MB", 100, "{:>6.1f} req/sec"): name_from = "/test/bigfile-copy.txt" for i in compat.xrange(100): name_to = "/test/bigfile-copy-{}.txt".format(i) client.move(name_from, name_to, depth="infinity", overwrite=True) name_from = name_to client.check_response() with Timing("100 x LOCK/UNLOCK", 200, "{:>6.1f} req/sec"): for _ in compat.xrange(100): locks = client.set_lock( "/test/lock-0", owner="test-bench", locktype="write", lockscope="exclusive", depth="infinity", ) token = locks[0] client.unlock("/test/lock-0", token) client.check_response() with Timing("1000 x PROPPATCH", 1000, "{:>6.1f} req/sec"): for _ in compat.xrange(1000): client.proppatch( "/test/file1.txt", set_props=[("{testns:}testname", "testval")], remove_props=None, ) client.check_response() with Timing("500 x PROPFIND", 500, "{:>6.1f} req/sec"): for _ in compat.xrange(500): client.propfind("/", properties="allprop", namespace="DAV:", depth=None, headers=None) client.check_response()