Roxen.git / server / etc / test / modules / TEST.pmod / http.pmod / WebDAV.pmod / TestBase.pike

version» Context lines:

Roxen.git/server/etc/test/modules/TEST.pmod/http.pmod/WebDAV.pmod/TestBase.pike:117:    if (lower_case(method) == "copy") {    // NB: No need to lock the source for a copy operation.    lock_paths = ({ new_uri });    } else {    lock_paths += ({ new_uri });    }       if (has_prefix(new_uri, "/")) {    new_uri = new_uri[1..];    } +  new_uri = map((new_uri/"/"), Protocols.HTTP.percent_encode) * "/";    Standards.URI dest_uri = Standards.URI(new_uri, base_uri); -  +  dest_uri->password = dest_uri->password = "";    headers["destination"] = (string)dest_uri;    }       multiset(string) locks = (<>);    if (current_locks) {    foreach(lock_paths, string dir) {    while(1) {    string lock = current_locks[dir];    if (lock) {    locks[lock] = 1;    }    if (dir == "/") {    break;    }    dir = dirname(dir);    }    } -  +  if ((lower_case(method) == "move") || +  (lower_case(method) == "copy") || +  (lower_case(method) == "delete")) { +  foreach(indices(current_locks), string path) { +  foreach(lock_paths, string dir) { +  if (has_prefix(path, dir + "/")) { +  locks[current_locks[path]] = 1; +  } +  } +  } +  }    if (sizeof(locks)) {    headers->if = "(<" + (indices(locks) * ">), (<") + ">)";    }    }    if (has_prefix(path, "/")) {    path = path[1..];    }       path = map((path/"/"), Protocols.HTTP.percent_encode) * "/";    Standards.URI url = Standards.URI(path, base_uri);
Roxen.git/server/etc/test/modules/TEST.pmod/http.pmod/WebDAV.pmod/TestBase.pike:418:    webdav_mp += "/";    }    return array_sscanf(href, "%*s"+webdav_mp+"%s");    }));    // Remove leading "/"    array(string) expected_ = map(expected,    lambda(string path) { return has_prefix(path, "/") ? path[1..] : path; });    // Remove empty strings if any.    actual = filter(actual, lambda(string str) { return sizeof(str) > 0; });    expected_ = filter(expected_, lambda(string str) { return sizeof(str) > 0; }); +  expected_ = map(expected_, Unicode.normalize, "NFC");    if (new_style) {    ASSERT_EQUAL(sort(expected_), sort(actual));    return res;    }    TEST_EQUAL(sort(expected_), sort(actual));    return equal(sort(expected_), sort(actual));   }      protected WebDAVResponse webdav_ls(string path,    array(string) expected,
Roxen.git/server/etc/test/modules/TEST.pmod/http.pmod/WebDAV.pmod/TestBase.pike:1150:    A,    Stdio.append_path(A, "X"),    Stdio.append_path(A, "X", "Y"),    });    array(string) files =    ({    Stdio.append_path(A, "file.txt"),    Stdio.append_path(A, "X", "x_file.txt"),    Stdio.append_path(A, "X", "Y", "y_file.txt"),    }); -  webdav_mkcol(directories[0], STATUS_CREATED); -  webdav_mkcol(directories[1], STATUS_CREATED); +  foreach(directories, string dir) { +  webdav_mkcol(dir, STATUS_CREATED); +  }    foreach (files, string file) {    webdav_put(file, "Some content", STATUS_CREATED);    }    string B = Stdio.append_path(this::testcase_dir, "B");    WebDAVResponse res =    webdav_request("COPY", A,    ([ "new-uri": B ]) + ( depth ? ([ "Depth" : depth ]) : ([]) )    );    ASSERT_EQUAL(res->status, STATUS_CREATED);    array(string) expected;
Roxen.git/server/etc/test/modules/TEST.pmod/http.pmod/WebDAV.pmod/TestBase.pike:1244:   private void do_test_copy_dir_to_existing_dir(string method,    string|void overwrite)   {    ASSERT_TRUE(method == "COPY" || method == "MOVE");    ASSERT_TRUE(!overwrite || overwrite == "T");    mapping(string:string) headers = ([]);    if (overwrite) {    headers = ([ "Overwrite" : overwrite ]);    }    // Copy dir to dir -  string dir1 = Stdio.append_path(testcase_dir, "dir1"); +  string dir = Stdio.append_path(testcase_dir, +  sprintf("%s_dir_to_dir", lower_case(method))); +  string dir1 = Stdio.append_path(dir, "dir1");    string file1 = Stdio.append_path(dir1, "file1.txt"); -  string dir2 = Stdio.append_path(testcase_dir, "dir2"); +  string dir2 = Stdio.append_path(dir, "dir2");    string file2 = Stdio.append_path(dir2, "file2.txt"); -  +  webdav_mkcol(dir, STATUS_CREATED);    webdav_mkcol(dir1, STATUS_CREATED);    webdav_mkcol(dir2, STATUS_CREATED);    webdav_put(file1, "Content 1", STATUS_CREATED);    webdav_put(file2, "Content 2", STATUS_CREATED);    mapping(string:string) locks = ([]);    webdav_lock(dir2, locks, STATUS_OK);    WebDAVResponse res = webdav_request(method, dir1,    ([ "new-uri": dir2 ]) + headers);    ASSERT_EQUAL(res->status, STATUS_LOCKED);    verify_lock_token(res);    current_locks = locks;    res = webdav_request(method, dir1,    ([ "new-uri": dir2 ]) + headers);    ASSERT_EQUAL(res->status, STATUS_NO_CONTENT);    if (method == "COPY") { -  webdav_ls(testcase_dir, -  ({ testcase_dir, +  webdav_ls(dir, +  ({ dir,    dir1,    file1,    dir2,    Stdio.append_path(dir2, "file1.txt") }));    } else { // method == "MOVE" -  webdav_ls(testcase_dir, -  ({ testcase_dir, +  webdav_ls(dir, +  ({ dir,    dir2,    Stdio.append_path(dir2, "file1.txt") }));    }   }      private void do_test_copy_file_to_existing_file(string method,    string|void overwrite)   {    ASSERT_TRUE(method == "COPY" || method == "MOVE");    ASSERT_TRUE(!overwrite || overwrite == "T");    mapping(string:string) headers = ([]);    if (overwrite) {    headers = ([ "Overwrite" : overwrite ]);    }    // Copy file to file -  string file1 = Stdio.append_path(testcase_dir, "file1.txt"); -  string file2 = Stdio.append_path(testcase_dir, "file2.txt"); +  string dir = Stdio.append_path(testcase_dir, +  sprintf("%s_file_to_file", lower_case(method))); +  string file1 = Stdio.append_path(dir, "file1.txt"); +  string file2 = Stdio.append_path(dir, "file2.txt"); +  webdav_mkcol(dir, STATUS_CREATED);    webdav_put(file1, "Content 1", STATUS_CREATED);    webdav_put(file2, "Content 2", STATUS_CREATED);    mapping(string:string) locks = ([]);    webdav_lock(file2, locks, STATUS_OK);    WebDAVResponse res = webdav_request(method, file1,    ([ "new-uri": file2 ]) + headers);    ASSERT_EQUAL(res->status, STATUS_LOCKED);    verify_lock_token(res);    current_locks = locks;    res = ASSERT_CALL(webdav_request, method, file1,    ([ "new-uri": file2 ]) + headers);    ASSERT_EQUAL(res->status, STATUS_NO_CONTENT);    ASSERT_TRUE(filesystem_compare_files, file1, file2);    ASSERT_TRUE(filesystem_check_content, file2, "Content 1");    if (method == "COPY") { -  webdav_ls(testcase_dir, -  ({ testcase_dir, +  webdav_ls(dir, +  ({ dir,    file1,    file2 }));    } else { // method == "MOVE" -  webdav_ls(testcase_dir, -  ({ testcase_dir, +  webdav_ls(dir, +  ({ dir,    file2 }));    }   }      private void do_test_copy_file_to_existing_dir(string method,    string|void overwrite)   {    ASSERT_TRUE(method == "COPY" || method == "MOVE");    ASSERT_TRUE(!overwrite || overwrite == "T");    mapping(string:string) headers = ([]);    if (overwrite) {    headers = ([ "Overwrite" : overwrite ]);    }    // Copy file to dir -  string dir = Stdio.append_path(testcase_dir, "mydir"); -  string file = Stdio.append_path(testcase_dir, "myfile.txt"); +  string dir = Stdio.append_path(testcase_dir, +  sprintf("%s_file_to_dir", lower_case(method))); +  string mydir = Stdio.append_path(dir, "mydir"); +  string file = Stdio.append_path(dir, "myfile.txt");    webdav_mkcol(dir, STATUS_CREATED); -  ASSERT_CALL_TRUE(filesystem_is_dir, dir); -  ASSERT_CALL_FALSE(filesystem_is_file, dir); +  webdav_mkcol(mydir, STATUS_CREATED); +  ASSERT_CALL_TRUE(filesystem_is_dir, mydir); +  ASSERT_CALL_FALSE(filesystem_is_file, mydir);    webdav_put(file, "My content", STATUS_CREATED);    mapping(string:string) locks = ([]); -  webdav_lock(dir, locks, STATUS_OK); +  webdav_lock(mydir, locks, STATUS_OK);    WebDAVResponse res = webdav_request(method, file, -  ([ "new-uri": dir ]) + headers); +  ([ "new-uri": mydir ]) + headers);    ASSERT_EQUAL(res->status, STATUS_LOCKED);    verify_lock_token(res);    current_locks = locks;    res = webdav_request(method, file, -  ([ "new-uri": dir ]) + headers); +  ([ "new-uri": mydir ]) + headers);    ASSERT_EQUAL(res->status, STATUS_NO_CONTENT); -  ASSERT_CALL_TRUE(filesystem_is_file, dir); -  ASSERT_CALL_FALSE(filesystem_is_dir, dir); -  ASSERT_CALL_TRUE(filesystem_check_content, dir, "My content"); +  ASSERT_CALL_TRUE(filesystem_is_file, mydir); +  ASSERT_CALL_FALSE(filesystem_is_dir, mydir); +  ASSERT_CALL_TRUE(filesystem_check_content, mydir, "My content");    if (method == "COPY") { -  webdav_ls(testcase_dir, -  ({ testcase_dir, -  dir, +  webdav_ls(dir, +  ({ dir, +  mydir,    file }));    } else { // method == "MOVE" -  webdav_ls(testcase_dir, -  ({ testcase_dir, -  dir })); +  webdav_ls(dir, +  ({ dir, +  mydir }));    }   }      private void do_test_copy_dir_to_existing_file(string method,    string|void overwrite)   {    ASSERT_TRUE(method == "COPY" || method == "MOVE");    ASSERT_TRUE(!overwrite || overwrite == "T");    mapping(string:string) headers = ([]);    if (overwrite) {    headers = ([ "Overwrite" : overwrite ]);    }    // Copy dir to file -  string dir = Stdio.append_path(testcase_dir, "mydir"); -  string file = Stdio.append_path(testcase_dir, "myfile.txt"); +  string dir = Stdio.append_path(testcase_dir, +  sprintf("%s_dir_to_file", lower_case(method))); +  string mydir = Stdio.append_path(dir, "mydir"); +  string file = Stdio.append_path(dir, "myfile.txt");    webdav_mkcol(dir, STATUS_CREATED); -  +  webdav_mkcol(mydir, STATUS_CREATED); +  webdav_put(file, "My content", STATUS_CREATED);    ASSERT_CALL_TRUE(filesystem_is_file, file);    ASSERT_CALL_FALSE(filesystem_is_dir, file); -  webdav_put(file, "My content", STATUS_CREATED); +     mapping(string:string) locks = ([]); -  ASSERT_CALL(webdav_lock, file, locks); -  WebDAVResponse res = webdav_request(method, dir, +  ASSERT_CALL(webdav_lock, file, locks, STATUS_OK); +  WebDAVResponse res = webdav_request(method, mydir,    ([ "new-uri": file ]) + headers);    ASSERT_EQUAL(res->status, STATUS_LOCKED);    verify_lock_token(res); -  current_locks = locks; -  res = webdav_request(method, dir, +  current_locks = locks + ([]); +  res = webdav_request(method, mydir,    ([ "new-uri": file ]) + headers);    ASSERT_EQUAL(res->status, STATUS_NO_CONTENT);    ASSERT_CALL_TRUE(filesystem_is_dir, file);    ASSERT_CALL_FALSE(filesystem_is_file, file);    if (method == "COPY") { -  webdav_ls(testcase_dir, -  ({ testcase_dir, -  dir, +  webdav_ls(dir, +  ({ dir, +  mydir,    file }));    } else { // method = "MOVE" -  webdav_ls(testcase_dir, -  ({ testcase_dir, +  webdav_ls(dir, +  ({ dir,    file }));    }   }      public void test_copy_dest_exist_no_overwrite_header()   {    do_test_copy_file_to_existing_file("COPY", UNDEFINED);    do_test_copy_file_to_existing_dir( "COPY", UNDEFINED);    do_test_copy_dir_to_existing_file( "COPY", UNDEFINED);    do_test_copy_dir_to_existing_dir( "COPY", UNDEFINED);
Roxen.git/server/etc/test/modules/TEST.pmod/http.pmod/WebDAV.pmod/TestBase.pike:1638:    A,    Stdio.append_path(A, "X"),    Stdio.append_path(A, "X", "Y"),    });    array(string) files =    ({    Stdio.append_path(A, "file.txt"),    Stdio.append_path(A, "X", "x_file.txt"),    Stdio.append_path(A, "X", "Y", "y_file.txt"),    }); -  webdav_mkcol(directories[0], STATUS_CREATED); -  webdav_mkcol(directories[1], STATUS_CREATED); +  foreach(directories, string dir) { +  webdav_mkcol(dir, STATUS_CREATED); +  }    foreach (files, string file) {    webdav_put(file, "Some content", STATUS_CREATED);    }    string B = Stdio.append_path(this::testcase_dir, "B");    WebDAVResponse res = webdav_request("MOVE", A,    ([ "new-uri": B ]) +    ( depth ? ([ "Depth" : depth ]) : ([]) ));    ASSERT_EQUAL(res->status, STATUS_CREATED);    array(string) expected = map(directories + files, replace, "/A", "/B");    ASSERT_CALL_TRUE(webdav_ls, B, expected);
Roxen.git/server/etc/test/modules/TEST.pmod/http.pmod/WebDAV.pmod/TestBase.pike:2031:    string file1 = make_filenames(dir1, filename,    unicode_method_put1, true)[case_put1];    string dir2 = make_filenames(this::testcase_dir, filename,    unicode_method_put2, true)[case_put2];    string file2 = make_filenames(dir2, filename,    unicode_method_put2, true)[case_put2];    string exp_dir = make_filenames(this::testcase_dir, filename,    "NFC", false)[case_put1];    mapping(string:string) exp_file = make_filenames(exp_dir, filename,    "NFC", false); +  webdav_mkcol(dir1, STATUS_CREATED); +  if (!caseSensitive || (case_put1 == case_put2)) { +  webdav_mkcol(dir2, STATUS_METHOD_NOT_ALLOWED); +  } else { +  webdav_mkcol(dir2, STATUS_CREATED); +  }    webdav_put(file1, "FILE " + count, STATUS_CREATED);    // Try to put again, possibly with different encoding and    // possible with different case.    int expected_status_code = STATUS_CREATED;    bool filenames_considered_equal;    if (caseSensitive) {    filenames_considered_equal =    Unicode.normalize(utf8_to_string(file1), "NFC") ==    Unicode.normalize(utf8_to_string(file2), "NFC");    } else {
Roxen.git/server/etc/test/modules/TEST.pmod/http.pmod/WebDAV.pmod/TestBase.pike:2056:    expected_status_code = STATUS_OK;    }    webdav_put(file2, "FILE 2" + count, expected_status_code);    if (!caseSensitive) {    webdav_ls(dir1,    ({ exp_dir, exp_file[case_put1] }) );    webdav_ls(dir2,    ({ exp_dir, exp_file[case_put1] }) );    } else {    webdav_ls(dir1, -  ({ dir1, -  file1 }) ); +  map(({ dir1, file1 }), utf8_to_string) );    webdav_ls(dir2, -  ({ dir2, -  file2 }) ); +  map(({ dir2, file2 }), utf8_to_string) );    }    }    }    }    }    }   }      // Test copy where src and target is the same except for case.   public void test_x_copy_file()
Roxen.git/server/etc/test/modules/TEST.pmod/http.pmod/WebDAV.pmod/TestBase.pike:2090:    foreach (({"mc", "lc", "uc"}), string case_target) {    string filename = sprintf("%0"+w+"d_%s", count++, str);    string src_file =    make_filenames(this::testcase_dir, filename, unicode_method_src,    true)[case_src];    string target_file =    make_filenames(this::testcase_dir, filename,    unicode_method_target, true)[case_target];    webdav_put(src_file, "FILE " + count, STATUS_CREATED);    if (case_src == case_target) { -  // Src and target is equal and same case but may be different -  //encoded (will be at least once when looping...) +  // Src and target are equal and same case but may be different +  // encoded (will be at least once when looping...)    webdav_copy(src_file, target_file, STATUS_FORBIDDEN);    } else {    // Src and target is different case (but the same otherwise).    webdav_copy(src_file, target_file,    caseSensitive ? STATUS_CREATED : STATUS_NO_CONTENT);    }    }    }    }    }