mirror of
https://github.com/nodejs/node.git
synced 2025-05-01 17:03:34 +00:00

Disallow the use of Object.defineProperty() to hide entries in process.env or make them immutable. PR-URL: https://github.com/nodejs/node/pull/28006 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
68 lines
1.5 KiB
JavaScript
68 lines
1.5 KiB
JavaScript
'use strict';
|
|
require('../common');
|
|
const assert = require('assert');
|
|
|
|
assert.throws(
|
|
() => {
|
|
Object.defineProperty(process.env, 'foo', {
|
|
value: 'foo1'
|
|
});
|
|
},
|
|
{
|
|
code: 'ERR_INVALID_OBJECT_DEFINE_PROPERTY',
|
|
name: 'TypeError',
|
|
message: '\'process.env\' only accepts a ' +
|
|
'configurable, writable,' +
|
|
' and enumerable data descriptor'
|
|
}
|
|
);
|
|
|
|
assert.strictEqual(process.env.foo, undefined);
|
|
process.env.foo = 'foo2';
|
|
assert.strictEqual(process.env.foo, 'foo2');
|
|
|
|
assert.throws(
|
|
() => {
|
|
Object.defineProperty(process.env, 'goo', {
|
|
get() {
|
|
return 'goo';
|
|
},
|
|
set() {}
|
|
});
|
|
},
|
|
{
|
|
code: 'ERR_INVALID_OBJECT_DEFINE_PROPERTY',
|
|
name: 'TypeError',
|
|
message: '\'process.env\' does not accept an' +
|
|
'accessor(getter/setter) descriptor'
|
|
}
|
|
);
|
|
|
|
const attributes = ['configurable', 'writable', 'enumerable'];
|
|
|
|
attributes.forEach((attribute) => {
|
|
assert.throws(
|
|
() => {
|
|
Object.defineProperty(process.env, 'goo', {
|
|
[attribute]: false
|
|
});
|
|
},
|
|
{
|
|
code: 'ERR_INVALID_OBJECT_DEFINE_PROPERTY',
|
|
name: 'TypeError',
|
|
message: '\'process.env\' only accepts a ' +
|
|
'configurable, writable,' +
|
|
' and enumerable data descriptor'
|
|
}
|
|
);
|
|
});
|
|
|
|
assert.strictEqual(process.env.goo, undefined);
|
|
Object.defineProperty(process.env, 'goo', {
|
|
value: 'goo',
|
|
configurable: true,
|
|
writable: true,
|
|
enumerable: true
|
|
});
|
|
assert.strictEqual(process.env.goo, 'goo');
|