• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright Joyent, Inc. and other Node contributors.
2//
3// Permission is hereby granted, free of charge, to any person obtaining a
4// copy of this software and associated documentation files (the
5// "Software"), to deal in the Software without restriction, including
6// without limitation the rights to use, copy, modify, merge, publish,
7// distribute, sublicense, and/or sell copies of the Software, and to permit
8// persons to whom the Software is furnished to do so, subject to the
9// following conditions:
10//
11// The above copyright notice and this permission notice shall be included
12// in all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20// USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22'use strict';
23const common = require('../common');
24const assert = require('assert');
25
26if (!common.isMainThread) {
27  assert.strictEqual(typeof process.umask(), 'number');
28  assert.throws(() => {
29    process.umask('0664');
30  }, { code: 'ERR_WORKER_UNSUPPORTED_OPERATION' });
31
32  common.skip('Setting process.umask is not supported in Workers');
33}
34
35// Note in Windows one can only set the "user" bits.
36let mask;
37if (common.isWindows) {
38  mask = '0600';
39} else {
40  mask = '0664';
41}
42
43const old = process.umask(mask);
44
45assert.strictEqual(process.umask(old), parseInt(mask, 8));
46
47// Confirm reading the umask does not modify it.
48// 1. If the test fails, this call will succeed, but the mask will be set to 0
49assert.strictEqual(process.umask(), old);
50// 2. If the test fails, process.umask() will return 0
51assert.strictEqual(process.umask(), old);
52
53assert.throws(() => {
54  process.umask({});
55}, {
56  code: 'ERR_INVALID_ARG_VALUE',
57  message: 'The argument \'mask\' must be a 32-bit unsigned integer ' +
58           'or an octal string. Received {}'
59});
60
61['123x', 'abc', '999'].forEach((value) => {
62  assert.throws(() => {
63    process.umask(value);
64  }, {
65    code: 'ERR_INVALID_ARG_VALUE',
66    message: 'The argument \'mask\' must be a 32-bit unsigned integer ' +
67             `or an octal string. Received '${value}'`
68  });
69});
70