From a4ca9e7c08844540a8e3f8a9088edbacc0a4eaab Mon Sep 17 00:00:00 2001 From: Bartosz Sosnowski Date: Thu, 26 Apr 2018 12:38:59 +0200 Subject: [PATCH] test: regression test for Node issue #20112 Port test from https://github.com/nodejs/node/pull/20138 to libuv. Refs: https://github.com/nodejs/node/issues/20112 Refs: https://github.com/nodejs/node/pull/20138 --- test/test-fs.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++ test/test-list.h | 2 ++ 2 files changed, 91 insertions(+) diff --git a/test/test-fs.c b/test/test-fs.c index 000a151a64e..d1131ec5d95 100644 --- a/test/test-fs.c +++ b/test/test-fs.c @@ -3230,3 +3230,92 @@ TEST_IMPL(fs_exclusive_sharing_mode) { return 0; } #endif + +#ifdef _WIN32 +int call_icacls(const char* command, ...) { + uv_process_t handle; + uv_process_options_t options; + char icacls_command[1024]; + char* icacls_args[3]; + va_list args; + + va_start(args, command); + vsnprintf(icacls_command, ARRAYSIZE(icacls_command), command, args); + va_end(args); + return system(icacls_command); +} + +TEST_IMPL(fs_open_readonly_acl) { + uv_passwd_t pwd; + uv_fs_t req; + int r; + + /* + Based on Node.js test from + https://github.com/nodejs/node/commit/3ba81e34e86a5c32658e218cb6e65b13e8326bc5 + + If anything goes wrong, you can delte the test_fle_icacls with: + + icacls test_file_icacls /remove "%USERNAME%" /inheritance:e + attrib -r test_file_icacls + del test_file_icacls + */ + + /* Setup - clear the ACL and remove the file */ + loop = uv_default_loop(); + r = uv_os_get_passwd(&pwd); + ASSERT(r == 0); + call_icacls("icacls test_file_icacls /remove \"%s\" /inheritance:e", + pwd.username); + uv_fs_chmod(loop, &req, "test_file_icacls", S_IWUSR, NULL); + unlink("test_file_icacls"); + + /* Create the file */ + r = uv_fs_open(loop, + &open_req1, + "test_file_icacls", + O_RDONLY | O_CREAT, + S_IRUSR, + NULL); + ASSERT(r >= 0); + ASSERT(open_req1.result >= 0); + uv_fs_req_cleanup(&open_req1); + r = uv_fs_close(NULL, &close_req, open_req1.result, NULL); + ASSERT(r == 0); + ASSERT(close_req.result == 0); + uv_fs_req_cleanup(&close_req); + + /* Set up ACL */ + r = call_icacls("icacls test_file_icacls /inheritance:r /remove \"%s\"", + pwd.username); + if (r != 0) { + goto acl_cleanup; + } + r = call_icacls("icacls test_file_icacls /grant \"%s\":RX", pwd.username); + if (r != 0) { + goto acl_cleanup; + } + + /* Try opening the file */ + r = uv_fs_open(NULL, &open_req1, "test_file_icacls", O_RDONLY, 0, NULL); + if (r < 0) { + goto acl_cleanup; + } + uv_fs_req_cleanup(&open_req1); + r = uv_fs_close(NULL, &close_req, open_req1.result, NULL); + if (r != 0) { + goto acl_cleanup; + } + uv_fs_req_cleanup(&close_req); + + acl_cleanup: + /* Cleanup */ + call_icacls("icacls test_file_icacls /remove \"%s\" /inheritance:e", + pwd.username); + unlink("test_file_icacls"); + uv_os_free_passwd(&pwd); + ASSERT(r == 0); + MAKE_VALGRIND_HAPPY(); + return 0; +} +#endif diff --git a/test/test-list.h b/test/test-list.h index b89930d709e..bb95ba56f47 100644 --- a/test/test-list.h +++ b/test/test-list.h @@ -337,6 +337,7 @@ TEST_DECLARE (fs_file_pos_after_op_with_offset) TEST_DECLARE (fs_null_req) #ifdef _WIN32 TEST_DECLARE (fs_exclusive_sharing_mode) +TEST_DECLARE (fs_open_readonly_acl) #endif TEST_DECLARE (threadpool_queue_work_simple) TEST_DECLARE (threadpool_queue_work_einval) @@ -869,6 +870,7 @@ TASK_LIST_START TEST_ENTRY (fs_null_req) #ifdef _WIN32 TEST_ENTRY (fs_exclusive_sharing_mode) + TEST_ENTRY (fs_open_readonly_acl) #endif TEST_ENTRY (get_osfhandle_valid_handle) TEST_ENTRY (threadpool_queue_work_simple)