diff options
author | cjihrig <cjihrig@gmail.com> | 2016-04-07 13:45:40 -0400 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2016-04-26 12:16:00 -0700 |
commit | e052096ee08308ed8b08197c2f1e1f45ce72e005 (patch) | |
tree | f80cf67a7af35980440bdfe351b3b6b70371a838 /test | |
parent | 5a26849e1d7f979971faa20969a9182934cf5538 (diff) | |
download | node-new-e052096ee08308ed8b08197c2f1e1f45ce72e005.tar.gz |
os: add userInfo() method
os.userInfo() calls libuv's uv_os_get_passwd() function. It returns
an object containing the current effective user's username, uid,
gid, shell, and home directory. On Windows, the uid and gid are
-1, and the shell is null.
Refs: https://github.com/nodejs/node/issues/5582
PR-URL: https://github.com/nodejs/node/pull/6104
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-os.js | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/test/parallel/test-os.js b/test/parallel/test-os.js index 15fd189f9b..dcf6bcfbe9 100644 --- a/test/parallel/test-os.js +++ b/test/parallel/test-os.js @@ -125,3 +125,27 @@ if (common.isWindows && process.env.USERPROFILE) { assert.ok(os.homedir().indexOf(path.sep) !== -1); process.env.HOME = home; } + +const pwd = os.userInfo(); +const pwdBuf = os.userInfo({ encoding: 'buffer' }); + +if (common.isWindows) { + assert.strictEqual(pwd.uid, -1); + assert.strictEqual(pwd.gid, -1); + assert.strictEqual(pwd.shell, null); + assert.strictEqual(pwdBuf.uid, -1); + assert.strictEqual(pwdBuf.gid, -1); + assert.strictEqual(pwdBuf.shell, null); +} else { + assert.strictEqual(typeof pwd.uid, 'number'); + assert.strictEqual(typeof pwd.gid, 'number'); + assert.notStrictEqual(pwd.shell.indexOf(path.sep), -1); + assert.strictEqual(pwd.uid, pwdBuf.uid); + assert.strictEqual(pwd.gid, pwdBuf.gid); + assert.strictEqual(pwd.shell, pwdBuf.shell.toString('utf8')); +} + +assert.strictEqual(typeof pwd.username, 'string'); +assert.notStrictEqual(pwd.homedir.indexOf(path.sep), -1); +assert.strictEqual(pwd.username, pwdBuf.username.toString('utf8')); +assert.strictEqual(pwd.homedir, pwdBuf.homedir.toString('utf8')); |