1052 testutil_iostream_destroy(st); |
1052 testutil_iostream_destroy(st); |
1053 |
1053 |
1054 UCX_TEST_END; |
1054 UCX_TEST_END; |
1055 |
1055 |
1056 } |
1056 } |
|
1057 |
|
1058 /* ------------------------------------------------------------------------- |
|
1059 * |
|
1060 * PROPPATCH TESTS |
|
1061 * |
|
1062 * ------------------------------------------------------------------------ */ |
|
1063 |
|
1064 static int test_proppatch_init( |
|
1065 Session **out_sn, |
|
1066 Request **out_rq, |
|
1067 WebdavProppatchRequest **out_proppatch, |
|
1068 const char *xml) |
|
1069 { |
|
1070 if(!webdav_is_initialized) { |
|
1071 if(webdav_init(NULL, NULL, NULL) != REQ_PROCEED) { |
|
1072 return 1; |
|
1073 } |
|
1074 webdav_is_initialized = 1; |
|
1075 } |
|
1076 |
|
1077 Session *sn = testutil_session(); |
|
1078 Request *rq = testutil_request(sn->pool, "PROPPATCH", "/"); |
|
1079 |
|
1080 int error = 0; |
|
1081 |
|
1082 WebdavProppatchRequest *proppatch = proppatch_parse( |
|
1083 sn, |
|
1084 rq, |
|
1085 xml, |
|
1086 strlen(xml), |
|
1087 &error); |
|
1088 |
|
1089 if(error) { |
|
1090 return 1; |
|
1091 } |
|
1092 |
|
1093 if(!proppatch || !(proppatch->set || proppatch->remove)) { |
|
1094 return 1; |
|
1095 } |
|
1096 |
|
1097 *out_sn = sn; |
|
1098 *out_rq = rq; |
|
1099 *out_proppatch = proppatch; |
|
1100 return 0; |
|
1101 } |
|
1102 |
|
1103 static WebdavOperation* test_proppatch_op1( |
|
1104 Session **out_sn, |
|
1105 Request **out_rq, |
|
1106 const char *xml) |
|
1107 { |
|
1108 WebdavProppatchRequest *proppatch; |
|
1109 if(test_proppatch_init(out_sn, out_rq, &proppatch, xml)) { |
|
1110 return NULL; |
|
1111 } |
|
1112 |
|
1113 Multistatus *ms = multistatus_response(*out_sn, *out_rq); |
|
1114 if(!ms) { |
|
1115 return NULL; |
|
1116 } |
|
1117 // WebdavResponse is the public interface used by Backends |
|
1118 // for adding resources to the response |
|
1119 WebdavResponse *response = (WebdavResponse*)ms; |
|
1120 |
|
1121 return webdav_create_proppatch_operation( |
|
1122 (*out_sn), |
|
1123 (*out_rq), |
|
1124 &backend1, |
|
1125 proppatch, |
|
1126 response); |
|
1127 } |
|
1128 |
|
1129 |
|
1130 UCX_TEST(test_proppatch_msresponse) { |
|
1131 Session *sn; |
|
1132 Request *rq; |
|
1133 WebdavOperation *op; |
|
1134 |
|
1135 Multistatus *ms; |
|
1136 WebdavResource *res; |
|
1137 |
|
1138 WebdavProperty p[16]; |
|
1139 const char *names[] = {"a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9"}; |
|
1140 for(int i=0;i<8;i++) { |
|
1141 p[i].namespace = webdav_dav_namespace(); |
|
1142 p[i].name = names[i]; |
|
1143 p[i].lang = NULL; |
|
1144 p[i].value.node = NULL; |
|
1145 p[1].vtype = 0; |
|
1146 } |
|
1147 |
|
1148 UCX_TEST_BEGIN; |
|
1149 |
|
1150 op = test_proppatch_op1(&sn, &rq, TEST_PROPPATCH2); |
|
1151 UCX_TEST_ASSERT(op, "failed to create proppatch operation"); |
|
1152 |
|
1153 ms = (Multistatus*)op->response; |
|
1154 ms->proppatch = TRUE; |
|
1155 res = ms->response.addresource(&ms->response, "/"); |
|
1156 UCX_TEST_ASSERT(res, "cannot create resource 1"); |
|
1157 |
|
1158 UCX_TEST_ASSERT(!res->addproperty(res, &p[0], 200), "addproperty 1 failed"); |
|
1159 UCX_TEST_ASSERT(!res->addproperty(res, &p[1], 200), "addproperty 2 failed"); |
|
1160 UCX_TEST_ASSERT(!res->addproperty(res, &p[2], 200), "addproperty 3 failed"); |
|
1161 UCX_TEST_ASSERT(!res->addproperty(res, &p[3], 200), "addproperty 4 failed"); |
|
1162 |
|
1163 UCX_TEST_ASSERT(!res->close(res), "close failed"); |
|
1164 |
|
1165 MSResponse *msres = (MSResponse*)res; |
|
1166 UCX_TEST_ASSERT(!msres->errors, "error list not NULL"); |
|
1167 UCX_TEST_ASSERT(msres->plist_begin, "elm1 missing"); |
|
1168 UCX_TEST_ASSERT(msres->plist_begin->next, "elm2 missing"); |
|
1169 UCX_TEST_ASSERT(msres->plist_begin->next->next, "elm3 missing"); |
|
1170 UCX_TEST_ASSERT(msres->plist_begin->next->next->next, "elm4 missing"); |
|
1171 UCX_TEST_ASSERT(!msres->plist_begin->next->next->next->next, "count != 4"); |
|
1172 |
|
1173 UCX_TEST_END; |
|
1174 testutil_destroy_session(sn); |
|
1175 } |
|
1176 |
|
1177 UCX_TEST(test_msresponse_addproperty_with_errors) { |
|
1178 Session *sn; |
|
1179 Request *rq; |
|
1180 WebdavOperation *op; |
|
1181 |
|
1182 Multistatus *ms; |
|
1183 WebdavResource *res; |
|
1184 |
|
1185 WebdavProperty p[16]; |
|
1186 const char *names[] = {"a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9"}; |
|
1187 for(int i=0;i<8;i++) { |
|
1188 p[i].namespace = webdav_dav_namespace(); |
|
1189 p[i].name = names[i]; |
|
1190 p[i].lang = NULL; |
|
1191 p[i].value.node = NULL; |
|
1192 p[1].vtype = 0; |
|
1193 } |
|
1194 |
|
1195 UCX_TEST_BEGIN; |
|
1196 |
|
1197 op = test_proppatch_op1(&sn, &rq, TEST_PROPPATCH2); |
|
1198 UCX_TEST_ASSERT(op, "failed to create proppatch operation"); |
|
1199 |
|
1200 ms = (Multistatus*)op->response; |
|
1201 ms->proppatch = TRUE; |
|
1202 res = ms->response.addresource(&ms->response, "/"); |
|
1203 UCX_TEST_ASSERT(res, "cannot create resource 1"); |
|
1204 |
|
1205 UCX_TEST_ASSERT(!res->addproperty(res, &p[0], 200), "addproperty 1 failed"); |
|
1206 UCX_TEST_ASSERT(!res->addproperty(res, &p[1], 200), "addproperty 2 failed"); |
|
1207 UCX_TEST_ASSERT(!res->addproperty(res, &p[2], 409), "addproperty 3 failed"); |
|
1208 UCX_TEST_ASSERT(!res->addproperty(res, &p[3], 200), "addproperty 4 failed"); |
|
1209 |
|
1210 UCX_TEST_ASSERT(!res->close(res), "close failed"); |
|
1211 |
|
1212 // all properties should have an error status code now |
|
1213 // 1 x 409, 3 x 424 |
|
1214 |
|
1215 MSResponse *msres = (MSResponse*)res; |
|
1216 |
|
1217 UCX_TEST_ASSERT(!msres->plist_begin, "plist not NULL"); |
|
1218 UCX_TEST_ASSERT(msres->errors, "error list is NULL"); |
|
1219 UCX_TEST_ASSERT(msres->errors->next, "second error list is missing"); |
|
1220 UCX_TEST_ASSERT(!msres->errors->next->next, "wrong error list size"); |
|
1221 |
|
1222 // We know that we have 2 error lists, one with status code 409 and |
|
1223 // the other must have 409. However we don't enforce the order of the |
|
1224 // error lists, therefore check both variants |
|
1225 if(msres->errors->status == 409) { |
|
1226 UCX_TEST_ASSERT(msres->errors->next->status == 424, "wrong status code in second err elm"); |
|
1227 UCX_TEST_ASSERT(msres->errors->begin, "missing 409 property"); |
|
1228 UCX_TEST_ASSERT(msres->errors->next->begin, "missing 424 properties"); |
|
1229 } else { |
|
1230 UCX_TEST_ASSERT(msres->errors->next->status == 409, "wrong status code in second err elm"); |
|
1231 UCX_TEST_ASSERT(msres->errors->begin, "missing 424 properties"); |
|
1232 UCX_TEST_ASSERT(msres->errors->next->begin, "missing 409 property"); |
|
1233 } |
|
1234 |
|
1235 UCX_TEST_END; |
|
1236 testutil_destroy_session(sn); |
|
1237 } |