2018-05-28 19:03:34 +00:00
|
|
|
var util = require('../lib/test-utils.js');
|
|
|
|
var expect = require('chai').expect;
|
|
|
|
|
|
|
|
describe('fs.chmod, fs.fchmod', function() {
|
|
|
|
beforeEach(util.setup);
|
|
|
|
afterEach(util.cleanup);
|
|
|
|
|
|
|
|
it('should be functions', function() {
|
|
|
|
var fs = util.fs();
|
|
|
|
expect(typeof fs.chmod).to.equal('function');
|
|
|
|
expect(typeof fs.fchmod).to.equal('function');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should automatically set mode=755 for a directory', function(done) {
|
|
|
|
var fs = util.fs();
|
|
|
|
|
|
|
|
fs.mkdir('/dir', function(err) {
|
|
|
|
if(err) throw err;
|
|
|
|
|
|
|
|
fs.stat('/dir', function(err, stats) {
|
|
|
|
if(err) throw err;
|
|
|
|
expect(stats.mode & 0o755).to.equal(0o755);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should automatically set mode=644 for a file', function(done) {
|
|
|
|
var fs = util.fs();
|
|
|
|
|
|
|
|
fs.open('/file', 'w', function(err, fd) {
|
|
|
|
if(err) throw err;
|
|
|
|
|
|
|
|
fs.fstat(fd, function(err, stats) {
|
|
|
|
if(err) throw err;
|
|
|
|
expect(stats.mode & 0o644).to.equal(0o644);
|
|
|
|
fs.close(fd, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-09-25 04:15:07 +00:00
|
|
|
it('should be a valid mode value to set permissions', function(done){
|
2018-09-24 18:16:16 +00:00
|
|
|
var fs = util.fs();
|
2018-09-25 04:15:07 +00:00
|
|
|
|
|
|
|
fs.mkdir('/file',function(err) {
|
2018-09-24 18:16:16 +00:00
|
|
|
if(err) throw err;
|
2018-09-25 04:29:33 +00:00
|
|
|
|
2018-09-25 04:15:07 +00:00
|
|
|
fs.chmod('file', 1000, function(err) {
|
2018-09-24 18:16:16 +00:00
|
|
|
expect(err).to.exist;
|
|
|
|
expect(err.code).to.equal('EINVAL');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-05-28 19:03:34 +00:00
|
|
|
it('should allow for updating mode of a given file', function(done) {
|
|
|
|
var fs = util.fs();
|
|
|
|
|
|
|
|
fs.open('/file', 'w', function(err, fd) {
|
|
|
|
if(err) throw err;
|
|
|
|
|
|
|
|
fs.fchmod(fd, 0o777, function(err) {
|
|
|
|
if(err) throw err;
|
|
|
|
|
|
|
|
fs.fstat(fd, function(err, stats) {
|
|
|
|
if(err) throw err;
|
|
|
|
expect(stats.mode & 0o777).to.equal(0o777);
|
|
|
|
|
|
|
|
fs.close(fd, function(err) {
|
|
|
|
if(err) throw err;
|
|
|
|
|
|
|
|
fs.chmod('/file', 0o444, function(err) {
|
|
|
|
if(err) throw err;
|
|
|
|
|
|
|
|
fs.stat('/file', function(err, stats) {
|
|
|
|
if(err) throw err;
|
|
|
|
|
|
|
|
expect(stats.mode & 0o444).to.equal(0o444);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|