Skip to content

Commit 6543bec

Browse files
committed
Add tests for enabling/disabling permissions for all user classes
1 parent 2f55e3f commit 6543bec

1 file changed

Lines changed: 178 additions & 2 deletions

File tree

  • lib/node_modules/@stdlib/process/umask/test

lib/node_modules/@stdlib/process/umask/test/test.js

Lines changed: 178 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,9 @@ tape( 'if not provided any arguments, the function returns the process mask', fu
275275
});
276276

277277
tape( 'the function ignores unrecognized/unsupported options and returns the process mask', function test( t ) {
278-
var expected = process.umask( {} );
278+
var expected = process.umask();
279279
t.equal( typeof expected, 'number', 'returns a number' );
280-
t.equal( umask(), expected, 'returns expected value' );
280+
t.equal( umask( {} ), expected, 'returns expected value' );
281281
restore();
282282
t.end();
283283
});
@@ -433,3 +433,179 @@ tape( 'if provided an expression mask, the function supports setting the process
433433
restore();
434434
t.end();
435435
});
436+
437+
tape( 'the function supports enabling permissions using the "all" user class', function test( t ) {
438+
var expected;
439+
var values;
440+
var opts;
441+
var i;
442+
443+
values = [
444+
'a+', // no effect
445+
'a+r',
446+
'a+w',
447+
'a+x',
448+
'a+rw',
449+
'a+rx',
450+
'a+wx',
451+
'a+rwx'
452+
];
453+
expected = [
454+
'u=,g=,o=', // no effect
455+
'u=r,g=r,o=r',
456+
'u=w,g=w,o=w',
457+
'u=x,g=x,o=x',
458+
'u=rw,g=rw,o=rw',
459+
'u=rx,g=rx,o=rx',
460+
'u=wx,g=wx,o=wx',
461+
'u=rwx,g=rwx,o=rwx'
462+
];
463+
464+
opts = {
465+
'symbolic': true
466+
};
467+
468+
for ( i = 0; i < values.length; i++ ) {
469+
// Clear all bits:
470+
umask( 'u=,g=,o=' );
471+
t.equal( umask(), 511, 'returns expected value' ); // 511 == 0o0777
472+
473+
// Enable permissions:
474+
umask( values[ i ] );
475+
t.equal( umask( opts ), expected[ i ], 'returns expected value' );
476+
}
477+
restore();
478+
t.end();
479+
});
480+
481+
tape( 'the function supports disabling permissions using the "all" user class', function test( t ) {
482+
var expected;
483+
var values;
484+
var opts;
485+
var i;
486+
487+
values = [
488+
'a-', // no effect
489+
'a-r',
490+
'a-w',
491+
'a-x',
492+
'a-rw',
493+
'a-rx',
494+
'a-wx',
495+
'a-rwx'
496+
];
497+
expected = [
498+
'u=rwx,g=rwx,o=rwx', // no effect
499+
'u=wx,g=wx,o=wx',
500+
'u=rx,g=rx,o=rx',
501+
'u=rw,g=rw,o=rw',
502+
'u=x,g=x,o=x',
503+
'u=w,g=w,o=w',
504+
'u=r,g=r,o=r',
505+
'u=,g=,o='
506+
];
507+
508+
opts = {
509+
'symbolic': true
510+
};
511+
512+
for ( i = 0; i < values.length; i++ ) {
513+
// Set all bits:
514+
umask( 'u=rwx,g=rwx,o=rwx' );
515+
t.equal( umask(), 0, 'returns expected value' ); // 0 == 0o0000
516+
517+
// Disable permissions:
518+
umask( values[ i ] );
519+
t.equal( umask( opts ), expected[ i ], 'returns expected value' );
520+
}
521+
restore();
522+
t.end();
523+
});
524+
525+
tape( 'the function supports enabling permissions without specifying a user class', function test( t ) {
526+
var expected;
527+
var values;
528+
var opts;
529+
var i;
530+
531+
values = [
532+
'+', // no effect
533+
'+r',
534+
'+w',
535+
'+x',
536+
'+rw',
537+
'+rx',
538+
'+wx',
539+
'+rwx'
540+
];
541+
expected = [
542+
'u=,g=,o=', // no effect
543+
'u=r,g=r,o=r',
544+
'u=w,g=w,o=w',
545+
'u=x,g=x,o=x',
546+
'u=rw,g=rw,o=rw',
547+
'u=rx,g=rx,o=rx',
548+
'u=wx,g=wx,o=wx',
549+
'u=rwx,g=rwx,o=rwx'
550+
];
551+
552+
opts = {
553+
'symbolic': true
554+
};
555+
556+
for ( i = 0; i < values.length; i++ ) {
557+
// Clear all bits:
558+
umask( 'u=,g=,o=' );
559+
t.equal( umask(), 511, 'returns expected value' ); // 511 == 0o0777
560+
561+
// Enable permissions:
562+
umask( values[ i ] );
563+
t.equal( umask( opts ), expected[ i ], 'returns expected value' );
564+
}
565+
restore();
566+
t.end();
567+
});
568+
569+
tape( 'the function supports disabling permissions without specifying a user class', function test( t ) {
570+
var expected;
571+
var values;
572+
var opts;
573+
var i;
574+
575+
values = [
576+
'-', // no effect
577+
'-r',
578+
'-w',
579+
'-x',
580+
'-rw',
581+
'-rx',
582+
'-wx',
583+
'-rwx'
584+
];
585+
expected = [
586+
'u=rwx,g=rwx,o=rwx', // no effect
587+
'u=wx,g=wx,o=wx',
588+
'u=rx,g=rx,o=rx',
589+
'u=rw,g=rw,o=rw',
590+
'u=x,g=x,o=x',
591+
'u=w,g=w,o=w',
592+
'u=r,g=r,o=r',
593+
'u=,g=,o='
594+
];
595+
596+
opts = {
597+
'symbolic': true
598+
};
599+
600+
for ( i = 0; i < values.length; i++ ) {
601+
// Set all bits:
602+
umask( 'u=rwx,g=rwx,o=rwx' );
603+
t.equal( umask(), 0, 'returns expected value' ); // 0 == 0o0000
604+
605+
// Disable permissions:
606+
umask( values[ i ] );
607+
t.equal( umask( opts ), expected[ i ], 'returns expected value' );
608+
}
609+
restore();
610+
t.end();
611+
});

0 commit comments

Comments
 (0)