static int copy_overwrite(void) { PRECOND(copy_ok); /* Do it again with Overwrite: F to check that fails. */ ONN("COPY on existing resource with Overwrite: F should fail (RFC2518:S8.8.4)", ne_copy(i_session, 0, NE_DEPTH_INFINITE, src, dest) != NE_ERROR); if (STATUS(412)) { t_warning("COPY-on-existing fails with 412"); } ONV(ne_copy(i_session, 1, NE_DEPTH_INFINITE, src, dest), ("COPY-on-existing with 'Overwrite: T' should succeed (RFC2518:S8.8.4): %s", ne_get_error(i_session))); /* tricky one this, I didn't think it should work, but the spec * makes it look like it should. */ ONV(ne_copy(i_session, 1, NE_DEPTH_INFINITE, src, coll), ("COPY overwrites collection: %s", ne_get_error(i_session))); if (STATUS(204)) { t_warning("COPY to existing resource didn't give 204 (RFC2518:S8.8.5)"); } return OK; }
static int lock_collection(void) { struct ne_lock dummy; char *tmp,*tmp2; CALL(getlock(ne_lockscope_exclusive, NE_DEPTH_INFINITE)); PRECOND(gotlock); memcpy(&dummy, &reslock, sizeof(reslock)); dummy.token = NULL; dummy.uri.path = collZ; dummy.owner = ne_strdup("litmus: owner lock"); dummy.depth = NE_DEPTH_INFINITE; dummy.type = ne_locktype_write; dummy.scope = ne_lockscope_exclusive; ONNREQ2("LOCK on second collection for further tests", ne_lock(i_session, &dummy)); gotlock = ne_lock_copy(&dummy); ne_lockstore_add(store, gotlock); /* Testing creation of directories under a collection */ ONV(ne_mkcol(i_session, collX), ("MKCOL %s: %s", collX, ne_get_error(i_session))); ONV(ne_mkcol(i_session, collY), ("MKCOL %s: %s", collY, ne_get_error(i_session))); upload_foo("lockcoll/collX/temp"); tmp = ne_concat(collY,"copy-temp",NULL); ONV(ne_copy(i_session, 0, NE_DEPTH_INFINITE, res3,tmp), ("collection COPY `%s' to `%s': %s", res2, tmp, ne_get_error(i_session))); free(tmp); tmp2=ne_concat(collZ,"testing",NULL); ONV(ne_copy(i_session, 0, NE_DEPTH_INFINITE, res3,tmp2), ("collection COPY `%s' to `%s': %s", res2, tmp2, ne_get_error(i_session))); ne_free(res3); res3 = ne_concat(i_path,"not-existing",NULL); /* change res to point to a normal resource for subsequent * {not_,}owner_modify tests */ res = ne_concat(coll, "lockme.txt", NULL); return upload_foo("lockcoll/lockme.txt"); }
/* check that locks don't follow copies. */ static int copy(void) { char *dest; int count = 0; PRECOND(gotlock); dest = ne_concat(res, "-copydest", NULL); ne_delete(i_session2, dest); ONNREQ2("could not COPY locked resource", ne_copy(i_session2, 1, NE_DEPTH_ZERO, res, dest)); ONNREQ2("LOCK discovery failed", ne_lock_discover(i_session2, dest, count_discover, &count)); ONV(count != 0, ("found %d locks on copied resource", count)); ONNREQ2("could not delete copy of locked resource", ne_delete(i_session2, dest)); free(dest); return OK; }
static int owner_modify(void) { char *tmp; ne_propname pname = { "http://webdav.org/neon/litmus/", "random" }; ne_proppatch_operation pops[] = { { NULL, ne_propset, "foobar" }, { NULL } }; PRECOND(gotlock); ONV(ne_put(i_session, res, i_foo_fd), ("PUT on locked resource failed: %s", ne_get_error(i_session))); tmp = ne_concat(i_path, "whocares", NULL); ONN("COPY of locked resource", ne_copy(i_session, 1, NE_DEPTH_ZERO, res, tmp) == NE_ERROR); if (STATUS(201)) t_warning("COPY failed with %d not 201", GETSTATUS); ONN("DELETE of locked resource by owner", ne_delete(i_session, tmp) == NE_ERROR); if (STATUS(204)) t_warning("DELETE of %s failed with %d not 200", tmp, GETSTATUS); free(tmp); ONN("PROPPATCH of locked resource", ne_proppatch(i_session, res, pops) == NE_ERROR); if (STATUS(207)) t_warning("PROPPATCH failed with %d", GETSTATUS); return OK; }
static int copy_simple(void) { PRECOND(copy_ok); /* Now copy it once */ ONNREQ("simple resource COPY", ne_copy(i_session, 0, NE_DEPTH_INFINITE, src, dest)); if (STATUS(201)) { t_warning("COPY to new resource should give 201 (RFC2518:S8.8.5)"); } return OK; }
static int notowner_modify(void) { char *tmp; ne_propname pname = { "http://webdav.org/neon/litmus/", "random" }; ne_proppatch_operation pops[] = { { NULL, ne_propset, "foobar" }, { NULL } }; PRECOND(gotlock); pops[0].name = &pname; ONN("DELETE of locked resource should fail", ne_delete(i_session2, res) != NE_ERROR); if (STATUS2(423)) t_warning("DELETE failed with %d not 423", GETSTATUS2); tmp = ne_concat(i_path, "whocares", NULL); ONN("MOVE of locked resource should fail", ne_move(i_session2, 0, res, tmp) != NE_ERROR); free(tmp); if (STATUS2(423)) t_warning("MOVE failed with %d not 423", GETSTATUS2); ONN("COPY onto locked resource should fail", ne_copy(i_session2, 1, NE_DEPTH_ZERO, res2, res) != NE_ERROR); if (STATUS2(423)) t_warning("COPY failed with %d not 423", GETSTATUS2); ONN("PROPPATCH of locked resource should fail", ne_proppatch(i_session2, res, pops) != NE_ERROR); if (STATUS2(423)) t_warning("PROPPATCH failed with %d not 423", GETSTATUS2); ONN("PUT on locked resource should fail", ne_put(i_session2, res, i_foo_fd) != NE_ERROR); if (STATUS2(423)) t_warning("PUT failed with %d not 423", GETSTATUS2); return OK; }
static int copy_nodestcoll(void) { char *nodest = ne_concat(i_path, "nonesuch/foo", NULL); int ret; PRECOND(copy_ok); ret = ne_copy(i_session, 0, NE_DEPTH_ZERO, src, nodest); ONV(ret == NE_OK, ("COPY into non-existant collection '%snonesuch' succeeded", i_path)); if (STATUS(409)) { t_warning("COPY to non-existant collection '%snonesuch' gave '%s' not 409" " (RFC2518:S8.8.5)", i_path, ne_get_error(i_session)); } ne_free(nodest); return OK; }
static int copy_shallow(void) { char *csrc, *cdest, *res; csrc = ne_concat(i_path, "ccsrc/", NULL); cdest = ne_concat(i_path, "ccdest/", NULL); /* Set up the ccsrc collection with one member */ ONMREQ("MKCOL", csrc, ne_mkcol(i_session, csrc)); CALL(upload_foo("ccsrc/foo")); /* Clean up to make some fresh copies. */ ne_delete(i_session, cdest); /* Now copy with Depth 0 */ ONV(ne_copy(i_session, 0, NE_DEPTH_ZERO, csrc, cdest), ("collection COPY `%s' to `%s': %s", csrc, cdest, ne_get_error(i_session))); /* Remove the source, to be paranoid. */ if (ne_delete(i_session, csrc)) { t_warning("Could not delete csrc"); } /* Now make sure the child resource hasn't been copied along with * the collection. */ res = ne_concat(i_path, "foo", NULL); ne_delete(i_session, res); ONV(STATUS(404), ("DELETE on `%s' should fail with 404: got %d", res, GETSTATUS)); ne_free(res); if (ne_delete(i_session, cdest)) { t_warning("Could not clean up cdest"); } return OK; }
static int move_coll(void) { int n; char *rsrc, *rdest, *subsrc, *subdest; char res[512]; msrc = ne_concat(i_path, "mvsrc/", NULL); mdest = ne_concat(i_path, "mvdest/", NULL); mdest2 = ne_concat(i_path, "mvdest2/", NULL); rsrc = ne_concat(i_path, "mvsrc/foo", NULL); rdest = ne_concat(i_path, "mvdest/foo", NULL); subsrc = ne_concat(i_path, "mvsrc/subcoll/", NULL); subdest = ne_concat(i_path, "mvdest/subcoll/", NULL); mnoncoll = ne_concat(i_path, "mvnoncoll", NULL); /* Set up the mvsrc collection. */ ONMREQ("MKCOL", msrc, ne_mkcol(i_session, msrc)); for (n = 0; n < 10; n++) { sprintf(res, "mvsrc/foo.%d", n); CALL(upload_foo(res)); } CALL(upload_foo("mvnoncoll")); ONV(ne_mkcol(i_session, subsrc), ("MKCOL of `%s' failed: %s\n", subsrc, SERR)); /* Now make a copy of the collection */ ONV(ne_copy(i_session, 0, NE_DEPTH_INFINITE, msrc, mdest2), ("collection COPY `%s' to `%s', depth infinity: %s", msrc, mdest2, SERR)); ONV(ne_move(i_session, 0, msrc, mdest), ("collection MOVE `%s' to `%s': %s", msrc, mdest, SERR)); ONN("MOVE-on-existing-coll should fail", ne_move(i_session, 0, mdest, mdest2) != NE_ERROR); ONN("MOVE-on-existing-coll with overwrite", ne_move(i_session, 1, mdest2, mdest)); /* Take another copy. */ ONV(ne_copy(i_session, 0, NE_DEPTH_INFINITE, mdest, mdest2), ("collection COPY `%s' to `%s', depth infinity: %s", mdest, mdest2, ne_get_error(i_session))); /* Now delete things out of the destination collection to check if * they are there. */ for (n = 0; n < 10; n++) { sprintf(res, "%s%s.%d", i_path, "mvdest/foo", n); ONV(ne_delete(i_session, res), ("DELETE from copied collection failed for `%s': %s", res, SERR)); } ONV(ne_delete(i_session, subdest), ("DELETE from copied collection failed for `%s': %s", subdest, SERR)); /* And move the spare collection over a non-coll. */ ONV(ne_move(i_session, 1, mdest2, mnoncoll), ("MOVE collection `%s' over non-collection `%s' with overwrite: %s", mdest2, mnoncoll, ne_get_error(i_session))); return OK; }
static int copy_coll(void) { int n; char *csrc, *cdest, *rsrc, *rdest, *subsrc, *subdest, *cdest2; char res[512]; csrc = ne_concat(i_path, "ccsrc/", NULL); cdest = ne_concat(i_path, "ccdest/", NULL); cdest2 = ne_concat(i_path, "ccdest2/", NULL); rsrc = ne_concat(i_path, "ccsrc/foo", NULL); rdest = ne_concat(i_path, "ccdest/foo", NULL); subsrc = ne_concat(i_path, "ccsrc/subcoll/", NULL); subdest = ne_concat(i_path, "ccdest/subcoll/", NULL); /* Set up the ccsrc collection. */ ONMREQ("MKCOL", csrc, ne_mkcol(i_session, csrc)); for (n = 0; n < 10; n++) { sprintf(res, "ccsrc/foo.%d", n); CALL(upload_foo(res)); } ONMREQ("MKCOL", subsrc, ne_mkcol(i_session, subsrc)); /* Clean up to make some fresh copies. */ ne_delete(i_session, cdest); ne_delete(i_session, cdest2); /* Now copy the collection a couple of times */ ONV(ne_copy(i_session, 0, NE_DEPTH_INFINITE, csrc, cdest), ("collection COPY `%s' to `%s': %s", csrc, cdest, ne_get_error(i_session))); ONV(ne_copy(i_session, 0, NE_DEPTH_INFINITE, csrc, cdest2), ("collection COPY `%s' to `%s': %s", csrc, cdest, ne_get_error(i_session))); ONN("COPY-on-existing-coll should fail", ne_copy(i_session, 0, NE_DEPTH_INFINITE, cdest, cdest2) != NE_ERROR); ONV(ne_copy(i_session, 1, NE_DEPTH_INFINITE, cdest2, cdest), ("COPY-on-existing-coll with overwrite: %s", ne_get_error(i_session))); /* Remove the source, to be paranoid. */ if (ne_delete(i_session, csrc)) { t_warning("Could not delete csrc"); } /* Now delete things out of the destination collection to check if * they are there. */ for (n = 0; n < 10; n++) { sprintf(res, "%s%s.%d", i_path, "ccdest/foo", n); ONV(ne_delete(i_session, res), ("COPY destination coll missing %s? %s", res, ne_get_error(i_session))); } ONV(ne_delete(i_session, subdest), ("COPY destination missing sub-coll %s? %s", subdest, ne_get_error(i_session))); /* Now nuke the whole of the second copy. */ ONV(ne_delete(i_session, cdest2), ("COPY destination %s missing? %s", cdest2, ne_get_error(i_session))); if (ne_delete(i_session, cdest)) { t_warning("Could not clean up cdest"); } return OK; }
static int lock_on_no_file(void) { char *tmp; res = ne_concat(i_path, "locknullfile", NULL); tmp = ne_concat(i_path, "whocares", NULL); getlock(ne_lockscope_exclusive, NE_DEPTH_ZERO); if (STATUS(200)) t_warning("Lock Null failed with %d not 200", GETSTATUS); //FIXME: After Lock Null is created, Do Unlock it to maintain integrity of tests //ONNREQ2("unlock of second shared lock",ne_unlock(i_session, &gotlock)); // Copy of nulllock resource ONN("COPY null locked resource should ", ne_copy(i_session, 1, NE_DEPTH_ZERO, res, tmp) == NE_ERROR); // Delete of nulllockresource ONN("DELETE of locknull resource by owner", ne_delete(i_session, tmp) == NE_ERROR); free(tmp); // Move of nulllockresource tmp = ne_concat(i_path, "who-cares", NULL); ONN("MOVE of null-locked resource", ne_move(i_session, 0, res, tmp) == NE_ERROR); ONN("DELETE of locknull resource by owner after a MOVE with overwrite (F)", ne_delete(i_session, tmp) == NE_ERROR); /* Delete the locktoken from store */ ne_lockstore_remove(store, gotlock); getlock(ne_lockscope_exclusive, NE_DEPTH_ZERO); if (STATUS(200)) t_warning("Lock Null failed with %d not 200", GETSTATUS); /* Lot of code duplication, but want to test each case individually. * Locknull resource. How it behaves when it is copied * moved (with overwrite T/F) * PUT request on locknullresource should succeed. */ /*MOVE of null-locked resource with overwrite=T */ ONN("MOVE of null-locked resource with overwrite=T (1)", ne_move(i_session, 1, res, tmp) == NE_ERROR); ne_lockstore_remove(store, gotlock); getlock(ne_lockscope_exclusive, NE_DEPTH_ZERO); if (STATUS(200)) t_warning("Lock Null failed with %d not 200", GETSTATUS); ONN("MOVE of null-locked resource with overwrite=T (2)", ne_move(i_session, 1, res, tmp) == NE_ERROR); ne_lockstore_remove(store, gotlock); getlock(ne_lockscope_shared, NE_DEPTH_ZERO); if (STATUS(200)) t_warning("Lock Null failed with %d not 200", GETSTATUS); ONN("COPY on null-locked resource with overwrite=T", ne_copy(i_session, 1, NE_DEPTH_ZERO, tmp, res) == NE_ERROR); ONN("DELETE of locknull resource by owner after a MOVE (T) ", ne_delete(i_session, tmp) == NE_ERROR); free(tmp); // Put on nulllockresource ONV(ne_put(i_session,res, i_foo_fd), ("PUT on locknullfile resource failed: %s", ne_get_error(i_session))); return OK; }