@@ -10,26 +10,21 @@ if (!isMainThread) {
1010
1111const assert = require ( 'assert' ) ;
1212
13- // Guarantee the initial state
1413{
1514 assert . ok ( ! process . permission . has ( 'env' ) ) ;
1615}
1716
18- // Allowed env vars should be accessible
1917{
20- // Reading allowed env vars should not throw
2118 const home = process . env . HOME ;
2219 const path = process . env . PATH ;
2320 assert . ok ( process . permission . has ( 'env' , 'HOME' ) ) ;
2421 assert . ok ( process . permission . has ( 'env' , 'PATH' ) ) ;
2522}
2623
27- // Disallowed env vars should return undefined (silently denied)
2824{
2925 assert . strictEqual ( process . env . SECRET_KEY , undefined ) ;
3026}
3127
32- // Setting a disallowed env var should throw
3328{
3429 assert . throws ( ( ) => {
3530 process . env . NEW_VAR = 'value' ;
@@ -40,7 +35,6 @@ const assert = require('assert');
4035 } ) ) ;
4136}
4237
43- // Deleting a disallowed env var should throw
4438{
4539 assert . throws ( ( ) => {
4640 delete process . env . SECRET_KEY ;
@@ -51,12 +45,10 @@ const assert = require('assert');
5145 } ) ) ;
5246}
5347
54- // Querying a disallowed env var should return false (not found)
5548{
5649 assert . strictEqual ( 'SECRET_KEY' in process . env , false ) ;
5750}
5851
59- // Enumerating should only return allowed env vars
6052{
6153 const keys = Object . keys ( process . env ) ;
6254 for ( const key of keys ) {
@@ -66,3 +58,38 @@ const assert = require('assert');
6658 ) ;
6759 }
6860}
61+
62+ {
63+ const keys = [ ] ;
64+ for ( const key in process . env ) {
65+ keys . push ( key ) ;
66+ }
67+ for ( const key of keys ) {
68+ assert . ok (
69+ key === 'HOME' || key === 'PATH' ,
70+ `Unexpected env var in for...in: ${ key } `
71+ ) ;
72+ }
73+ }
74+
75+ {
76+ const copy = Object . assign ( { } , process . env ) ;
77+ const keys = Object . keys ( copy ) ;
78+ for ( const key of keys ) {
79+ assert . ok (
80+ key === 'HOME' || key === 'PATH' ,
81+ `Unexpected env var in Object.assign: ${ key } `
82+ ) ;
83+ }
84+ }
85+
86+ {
87+ const parsed = JSON . parse ( JSON . stringify ( process . env ) ) ;
88+ const keys = Object . keys ( parsed ) ;
89+ for ( const key of keys ) {
90+ assert . ok (
91+ key === 'HOME' || key === 'PATH' ,
92+ `Unexpected env var in JSON.stringify: ${ key } `
93+ ) ;
94+ }
95+ }
0 commit comments