/* PUT conditional on bogus lock-token and valid etag, should fail. */ static int fail_cond_put_unlocked(void) { int klass, code; CALL(conditional_put("(<DAV:no-lock>)", &klass, &code)); ONV(klass == 2, ("conditional PUT with invalid lock-token should fail: %s", ne_get_error(i_session))); ONN("conditional PUT with invalid lock-token code got 400", code == 400); if (code != 412) t_warning("PUT failed with %d not 412", code); return OK; }
/* PUT conditional on real lock-token and not(bogus lock-token), * should succeed. */ static int cond_put_with_not(void) { int klass, code; char hdr[200]; PRECOND(gotlock); ne_snprintf(hdr, sizeof hdr, "(<%s>) (Not <DAV:no-lock>)", gotlock->token); CALL(conditional_put(hdr, &klass, &code)); ONV(klass != 2, ("PUT with conditional (Not <DAV:no-lock>) failed: %s", ne_get_error(i_session))); return OK; }
/* a PUT conditional on lock and etag should succeed */ static int cond_put(void) { char *etag = get_etag(res); char hdr[200]; int klass; PRECOND(etag && gotlock); ne_snprintf(hdr, sizeof hdr, "(<%s> [%s])", gotlock->token, etag); CALL(conditional_put(hdr, &klass, NULL)); ONV(klass != 2, ("PUT conditional on lock and etag failed: %s", ne_get_error(i_session))); return OK; }
/* PUT with a conditional (lock-token and etag) (Not bogus-token and etag) */ static int complex_cond_put(void) { int klass, code; char hdr[200]; char *etag = get_etag(res); PRECOND(gotlock && etag != NULL); ne_snprintf(hdr, sizeof hdr, "(<%s> [%s]) (Not <DAV:no-lock> [%s])", gotlock->token, etag, etag); CALL(conditional_put(hdr, &klass, &code)); ONV(klass != 2, ("PUT with complex conditional failed: %s", ne_get_error(i_session))); return OK; }
/* PUT with a conditional (bogus-etag) (Not etag) */ static int fail_complex_cond_put_etag(void) { int klass, code; char hdr[200]; char *etag = get_etag(res); PRECOND(etag); ne_snprintf(hdr, sizeof hdr, "([\"%s\"]) (Not [\"%s\"])", "fake-etag" , etag); CALL(conditional_put(hdr, &klass, &code)); ONV(code != 412, ("PUT with complex bogus conditional should fail with 412: %s", ne_get_error(i_session))); return OK; }
/* PUT with a conditional (etag not bogus-etag) (bogus-etag) */ static int complex_cond_put_etag(void) { int klass, code; char hdr[200]; char *etag = get_etag(res); PRECOND(etag); ne_snprintf(hdr, sizeof hdr, "([\"%s\"] not [\"%s\"]) ([\"%s\"])", etag, "fake-etag", "fake-etag"); CALL(conditional_put(hdr, &klass, &code)); ONV(klass != 2, ("PUT with complex conditional failed: %s", ne_get_error(i_session))); return OK; }
/* a PUT conditional etag should succeed */ static int cond_put_etag(void) { char *etag = get_etag(res); char hdr[200]; int klass; PRECOND(etag); ne_snprintf(hdr, sizeof hdr, "([\"%s\"])", etag); CALL(conditional_put(hdr, &klass, NULL)); ONV(klass != 2, ("PUT conditional on etag failed: %s", ne_get_error(i_session))); return OK; }
/* PUT with a conditional <res> (res-etag res2-etag) <res2> (bogus-etag) (Not etag) */ static int fail_complex_cond_multiple_resources_put_etag(void) { int klass, code; char hdr[275]; char *etag = get_etag(res); char *etag2 = get_etag(res2); PRECOND(etag && etag2); ne_snprintf(hdr, sizeof hdr, "<%s> ([\"%s\"] [\"%s\"]) <%s> ([\"%s\"]) ([\"%s\"])", res, etag, etag2, res2, etag, etag2); CALL(conditional_put(hdr, &klass, &code)); ONV(code != 412, ("PUT with complex bogus conditional should fail with 412: %s", ne_get_error(i_session))); return OK; }
/* PUT conditional on bogus lock-token and valid etag, should fail. */ static int fail_cond_put(void) { int klass, code; char *etag = get_etag(res); char hdr[200]; PRECOND(etag && gotlock); ne_snprintf(hdr, sizeof hdr, "(<DAV:no-lock> [%s])", etag); CALL(conditional_put(hdr, &klass, &code)); ONV(klass == 2, ("conditional PUT with invalid lock-token should fail: %s", ne_get_error(i_session))); ONN("conditional PUT with invalid lock-token code got 400", code == 400); if (code != 412) t_warning("PUT failed with %d not 412", code); return OK; }
/* PUT with a conditional (lock-token and not-the-etag) (Not * bogus-token and etag) */ static int fail_complex_cond_put(void) { int klass, code; char hdr[200]; char *etag = get_etag(res), *pnt; PRECOND(gotlock && etag != NULL); /* Corrupt the etag string: change the third character from the end. */ pnt = etag + strlen(etag) - 3; PRECOND(pnt > etag); (*pnt)++; ne_snprintf(hdr, sizeof hdr, "(<%s> [%s]) (Not <DAV:no-lock> [%s])", gotlock->token, etag, etag); CALL(conditional_put(hdr, &klass, &code)); ONV(code != 412, ("PUT with complex bogus conditional should fail with 412: %s", ne_get_error(i_session))); return OK; }
/* a PUT conditional with bogus etag should fail */ static int fail_cond_put_etag(void) { //Can probably use the same resources as the other methods if they are working char *myres = ne_concat(i_path, "lockme", NULL); CALL(upload_foo("lockme")); char *etag = get_etag(myres); char hdr[200]; int klass; int code; PRECOND(etag); ne_snprintf(hdr, sizeof hdr, "([\"fake-etag\"])"); CALL(conditional_put(hdr, &klass, &code)); ONV(code != 412, ("PUT with complex bogus conditional should fail with 412: %s", ne_get_error(i_session))); return OK; }