-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: added input validation test for fchmod
Added a test to ensure input validation for FD and mode for fs.fchmod. Removed check for values lower than 0 for `mode` as it's already checked by `validateUint32`. PR-URL: #18217 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Anna Henningsen <anna@addaleax.net>
- Loading branch information
1 parent
a27f48d
commit 075eef5
Showing
3 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const fs = require('fs'); | ||
|
||
// This test ensures that input for fchmod is valid, testing for valid | ||
// inputs for fd and mode | ||
|
||
// Check input type | ||
['', false, null, undefined, {}, [], Infinity, -1].forEach((i) => { | ||
common.expectsError( | ||
() => fs.fchmod(i), | ||
{ | ||
code: 'ERR_INVALID_ARG_TYPE', | ||
type: TypeError, | ||
message: 'The "fd" argument must be of type integer' | ||
} | ||
); | ||
common.expectsError( | ||
() => fs.fchmodSync(i), | ||
{ | ||
code: 'ERR_INVALID_ARG_TYPE', | ||
type: TypeError, | ||
message: 'The "fd" argument must be of type integer' | ||
} | ||
); | ||
|
||
common.expectsError( | ||
() => fs.fchmod(1, i), | ||
{ | ||
code: 'ERR_INVALID_ARG_TYPE', | ||
type: TypeError, | ||
message: 'The "mode" argument must be of type integer' | ||
} | ||
); | ||
common.expectsError( | ||
() => fs.fchmodSync(1, i), | ||
{ | ||
code: 'ERR_INVALID_ARG_TYPE', | ||
type: TypeError, | ||
message: 'The "mode" argument must be of type integer' | ||
} | ||
); | ||
}); | ||
|
||
// Check for mode values range | ||
const modeUpperBoundaryValue = 0o777; | ||
fs.fchmod(1, modeUpperBoundaryValue); | ||
fs.fchmodSync(1, modeUpperBoundaryValue); | ||
|
||
// umask of 0o777 is equal to 775 | ||
const modeOutsideUpperBoundValue = 776; | ||
common.expectsError( | ||
() => fs.fchmod(1, modeOutsideUpperBoundValue), | ||
{ | ||
code: 'ERR_OUT_OF_RANGE', | ||
type: RangeError, | ||
message: 'The value of "mode" is out of range.' | ||
} | ||
); | ||
common.expectsError( | ||
() => fs.fchmodSync(1, modeOutsideUpperBoundValue), | ||
{ | ||
code: 'ERR_OUT_OF_RANGE', | ||
type: RangeError, | ||
message: 'The value of "mode" is out of range.' | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters