Skip to content

Commit

Permalink
test: regression test for Node issue #20112
Browse files Browse the repository at this point in the history
Port test from nodejs/node#20138 to libuv.

Refs: nodejs/node#20112
Refs: nodejs/node#20138
  • Loading branch information
bzoz committed Apr 26, 2018
1 parent 0b3c499 commit a4ca9e7
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
89 changes: 89 additions & 0 deletions test/test-fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions test/test-list.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a4ca9e7

Please sign in to comment.