node/test/parallel/test-fs-fchown.js
Luca Maraschi 075eef5956
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: https://github.com/nodejs/node/pull/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>
2018-02-06 11:58:31 +01:00

58 lines
1.2 KiB
JavaScript

'use strict';
const common = require('../common');
const fs = require('fs');
['', false, null, undefined, {}, [], Infinity, -1].forEach((i) => {
common.expectsError(
() => fs.fchown(i),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "fd" argument must be of type integer'
}
);
common.expectsError(
() => fs.fchownSync(i),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "fd" argument must be of type integer'
}
);
common.expectsError(
() => fs.fchown(1, i),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "uid" argument must be of type integer'
}
);
common.expectsError(
() => fs.fchownSync(1, i),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "uid" argument must be of type integer'
}
);
common.expectsError(
() => fs.fchown(1, 1, i),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "gid" argument must be of type integer'
}
);
common.expectsError(
() => fs.fchownSync(1, 1, i),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "gid" argument must be of type integer'
}
);
});