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:1:   // Necessary for stuff in testsuite.h to work...   inherit "etc/test/tests/pike_test_common.pike" : Parent;      #include <testsuite.h>      #charset utf-8      protected constant STATUS_OK = 200; + protected constant STATUS_CREATED = 201;   protected constant STATUS_NO_CONTENT = 204;   protected constant STATUS_MULTI_STATUS = 207;   protected constant STATUS_BAD_REQUEST = 400;   protected constant STATUS_FORBIDDEN = 403;   protected constant STATUS_NOT_FOUND = 404;   protected constant STATUS_METHOD_NOT_ALLOWED = 405;   protected constant STATUS_CONFLICT = 409;   protected constant STATUS_PRECONDITION_FAILED = 412; - protected constant STATUS_LOCKED = 423; - protected constant STATUS_CREATED = 201; +    protected constant STATUS_UNSUPPORTED_MEDIA_TYPE = 415; -  + protected constant STATUS_LOCKED = 423;         protected string webdav_mount_point;      private string testdir;   protected string testcase_dir;   private mapping(string:string) all_locks = ([]);      // Current Base URL to run the test suite for.   // Note that the hostname is an ip-number.
Roxen.git/server/etc/test/modules/TEST.pmod/http.pmod/WebDAV.pmod/TestBase.pike:57:      protected int filesystem_check_exists(string path);      protected string filesystem_read_file(string path);      // 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); +  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)   {    return filesystem_check_content(other_path, filesystem_read_file(first_path));   }      protected class WebDAVResponse(int status,    mapping(string:string) headers,
Roxen.git/server/etc/test/modules/TEST.pmod/http.pmod/WebDAV.pmod/TestBase.pike:189:    report_debug("Webdav: %s %O (url: %O) ==> code: %d\n",    method, path, url, con?con->status:600);       if (!con) {    return WebDAVResponse(600, ([]), "" );    }       return WebDAVResponse(con->status, con->headers, con->data());   }    + private mapping(string:string) make_lock_header(mapping(string:string) locks) + { +  string if_header = ""; +  foreach(locks; string path; string lock_token) { +  if (has_prefix(path, "/")) { +  path = path[1..]; +  } +  path = map((path / "/"), Protocols.HTTP.percent_encode) * "/"; +  path = Standards.URI(path, base_uri)->path; +  if_header += sprintf("<%s>(<%s>)", path, lock_token); +  } +  return (["if" : if_header]); + } +    private WebDAVResponse do_webdav_get(string method,    string path,    int expected_status_code)   {    ASSERT_TRUE(method == "GET" || method == "HEAD");    WebDAVResponse res =    webdav_request(method, path);    ASSERT_EQUAL(res->status, expected_status_code);    return res;   }
Roxen.git/server/etc/test/modules/TEST.pmod/http.pmod/WebDAV.pmod/TestBase.pike:211:   protected WebDAVResponse webdav_get(string path, int expected_status_code)   {    return do_webdav_get("GET", path, expected_status_code);   }      protected WebDAVResponse webdav_head(string path, int expected_status_code)   {    return do_webdav_get("HEAD", path, expected_status_code);   }    - protected WebDAVResponse webdav_put(string path, + protected WebDAVResponse webdav_put(string path,    string data, -  int|void expected_status_code) +  int expected_status_code, +  mapping(string:string)|void headers)   { -  expected_status_code = expected_status_code ? expected_status_code : -  STATUS_CREATED; +     WebDAVResponse res = -  webdav_request("PUT", path, UNDEFINED, data); +  webdav_request("PUT", path, headers, data);    ASSERT_EQUAL(res->status, expected_status_code);    if ( (res->status >= 200) && (res->status < 300) ) {    ASSERT_CALL_TRUE(filesystem_check_content, path, data);    }    return res;   }    - // New style. - protected variant WebDAVResponse webdav_lock(string path, + protected WebDAVResponse webdav_lock(string path,    mapping(string:string) locks,    int expected_status_code)   {    string lock_info = #"   <?xml version='1.0' encoding='utf-8'?>   <DAV:lockinfo xmlns:DAV='DAV:'>    <DAV:locktype><DAV:write/></DAV:locktype>    <DAV:lockscope><DAV:exclusive/></DAV:lockscope>   </DAV:lockinfo>   ";
Roxen.git/server/etc/test/modules/TEST.pmod/http.pmod/WebDAV.pmod/TestBase.pike:292:    ]));    ASSERT_EQUAL(res->status, expected_status_code);    if ((res[0] >= 200) && (res[0] < 300)) {    low_unlock(path, locks);    }    return res;   }      protected WebDAVResponse webdav_delete(string path,    mapping(string:string) locks, -  int expected_status_code) +  int expected_status_code, +  mapping(string:string)|void headers)   {    WebDAVResponse res = -  webdav_request("DELETE", path); +  webdav_request("DELETE", path, headers);    ASSERT_EQUAL(res->status, expected_status_code);    if ((res[0] >= 200) && (res[0] < 300) && (res[0] != STATUS_MULTI_STATUS) ){    low_recursive_unlock(path, locks);    ASSERT_CALL_FALSE(filesystem_check_exists, path);    }    return res;   }    - // New style. +    protected WebDAVResponse webdav_copy(string src_path,    string dst_path,    int expected_status_code)   {    WebDAVResponse res =    webdav_request("COPY", src_path, ([    "new-uri": dst_path,    ]));    ASSERT_EQUAL(res->status, expected_status_code);    if ( (res->status >= 200) && (res->status < 300) ) {    if (filesystem_is_file(src_path)) {    ASSERT_TRUE(filesystem_compare_files(src_path, dst_path));    } else if (filesystem_is_dir(src_path)) {    // TODO: Verify content of copied files.    } else {    error("Probably a bug in the test code."); -  +     }    }    return res;   }      protected WebDAVResponse webdav_move(string src_path,    string dst_path,    mapping(string:string) locks,    int expected_status_code)   {
Roxen.git/server/etc/test/modules/TEST.pmod/http.pmod/WebDAV.pmod/TestBase.pike:506:   {    this::testcase_dir = Stdio.append_path(this::testdir, testcase, "/");    prepare_testdir(this::testcase_dir);   }      protected void after_testcase(string testcase)   {    webdav_unlock_all(); // Usefull when running tests agains an already running server.   }    +  +    public void run()   {    mixed e = catch {    ASSERT_CALL(prepare_testdir, this::testdir);    array(mixed) testcases = indices(this);    if (getenv("TEST_CASE")) {    testcases = ({ getenv("TEST_CASE") });    }    foreach (testcases, mixed testcase) {    if (stringp(testcase) &&
Roxen.git/server/etc/test/modules/TEST.pmod/http.pmod/WebDAV.pmod/TestBase.pike:2292:    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];    string dir2 =    make_filenames(this::testcase_dir, filename, unicode_method_dir2,    true)[case_dir2];    webdav_mkcol(dir1, STATUS_CREATED);    if (case_dir1 == case_dir2) {    // Src and target is equal and same case but may be different -  //encoded (will be at least once when looping...) +  // encoded (will be at least once when looping...)    webdav_mkcol(dir2, STATUS_METHOD_NOT_ALLOWED);    } else {    // Src and target is different case (but the same otherwise).    webdav_mkcol(dir2,    caseSensitive ? STATUS_CREATED : STATUS_METHOD_NOT_ALLOWED);    }    }    }    }    }
Roxen.git/server/etc/test/modules/TEST.pmod/http.pmod/WebDAV.pmod/TestBase.pike:2328:    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);    mapping(string:string) locks = ([]);    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...) +  // encoded (will be at least once when looping...)    webdav_move(src_file, target_file, locks, STATUS_FORBIDDEN);    } else {    // Src and target is different case (but the same otherwise).    webdav_move(src_file, target_file, locks,    caseSensitive ? STATUS_CREATED : STATUS_NO_CONTENT);    }    // Delete the target file, so that we are guaranteed that the    // source file actually gets created with the expected file    // name by the put in the next loop.    webdav_delete(target_file, locks, STATUS_NO_CONTENT);    }    }    }    }    }   } -  +  + public void test_x_lock() + // Test cannot do mkcol on a locked non existing resource without lock. + // 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(); +  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); +  string resource = resources->mc; +  string exp_name = make_filenames(this::testcase_dir, +  filename, +  "NFC", +  false)->mc; +  foreach (({"NFC", "NFD"}), string unicode_method) { +  mapping(string:string) resources = make_filenames(this::testcase_dir, +  filename, +  unicode_method, +  true); +  foreach (cases, string case_) { +  // Lock the resource (does not exist yet). +  mapping(string:string) locks = ([]); +  webdav_lock(resource, locks, STATUS_OK); +  +  // Verify that we cannot create collection or file without the lock. +  // Try do delete without lock. +  webdav_mkcol(resources[case_], STATUS_LOCKED); +  webdav_put(resources[case_], "My content", STATUS_LOCKED); +  webdav_ls(resources[case_], ({ }), STATUS_NOT_FOUND); +  webdav_delete(resources[case_], ([]), STATUS_NOT_FOUND); +  +  // Now lets create a the resources (a file) that we have locked. +  webdav_put(resource, "My content", STATUS_CREATED, +  make_lock_header(locks)); +  webdav_ls(resources[case_], ({ exp_name })); +  +  // Try tp write to the locked file. Try to delete the locked file. +  webdav_put(resources[case_], "New content", STATUS_LOCKED); +  webdav_delete(resources[case_], ([]), STATUS_LOCKED); +  +  string lock_token = locks[resource]; +  mapping(string:string) lock_header = +  make_lock_header(([ resources[case_] : lock_token ])); +  // Put using lock. +  webdav_put(resources[case_], "New content", STATUS_OK, lock_header); +  // Delete without the lock. +  webdav_delete(resource, ([]), STATUS_LOCKED); +  // Delete using lock. +  webdav_delete(resource, ([]), STATUS_NO_CONTENT, lock_header); +  +  // Assert testcase dir is empty before next run. +  webdav_ls(this::testcase_dir, ({ this::testcase_dir })); +  } +  } +  } +  } + } +