2014-01-21 21:25:09 +00:00
|
|
|
define(["Filer", "util"], function(Filer, util) {
|
2013-11-27 17:18:09 +00:00
|
|
|
|
|
|
|
describe('path resolution', function() {
|
2014-01-21 21:25:09 +00:00
|
|
|
beforeEach(util.setup);
|
|
|
|
afterEach(util.cleanup);
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
it('should follow a symbolic link to the root directory', function(done) {
|
|
|
|
var fs = util.fs();
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.symlink('/', '/mydirectorylink', function(error) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.stat('/', function(error, result) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
expect(result['node']).to.exist;
|
|
|
|
var _node = result['node'];
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.stat('/mydirectorylink', function(error, result) {
|
|
|
|
expect(error).not.to.exist;
|
|
|
|
expect(result).to.exist;
|
|
|
|
expect(result['node']).to.equal(_node);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
it('should follow a symbolic link to a directory', function(done) {
|
|
|
|
var fs = util.fs();
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.mkdir('/mydir', function(error) {
|
|
|
|
fs.symlink('/mydir', '/mydirectorylink', function(error) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.stat('/mydir', function(error, result) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
expect(result['node']).to.exist;
|
|
|
|
var _node = result['node'];
|
|
|
|
fs.stat('/mydirectorylink', function(error, result) {
|
|
|
|
expect(error).not.to.exist;
|
|
|
|
expect(result).to.exist;
|
|
|
|
expect(result['node']).to.equal(_node);
|
|
|
|
done();
|
|
|
|
});
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
it('should follow a symbolic link to a file', function(done) {
|
|
|
|
var fs = util.fs();
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.open('/myfile', 'w', function(error, result) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
|
|
|
var fd = result;
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.close(fd, function(error) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.stat('/myfile', function(error, result) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
expect(result['node']).to.exist;
|
|
|
|
var _node = result['node'];
|
|
|
|
fs.symlink('/myfile', '/myfilelink', function(error) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.stat('/myfilelink', function(error, result) {
|
|
|
|
expect(error).not.to.exist;
|
|
|
|
expect(result).to.exist;
|
|
|
|
expect(result['node']).to.equal(_node);
|
|
|
|
done();
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
it('should follow multiple symbolic links to a file', function(done) {
|
|
|
|
var fs = util.fs();
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.open('/myfile', 'w', function(error, result) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
|
|
|
var fd = result;
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.close(fd, function(error) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.stat('/myfile', function(error, result) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
expect(result['node']).to.exist;
|
|
|
|
var _node = result['node'];
|
|
|
|
fs.symlink('/myfile', '/myfilelink1', function(error) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.symlink('/myfilelink1', '/myfilelink2', function(error) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.stat('/myfilelink2', function(error, result) {
|
|
|
|
expect(error).not.to.exist;
|
|
|
|
expect(result).to.exist;
|
|
|
|
expect(result['node']).to.equal(_node);
|
|
|
|
done();
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
it('should error if symbolic link leads to itself', function(done) {
|
|
|
|
var fs = util.fs();
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.symlink('/mylink1', '/mylink2', function(error) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.symlink('/mylink2', '/mylink1', function(error) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.stat('/myfilelink1', function(error, result) {
|
|
|
|
expect(error).to.exist;
|
|
|
|
expect(result).not.to.exist;
|
|
|
|
done();
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
it('should error if it follows more than 10 symbolic links', function(done) {
|
|
|
|
var fs = util.fs();
|
2013-12-14 20:14:44 +00:00
|
|
|
var nlinks = 11;
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2013-12-14 20:14:44 +00:00
|
|
|
function createSymlinkChain(n, callback) {
|
|
|
|
if(n > nlinks) {
|
|
|
|
return callback();
|
|
|
|
}
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.symlink('/myfile' + (n-1), '/myfile' + n, createSymlinkChain.bind(this, n+1, callback));
|
2013-12-14 20:14:44 +00:00
|
|
|
}
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.open('/myfile0', 'w', function(error, result) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
|
|
|
var fd = result;
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.close(fd, function(error) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.stat('/myfile0', function(error, result) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
|
|
|
|
2013-12-14 20:14:44 +00:00
|
|
|
createSymlinkChain(1, function() {
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.stat('/myfile11', function(error, result) {
|
|
|
|
expect(error).to.exist;
|
2014-03-05 19:28:31 +00:00
|
|
|
expect(error.code).to.equal('ELOOP');
|
2014-01-21 21:25:09 +00:00
|
|
|
expect(result).not.to.exist;
|
|
|
|
done();
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
|
|
|
});
|
2013-12-14 20:14:44 +00:00
|
|
|
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
it('should follow a symbolic link in the path to a file', function(done) {
|
|
|
|
var fs = util.fs();
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.open('/myfile', 'w', function(error, result) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
|
|
|
var fd = result;
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.close(fd, function(error) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.stat('/myfile', function(error, result) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
var _node = result['node'];
|
|
|
|
fs.symlink('/', '/mydirlink', function(error) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.stat('/mydirlink/myfile', function(error, result) {
|
|
|
|
expect(result).to.exist;
|
|
|
|
expect(error).not.to.exist;
|
|
|
|
expect(_node).to.exist;
|
|
|
|
expect(result['node']).to.equal(_node);
|
|
|
|
done();
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
it('should error if a symbolic link in the path to a file is itself a file', function(done) {
|
|
|
|
var fs = util.fs();
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.open('/myfile', 'w', function(error, result) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
|
|
|
var fd = result;
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.close(fd, function(error) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.stat('/myfile', function(error, result) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.open('/myfile2', 'w', function(error, result) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
|
|
|
var fd = result;
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.close(fd, function(error) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.symlink('/myfile2', '/mynotdirlink', function(error) {
|
2013-11-27 17:18:09 +00:00
|
|
|
if(error) throw error;
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
fs.stat('/mynotdirlink/myfile', function(error, result) {
|
|
|
|
expect(error).to.exist;
|
|
|
|
expect(result).not.to.exist;
|
|
|
|
done();
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|