filer/tests/spec/path-resolution.spec.js

225 lines
6.6 KiB
JavaScript
Raw Normal View History

define(["Filer", "util"], function(Filer, util) {
2013-11-27 17:18:09 +00:00
describe('path resolution', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
2013-11-27 17:18: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
fs.symlink('/', '/mydirectorylink', function(error) {
2013-11-27 17:18:09 +00:00
if(error) throw error;
fs.stat('/', function(error, result) {
2013-11-27 17:18:09 +00:00
if(error) throw error;
expect(result['node']).to.exist;
var _node = result['node'];
2013-11-27 17:18: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
});
});
it('should follow a symbolic link to a directory', function(done) {
var fs = util.fs();
2013-11-27 17:18: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;
fs.stat('/mydir', function(error, result) {
2013-11-27 17:18:09 +00:00
if(error) throw error;
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
});
});
});
});
it('should follow a symbolic link to a file', function(done) {
var fs = util.fs();
2013-11-27 17:18: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;
fs.close(fd, function(error) {
2013-11-27 17:18:09 +00:00
if(error) throw error;
fs.stat('/myfile', function(error, result) {
2013-11-27 17:18:09 +00:00
if(error) throw error;
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;
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
});
});
});
});
});
});
it('should follow multiple symbolic links to a file', function(done) {
var fs = util.fs();
2013-11-27 17:18: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;
fs.close(fd, function(error) {
2013-11-27 17:18:09 +00:00
if(error) throw error;
fs.stat('/myfile', function(error, result) {
2013-11-27 17:18:09 +00:00
if(error) throw error;
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;
fs.symlink('/myfilelink1', '/myfilelink2', function(error) {
2013-11-27 17:18:09 +00:00
if(error) throw error;
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
});
});
});
});
});
});
});
it('should error if symbolic link leads to itself', function(done) {
var fs = util.fs();
2013-11-27 17:18:09 +00:00
fs.symlink('/mylink1', '/mylink2', function(error) {
2013-11-27 17:18:09 +00:00
if(error) throw error;
fs.symlink('/mylink2', '/mylink1', function(error) {
2013-11-27 17:18:09 +00:00
if(error) throw error;
fs.stat('/myfilelink1', function(error, result) {
expect(error).to.exist;
expect(result).not.to.exist;
done();
2013-11-27 17:18:09 +00:00
});
});
});
});
it('should error if it follows more than 10 symbolic links', function(done) {
var fs = util.fs();
var nlinks = 11;
2013-11-27 17:18:09 +00:00
function createSymlinkChain(n, callback) {
if(n > nlinks) {
return callback();
}
fs.symlink('/myfile' + (n-1), '/myfile' + n, createSymlinkChain.bind(this, n+1, callback));
}
fs.open('/myfile0', 'w', function(error, result) {
2013-11-27 17:18:09 +00:00
if(error) throw error;
var fd = result;
fs.close(fd, function(error) {
2013-11-27 17:18:09 +00:00
if(error) throw error;
fs.stat('/myfile0', function(error, result) {
2013-11-27 17:18:09 +00:00
if(error) throw error;
createSymlinkChain(1, function() {
fs.stat('/myfile11', function(error, result) {
expect(error).to.exist;
expect(error.code).to.equal('ELOOP');
expect(result).not.to.exist;
done();
2013-11-27 17:18:09 +00:00
});
});
2013-11-27 17:18: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
fs.open('/myfile', 'w', function(error, result) {
2013-11-27 17:18:09 +00:00
if(error) throw error;
var fd = result;
fs.close(fd, function(error) {
2013-11-27 17:18:09 +00:00
if(error) throw error;
fs.stat('/myfile', function(error, result) {
2013-11-27 17:18:09 +00:00
if(error) throw error;
var _node = result['node'];
fs.symlink('/', '/mydirlink', function(error) {
2013-11-27 17:18:09 +00:00
if(error) throw error;
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
});
});
});
});
});
});
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
fs.open('/myfile', 'w', function(error, result) {
2013-11-27 17:18:09 +00:00
if(error) throw error;
var fd = result;
fs.close(fd, function(error) {
2013-11-27 17:18:09 +00:00
if(error) throw error;
fs.stat('/myfile', function(error, result) {
2013-11-27 17:18:09 +00:00
if(error) throw error;
fs.open('/myfile2', 'w', function(error, result) {
2013-11-27 17:18:09 +00:00
if(error) throw error;
var fd = result;
fs.close(fd, function(error) {
2013-11-27 17:18:09 +00:00
if(error) throw error;
fs.symlink('/myfile2', '/mynotdirlink', function(error) {
2013-11-27 17:18:09 +00:00
if(error) throw error;
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
});
});
});
});
});
});
});
});
});
});