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:57:   protected array(string) filesystem_get_dir(string path);      protected int filesystem_is_dir(string path);      protected int filesystem_is_file(string path);      protected int filesystem_check_exists(string path);      protected string filesystem_read_file(string path);    + protected int(0..1) filesystem_mkdir_recursive(string(8bit) path); +  + //! Writes a file to @[path], which is used verbatim without any normalization. + protected int(0..) filesystem_direct_write(string(8bit) path, string(8bit) data); +    // protected int filesystem_recursive_rm(string path);      protected int filesystem_check_content(string path, string expected_data)   {    string actual_data = filesystem_read_file(path);    TEST_EQUAL(actual_data, expected_data); // Needed for the old style test code.    return actual_data == expected_data;   }      protected int filesystem_compare_files(string first_path, string other_path)
Roxen.git/server/etc/test/modules/TEST.pmod/http.pmod/WebDAV.pmod/TestBase.pike:107:    string path,    mapping(string:string)|void extra_headers,    string|void data)   {    mapping(string:string) headers = base_headers + ([]);       if (extra_headers) {    headers += extra_headers;    }    +  if (upper_case(method) == "HEAD") { +  // Workaround for bug in Protocols.HTTP.Query. +  headers["connection"] = "close"; +  } +     array(string) lock_paths = ({ path });       // Convert the fake header "new-uri" into a proper "destination" header.    string new_uri = m_delete(headers, "new-uri");    if (new_uri) {    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 });
Roxen.git/server/etc/test/modules/TEST.pmod/http.pmod/WebDAV.pmod/TestBase.pike:345:    }    return res;   }      protected WebDAVResponse webdav_move(string src_path,    string dst_path,    mapping(string:string) locks,    int expected_status_code)   {    bool src_equals_dst = false; -  if (case_sensitive()) { +  if (case_sensitive_filesystem()) {    src_equals_dst = Unicode.normalize(utf8_to_string(src_path), "NFC") ==    Unicode.normalize(utf8_to_string(dst_path), "NFC");    } else {    src_equals_dst = lower_case(Unicode.normalize(utf8_to_string(src_path), "NFC")) ==    lower_case(Unicode.normalize(utf8_to_string(dst_path), "NFC"));    }    string expected_content;    bool is_regular_file = filesystem_is_file(src_path);    if (is_regular_file) {    expected_content = filesystem_read_file(src_path);
Roxen.git/server/etc/test/modules/TEST.pmod/http.pmod/WebDAV.pmod/TestBase.pike:480:   }      protected WebDAVResponse webdav_ls(string path,    array(string) expected,    int|void expected_status_code)   {    return [object(WebDAVResponse)]    do_webdav_ls(path, expected, true, expected_status_code);   }    - protected bool case_sensitive() + enum FSBehavior { +  FS_RAW = 0, +  FS_CASE_INSENSITIVE = 1, +  FS_UNICODE_NORMALIZING = 2, +  FS_BOTH = 3, + }; +  + protected FSBehavior filesystem_behavior()   {    string sysname = System.uname()->sysname;    if (sysname == "Darwin") { // OS X -  return false; +  return FS_BOTH;    }    if (has_value(sysname, "Win32")) { // Windows -  return false; +  return FS_CASE_INSENSITIVE;    } -  return true; +  return FS_RAW;   }    -  + protected bool case_sensitive_filesystem() + { +  return !(filesystem_behavior() & FS_CASE_INSENSITIVE); + } +  + protected bool non_normalizing_filesystem() + { +  return !(filesystem_behavior() & FS_UNICODE_NORMALIZING); + } +    protected void prepare_testdir(string testdir)   {    testdir = has_suffix(testdir, "/") ? testdir[..<1] : testdir;    DAV_WERROR("Webdav: Test dir is: %O\n", testdir);       // Consider working directly with the filesystem instead.    // filesystem_recursive_rm(testdir);       // webdav_mkcol may return true even it the dir already existed. Therefor    // we always clean.
Roxen.git/server/etc/test/modules/TEST.pmod/http.pmod/WebDAV.pmod/TestBase.pike:2078:    Test both with an empty destination directory and with a non empty    destination directory. (We already test at least one of the cases.)   */         // -----------------------------------------------------------------------------   // Special testcases combining different encodings and mixed/lower/upper case   // letters.   // -----------------------------------------------------------------------------    + // NB: Some character sets (eg kanji, hangul, etc) only have + // a single "case", and make_filenames() requires multiple + // cases. Work around this issue by prefixing with some + // multi-case ascii characters.   #ifdef WEBDAV_TEST_ASCII_ONLY   protected constant FILENAMES =    ({ -  "myFile", // To compare with +  "Ascii-myFile", // To compare with    });   #else   protected constant FILENAMES =    ({ -  "myFile", // To compare with -  "åÅäÄöÖæÆüÜñÑ@", // Some Latin 1 chars -  "ąĄŁůŮăĂçÇ", // Some Latin 2 chars -  "фщъЂЃЄЉЖ", // Some Cyrillic chars -  "ώψφλξβΩΠΞΔ€", // Some Greek chars +  "Ascii-myFile", // To compare with +  "Latin1-åÅäÄöÖæÆüÜñÑ@", // Some Latin 1 chars +  "Latin2-ąĄŁůŮăĂçÇ", // Some Latin 2 chars +  "Cyrillic-фщъЂЃЄЉЖ", // Some Cyrillic chars +  "Greek-ώψφλξβΩΠΞΔ€", // Some Greek chars +  "Kanji-日本語ひらがなカタカナ", // Some Kanji, hiragana and katakana.    });   #endif      // Create directory and file using one encoding and mixed, lower or upper case.   // Then do ls for all combinations of (same encoding, other encoding) x   // (mixed case, lower case, upper case).   public void test_x_ls()   {    int count = 0; -  bool caseSensitive = case_sensitive(); +  bool normalizing = !non_normalizing_filesystem(); +  bool casesensitive = case_sensitive_filesystem();    int w = sizeof("" + (sizeof(FILENAMES)*2*3) );    foreach (FILENAMES, string str) {    // TODO: Skip the following 2 loops and just pick an encoding and a case for the src, or?    foreach (({"NFC", "NFD"}), string unicode_method_create) {    foreach (({"mc", "lc", "uc"}), string case_create) {    foreach (({"NFC", "NFD"}), string unicode_method_ls) {    foreach (({"mc", "lc", "uc"}), string case_ls) {    string filename = sprintf("%0"+w+"d_%s", count++, str);    string new_dir =    make_filenames(this::testcase_dir, filename,
Roxen.git/server/etc/test/modules/TEST.pmod/http.pmod/WebDAV.pmod/TestBase.pike:2123:    make_filenames("", filename, unicode_method_create,    true)[case_create];    string dir_ls = make_filenames(this::testcase_dir, filename,    unicode_method_ls, true)[case_ls];    string file_ls = make_filenames("", filename, unicode_method_ls,    true)[case_ls];    mapping(string:string) exp_dir =    make_filenames(this::testcase_dir, filename, "NFC", false);    mapping(string:string) exp_file = make_filenames("", filename,    "NFC", false); -  webdav_mkcol(new_dir, STATUS_CREATED); -  if (case_create == case_ls) { +  ASSERT_EQUAL(filesystem_mkdir_recursive(new_dir), 1); +  string exp_path = exp_dir[case_ls] + "/" + exp_file[case_ls]; +  +  // NB: In normalizing (which implies !casesensitive) mode +  // the paths should always match. +  int exp_match = 1; +  if (!normalizing) { +  // NB: In casesensitive mode the paths only match if they +  // are coded identically. +  exp_match = (string_to_utf8(exp_path) == +  Stdio.append_path(new_dir, new_file)); +  if (!exp_match && !casesensitive) { +  // NB: To handle cases where the NFC and NFD normalizations +  // are equal (eg ascii or kanji) it is not sufficient +  // to just look at whether unicode_method_create is +  // "NFC" or "NFD". +  exp_match = (new_dir == +  make_filenames(this::testcase_dir, filename, +  "NFC", true)[case_create]); +  } +  } + #if 0 +  werror("normalizing: %d\n" +  "casesensitive: %d\n" +  "str: %O\n" +  "umc: %O\n" +  "cc: %O\n" +  "uml: %O\n" +  "cls: %O\n" +  "fn: %O\n" +  "nd: %O\n" +  "nf: %O\n" +  "dls: %O\n" +  "fls: %O\n" +  "ed: %O\n" +  "ef: %O\n" +  "ep: %O\n" +  "em: %O\n" +  "--------\n" +  "utf8(ep): %O\n" +  "ap(nd, nf): %O\n", +  normalizing, casesensitive, +  str, unicode_method_create, case_create, +  unicode_method_ls, case_ls, +  filename, +  new_dir, new_file, +  dir_ls, file_ls, +  exp_dir, exp_file, exp_path, exp_match, +  string_to_utf8(exp_path), +  Stdio.append_path(new_dir, new_file)); + #endif +  +  if (exp_match) {    webdav_ls(dir_ls, ({ exp_dir[case_ls] }) );    } else { -  webdav_ls(dir_ls, ({ exp_dir[case_ls] }), -  caseSensitive && STATUS_NOT_FOUND); +  webdav_ls(dir_ls, ({}), STATUS_NOT_FOUND);    } -  webdav_put(new_dir + "/" + new_file, "FILE " + count, STATUS_CREATED); -  if (case_create == case_ls) { +  string testdata = "FILE " + count; +  ASSERT_EQUAL(filesystem_direct_write(new_dir + "/" + new_file, +  testdata), +  sizeof(testdata)); +  if (exp_match) { +  // In this case we should always get a successful listing.    webdav_ls(dir_ls,    ({ exp_dir[case_ls],    exp_dir[case_ls] + "/" + exp_file[case_create] }) ); -  +  +  // When listing a file directly, it will have equivalent case +  // in the returned list.    webdav_ls(dir_ls + "/" + file_ls, -  ({ exp_dir[case_ls] + "/" + exp_file[case_create] }) ); +  ({ exp_dir[case_ls] + "/" + exp_file[case_ls] }) );    } else { -  webdav_ls(dir_ls, -  caseSensitive ? -  ({ }) : -  ({ exp_dir[case_ls], -  exp_dir[case_ls] + "/" + exp_file[case_create] }), -  caseSensitive ? STATUS_NOT_FOUND : STATUS_MULTI_STATUS); -  webdav_ls(dir_ls + "/" + file_ls, -  caseSensitive ? -  ({ }) : -  ({ exp_dir[case_ls] + "/" + exp_file[case_ls] }), -  caseSensitive ? STATUS_NOT_FOUND : STATUS_MULTI_STATUS); +  webdav_ls(dir_ls, ({}), STATUS_NOT_FOUND); +  webdav_ls(dir_ls + "/" + file_ls, ({ }), STATUS_NOT_FOUND);    }    }    }    }    }    }   }      // Test create directory and file containing special chars.   public void test_x_special_chars()
Roxen.git/server/etc/test/modules/TEST.pmod/http.pmod/WebDAV.pmod/TestBase.pike:2193:    webdav_ls(dir_path, ({ dir_path }) );    webdav_put(file_path, "FILE\n", STATUS_CREATED);    webdav_ls(dir_path, ({ dir_path, file_path }) );    };    }   }      public void test_x_put()   {    int count = 0; -  bool caseSensitive = case_sensitive(); +  bool caseSensitive = case_sensitive_filesystem();    int w = sizeof("" + (sizeof(FILENAMES)*2*3) );    foreach (FILENAMES, string str) {    // TODO: Skip the following 2 loops and just pick an encoding and a case for the src, or?    foreach (({"NFC", "NFD"}), string unicode_method_put1) {    foreach (({"mc", "lc", "uc"}), string case_put1) {    foreach (({"NFC", "NFD"}), string unicode_method_put2) {    foreach (({"mc", "lc", "uc"}), string case_put2) {    string filename = sprintf("%0"+w+"d_%s", count++, str);    string dir = make_filenames(this::testcase_dir, filename,    unicode_method_put1, true)[case_put1];
Roxen.git/server/etc/test/modules/TEST.pmod/http.pmod/WebDAV.pmod/TestBase.pike:2254:    }    }    }    }   }      // Test copy where src and target is the same except for case.   public void test_x_copy_file()   {    int count = 0; -  bool caseSensitive = case_sensitive(); +  bool caseSensitive = case_sensitive_filesystem();    int w = sizeof("" + (sizeof(FILENAMES)*2*3) );    foreach (FILENAMES, string str) {    // TODO: Skip the following 2 loops and just pick an encoding and a case for the src, or?    foreach (({"NFC", "NFD"}), string unicode_method_src) {    foreach (({"mc", "lc", "uc"}), string case_src) {    foreach (({"NFC", "NFD"}), string unicode_method_target) {    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,
Roxen.git/server/etc/test/modules/TEST.pmod/http.pmod/WebDAV.pmod/TestBase.pike:2290:    }    }    }    }   }      // This testcase tests creating a directory that already exists.   public void test_x_mkcol()   {    int count = 0; -  bool caseSensitive = case_sensitive(); +  bool caseSensitive = case_sensitive_filesystem();    int w = sizeof("" + (sizeof(FILENAMES)*2*3) );    foreach (FILENAMES, string str) {    // TODO: Skip the following 2 loops and just pick an encoding and a case for the src, or?    foreach (({"NFC", "NFD"}), string unicode_method_dir1) {    foreach (({"mc", "lc", "uc"}), string case_dir1) {    foreach (({"NFC", "NFD"}), string unicode_method_dir2) {    foreach (({"mc", "lc", "uc"}), string case_dir2) {    string filename = sprintf("%0"+w+"d_%s", count++, str);    string dir1 = make_filenames(this::testcase_dir, filename,    unicode_method_dir1, true)[case_dir1];
Roxen.git/server/etc/test/modules/TEST.pmod/http.pmod/WebDAV.pmod/TestBase.pike:2325:    }    }    }    }   }      // Test move where src and target is the same except for case.   public void test_x_move_file()   {    int count = 0; -  bool caseSensitive = case_sensitive(); +  bool caseSensitive = case_sensitive_filesystem();    int w = sizeof("" + (sizeof(FILENAMES)*2*3) );    foreach (FILENAMES, string str) {    // TODO: Skip the following 2 loops and just pick an encoding and a case for the src, or?    foreach (({"NFC", "NFD"}), string unicode_method_src) {    foreach (({"mc", "lc", "uc"}), string case_src) {    foreach (({"NFC", "NFD"}), string unicode_method_target) {    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];
Roxen.git/server/etc/test/modules/TEST.pmod/http.pmod/WebDAV.pmod/TestBase.pike:2364:    }    }    }    }    }   }      // Runs only on case insensitive systems.   public void test_x_put_copy_move_delete()   { -  if (case_sensitive()) { +  if (case_sensitive_filesystem()) {    return;    }    string mv_dst = Stdio.append_path(this::testcase_dir, "mv_dst");    string cp_dst = Stdio.append_path(this::testcase_dir, "cp_dst");    foreach (FILENAMES, string filename) {    foreach (({"NFC", "NFD"}), string unicode_method_put) {    string put_path = make_filenames(this::testcase_dir,    filename,    unicode_method_put,    true)->mc;
Roxen.git/server/etc/test/modules/TEST.pmod/http.pmod/WebDAV.pmod/TestBase.pike:2426:   // Test cannot put on a locked non existing resource without lock.   // Test cannot put on locked existing resource without lock.   // Test cannot delete locked existing resource without lock.   // Test can put on locked existing resource if we have the lock.   // Test can delete locked existing resource if we have the lock.   // Test lock handling is case insensitive on case insensitive systems.   //   // We satisfy with taking a lock on a resource with mixed case and later   // creating a file with the same case.   { -  bool caseSensitive = case_sensitive(); +  bool caseSensitive = case_sensitive_filesystem();    array(string) cases = ({"mc", "lc", "uc"});    if (caseSensitive) {    cases = ({ "mc" });    }    foreach (FILENAMES, string filename) {    foreach (({"NFC", "NFD"}), string unicode_method) {    mapping(string:string) resources = make_filenames(this::testcase_dir,    filename,    unicode_method,    true);