summaryrefslogtreecommitdiff
path: root/test/parallel/test-process-uid-gid.js
diff options
context:
space:
mode:
authorRajkumar Purushothaman <raj.dhandus@gmail.com>2018-04-06 18:42:38 -0400
committerTobias Nießen <tniessen@tnie.de>2018-04-07 02:08:28 +0200
commitfde93f82b2b0cb05c598913b8782005350bcf4de (patch)
treeef5c0f8145a9f6fb407209ac8f6f7b2e4d2bd1e9 /test/parallel/test-process-uid-gid.js
parent0c55abf5d1cb3e272f2d801e99b41c0d071b1a3e (diff)
downloadandroid-node-v8-fde93f82b2b0cb05c598913b8782005350bcf4de.tar.gz
android-node-v8-fde93f82b2b0cb05c598913b8782005350bcf4de.tar.bz2
android-node-v8-fde93f82b2b0cb05c598913b8782005350bcf4de.zip
test: rename test cases
test-process-geteuid-getegid.js is renamed to test-process-euid-egid.js. test-process-setuid-setgid.js is renamed to test-process-uid-gid.js. PR-URL: https://github.com/nodejs/node/pull/19765 Fixes: https://github.com/nodejs/node/issues/19592 Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/parallel/test-process-uid-gid.js')
-rw-r--r--test/parallel/test-process-uid-gid.js71
1 files changed, 71 insertions, 0 deletions
diff --git a/test/parallel/test-process-uid-gid.js b/test/parallel/test-process-uid-gid.js
new file mode 100644
index 0000000000..d3aac29dec
--- /dev/null
+++ b/test/parallel/test-process-uid-gid.js
@@ -0,0 +1,71 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+'use strict';
+const common = require('../common');
+
+const assert = require('assert');
+
+if (common.isWindows) {
+ // uid/gid functions are POSIX only
+ assert.strictEqual(process.getuid, undefined);
+ assert.strictEqual(process.setuid, undefined);
+ assert.strictEqual(process.getgid, undefined);
+ assert.strictEqual(process.setgid, undefined);
+ return;
+}
+
+assert.throws(() => {
+ process.setuid({});
+}, /^TypeError: setuid argument must be a number or a string$/);
+
+assert.throws(() => {
+ process.setuid('fhqwhgadshgnsdhjsdbkhsdabkfabkveybvf');
+}, /^Error: setuid user id does not exist$/);
+
+// If we're not running as super user...
+if (process.getuid() !== 0) {
+ // Should not throw.
+ process.getgid();
+ process.getuid();
+
+ assert.throws(
+ () => { process.setgid('nobody'); },
+ /^Error: (?:EPERM, .+|setgid group id does not exist)$/
+ );
+
+ assert.throws(
+ () => { process.setuid('nobody'); },
+ /^Error: (?:EPERM, .+|setuid user id does not exist)$/
+ );
+ return;
+}
+
+// If we are running as super user...
+const oldgid = process.getgid();
+process.setgid('nobody');
+const newgid = process.getgid();
+assert.notStrictEqual(newgid, oldgid);
+
+const olduid = process.getuid();
+process.setuid('nobody');
+const newuid = process.getuid();
+assert.notStrictEqual(newuid, olduid);