This commit is contained in:
David Humphrey 2018-12-14 22:05:51 -05:00
commit acef2c93b0
2 changed files with 76 additions and 2 deletions

View File

@ -2184,14 +2184,14 @@ function futimes(fs, context, fd, atime, mtime, callback) {
function chmod(fs, context, path, mode, callback) {
if(!pathCheck(path, callback)) return;
mode = validateAndMaskMode(mode, 'mode');
mode = validateAndMaskMode(mode, 'mode', callback);
if(!mode) return;
chmod_file(context, path, mode, callback);
}
function fchmod(fs, context, fd, mode, callback) {
mode = validateAndMaskMode(mode, 'mode');
mode = validateAndMaskMode(mode, 'mode', callback);
if(!mode) return;
var ofd = fs.openFiles[fd];

View File

@ -46,7 +46,81 @@ describe('fs.chmod, fs.fchmod', function() {
expect(err.code).to.equal('ENOENT');
done();
});
});
it('should error if mode value is a non-numeric string', function(done) {
var fs = util.fs();
fs.mkdir('/dir', function(err) {
if(err) throw err;
fs.chmod('/dir', 'mode', function(err) {
expect(err).to.exist;
expect(err.code).to.equal('EINVAL');
done();
});
});
});
it('should error if mode value is null', function(done) {
var fs = util.fs();
fs.mkdir('/dir', function(err) {
if(err) throw err;
fs.chmod('/dir', 'null', function(err) {
expect(err).to.exist;
expect(err.code).to.equal('EINVAL');
done();
});
});
});
it('should error if mode value is non-integer number', function(done) {
var fs = util.fs();
fs.mkdir('/dir', function(err) {
if(err) throw err;
fs.chmod('/dir', 3.14, function(err) {
expect(err).to.exist;
expect(err.code).to.equal('EINVAL');
done();
});
});
});
it('should error if mode value is non-integer number', function(done) {
var fs = util.fs();
fs.mkdir('/dir', function(err) {
if(err) throw err;
fs.chmod('/dir', 3.14, function(err) {
expect(err).to.exist;
expect(err.code).to.equal('EINVAL');
done();
});
});
});
it('should allow octal strings for mode value', function(done) {
var fs = util.fs();
fs.mkdir('/dir', function(err) {
if(err) throw err;
fs.chmod('/dir', '777', function(err) {
if(err) throw err;
fs.stat('/dir/', function(err, stats) {
if(err) throw err;
expect(stats.mode & 0o777).to.equal(0o777);
done();
});
});
});
});
it('should allow for updating mode of a given file', function(done) {