2018-05-28 19:03:34 +00:00
|
|
|
var util = require('../lib/test-utils.js');
|
|
|
|
var expect = require('chai').expect;
|
|
|
|
|
2019-04-07 04:26:19 +00:00
|
|
|
describe('fs.chown, fs.fchown, fs.lchown', function() {
|
2018-05-28 19:03:34 +00:00
|
|
|
beforeEach(util.setup);
|
|
|
|
afterEach(util.cleanup);
|
|
|
|
|
|
|
|
it('should be functions', function() {
|
|
|
|
var fs = util.fs();
|
|
|
|
expect(typeof fs.chown).to.equal('function');
|
|
|
|
expect(typeof fs.fchown).to.equal('function');
|
|
|
|
});
|
|
|
|
|
2018-07-27 15:01:26 +00:00
|
|
|
it('should automatically set a file\'s uid and gid to 0 (i.e., root)', function(done) {
|
2018-05-28 19:03:34 +00:00
|
|
|
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.uid).to.equal(0);
|
|
|
|
expect(stats.gid).to.equal(0);
|
|
|
|
fs.close(fd, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-04-07 04:26:19 +00:00
|
|
|
it('lchown should expect an interger value for uid', function(done) {
|
|
|
|
var fs = util.fs();
|
|
|
|
|
|
|
|
fs.open('/file', 'w', function(err, fd) {
|
|
|
|
if(err) throw err;
|
|
|
|
|
|
|
|
fs.lchown(fd, '1001', 1001, function(err) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(err.code).to.equal('EINVAL');
|
|
|
|
fs.close(fd, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-11-30 00:14:43 +00:00
|
|
|
it('fchown should expect an interger value for uid', function(done) {
|
|
|
|
var fs = util.fs();
|
|
|
|
|
|
|
|
fs.open('/file', 'w', function(err, fd) {
|
|
|
|
if(err) throw err;
|
|
|
|
|
|
|
|
fs.fchown(fd, '1001', 1001, function(err) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(err.code).to.equal('EINVAL');
|
2018-12-29 18:10:58 +00:00
|
|
|
fs.close(fd, done);
|
2018-11-30 00:14:43 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('chown should expect an interger value for uid', function(done) {
|
|
|
|
var fs = util.fs();
|
|
|
|
|
|
|
|
fs.writeFile('/file', 'w', function(err) {
|
|
|
|
if(err) throw err;
|
|
|
|
|
|
|
|
fs.chown('/file', '1001', 1001, function(err) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(err.code).to.equal('EINVAL');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-04-07 04:26:19 +00:00
|
|
|
it('lchown should expect an interger value for gid', function(done) {
|
|
|
|
var fs = util.fs();
|
|
|
|
|
|
|
|
fs.open('/file', 'w', function(err, fd) {
|
|
|
|
if(err) throw err;
|
|
|
|
|
|
|
|
fs.lchown(fd, 1001, '1001', function(err) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(err.code).to.equal('EINVAL');
|
|
|
|
fs.close(fd, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-11-30 00:14:43 +00:00
|
|
|
it('fchown should expect an interger value for gid', function(done) {
|
|
|
|
var fs = util.fs();
|
|
|
|
|
|
|
|
fs.open('/file', 'w', function(err, fd) {
|
|
|
|
if(err) throw err;
|
|
|
|
|
|
|
|
fs.fchown(fd, 1001, '1001', function(err) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(err.code).to.equal('EINVAL');
|
2018-12-29 18:10:58 +00:00
|
|
|
fs.close(fd, done);
|
2018-11-30 00:14:43 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('chown should expect an interger value for gid', function(done) {
|
|
|
|
var fs = util.fs();
|
|
|
|
|
|
|
|
fs.writeFile('/file', 'w', function(err) {
|
|
|
|
if(err) throw err;
|
|
|
|
|
|
|
|
fs.chown('/file', 1001, '1001', function(err) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(err.code).to.equal('EINVAL');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-05-28 19:03:34 +00:00
|
|
|
it('should allow updating gid and uid for a file', function(done) {
|
|
|
|
var fs = util.fs();
|
|
|
|
|
|
|
|
fs.open('/file', 'w', function(err, fd) {
|
|
|
|
if(err) throw err;
|
|
|
|
|
|
|
|
fs.fchown(fd, 1001, 1001, function(err) {
|
|
|
|
if(err) throw err;
|
|
|
|
|
|
|
|
fs.fstat(fd, function(err, stats) {
|
|
|
|
if(err) throw err;
|
|
|
|
|
|
|
|
expect(stats.uid).to.equal(1001);
|
|
|
|
expect(stats.gid).to.equal(1001);
|
|
|
|
|
|
|
|
fs.close(fd, function(err) {
|
|
|
|
if(err) throw err;
|
|
|
|
|
|
|
|
fs.chown('/file', 500, 500, function(err) {
|
|
|
|
if(err) throw err;
|
|
|
|
|
|
|
|
fs.stat('/file', function(err, stats) {
|
|
|
|
if(err) throw err;
|
|
|
|
|
2019-04-07 04:26:19 +00:00
|
|
|
expect(stats.uid).to.equal(500);
|
|
|
|
expect(stats.gid).to.equal(500);
|
|
|
|
//done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
fs.lchown('/file', 500, 500, function(err) {
|
|
|
|
if(err) throw err;
|
|
|
|
|
|
|
|
fs.lstat('/file', function(err, stats) {
|
|
|
|
if(err) throw err;
|
|
|
|
|
2018-05-28 19:03:34 +00:00
|
|
|
expect(stats.uid).to.equal(500);
|
|
|
|
expect(stats.gid).to.equal(500);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-10-16 15:43:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
describe('fs.promises.chown', function(){
|
|
|
|
beforeEach(util.setup);
|
|
|
|
afterEach(util.setup);
|
|
|
|
|
|
|
|
it('should be a function', function(){
|
|
|
|
var fsPromises = util.fs().promises;
|
|
|
|
expect(fsPromises.chown).to.be.a('function');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should allow updating uid and gid for a file', function() {
|
|
|
|
var fsPromises = util.fs().promises;
|
2018-12-02 03:02:26 +00:00
|
|
|
|
|
|
|
return fsPromises
|
|
|
|
.writeFile('/file', 'data')
|
|
|
|
.then(() => fsPromises.chown('/file', 500, 500))
|
|
|
|
.then(() => fsPromises.stat('/file'))
|
|
|
|
.then((stats) => {
|
2018-10-16 15:43:59 +00:00
|
|
|
expect(stats.uid).to.equal(500);
|
|
|
|
expect(stats.gid).to.equal(500);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|