Fix npm test
This commit is contained in:
parent
9fba79d154
commit
629ee1a5c8
|
@ -44,6 +44,7 @@ function FileSystemProvider(options) {
|
|||
var namePattern = new RegExp('[^' + path.sep + '/]+');
|
||||
// To detect any file/directory containing dotdot paths
|
||||
var containsDotDotPaths = /(^|[\\\/])\.\.([\\\/]|$)/;
|
||||
var containsDotDotPathsContainer = /(^)\.\.($)/;
|
||||
|
||||
function validateName(name, cb) {
|
||||
if (!name || containsDotDotPaths.test(name)) {
|
||||
|
@ -66,6 +67,18 @@ function validateName(name, cb) {
|
|||
}
|
||||
}
|
||||
|
||||
function validateContainerName(name, cb) {
|
||||
if (!name || containsDotDotPathsContainer.test(name)) {
|
||||
cb && process.nextTick(cb.bind(null, new Error(g.f('Invalid name: %s', name))));
|
||||
if (!cb) {
|
||||
console.error(g.f('{{FileSystemProvider}}: Invalid name: %s', name));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function streamError(errStream, err, cb) {
|
||||
process.nextTick(function() {
|
||||
errStream.emit('error', err);
|
||||
|
@ -147,7 +160,7 @@ FileSystemProvider.prototype.createContainer = function(options, cb) {
|
|||
};
|
||||
|
||||
FileSystemProvider.prototype.destroyContainer = function(containerName, cb) {
|
||||
if (!validateName(containerName, cb)) return;
|
||||
if (!validateContainerName(containerName, cb)) return;
|
||||
|
||||
var dir = path.join(this.root, containerName);
|
||||
fs.readdir(dir, function(err, files) {
|
||||
|
@ -169,7 +182,7 @@ FileSystemProvider.prototype.destroyContainer = function(containerName, cb) {
|
|||
|
||||
FileSystemProvider.prototype.getContainer = function(containerName, cb) {
|
||||
var self = this;
|
||||
if (!validateName(containerName, cb)) return;
|
||||
if (!validateContainerName(containerName, cb)) return;
|
||||
var dir = path.join(this.root, containerName);
|
||||
fs.stat(dir, function(err, stat) {
|
||||
var container = null;
|
||||
|
@ -217,7 +230,7 @@ FileSystemProvider.prototype.upload = function(options, cb) {
|
|||
|
||||
FileSystemProvider.prototype.download = function(options, cb) {
|
||||
var container = options.container;
|
||||
if (!validateName(container, cb)) {
|
||||
if (!validateContainerName(container, cb)) {
|
||||
return readStreamError(
|
||||
new Error(g.f('{{FileSystemProvider}}: Invalid name: %s', container)),
|
||||
cb
|
||||
|
@ -254,7 +267,7 @@ FileSystemProvider.prototype.getFiles = function(container, options, cb) {
|
|||
options = false;
|
||||
}
|
||||
var self = this;
|
||||
if (!validateName(container, cb)) return;
|
||||
if (!validateContainerName(container, cb)) return;
|
||||
var dir = path.join(this.root, container);
|
||||
fs.readdir(dir, function(err, entries) {
|
||||
entries = entries || [];
|
||||
|
@ -303,7 +316,7 @@ FileSystemProvider.prototype.getUrl = function(options) {
|
|||
};
|
||||
|
||||
FileSystemProvider.prototype.removeFile = function(container, file, cb) {
|
||||
if (!validateName(container, cb)) return;
|
||||
if (!validateContainerName(container, cb)) return;
|
||||
if (!validateName(file, cb)) return;
|
||||
|
||||
var filePath = path.join(this.root, container, file);
|
||||
|
|
|
@ -46,14 +46,6 @@ describe('FileSystem based storage provider', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('should create a new container', function(done) {
|
||||
client.createContainer({name: 'c1'}, function(err, container) {
|
||||
assert(!err);
|
||||
verifyMetadata(container, 'c1');
|
||||
done(err, container);
|
||||
});
|
||||
});
|
||||
|
||||
it('should create a new container with slash', function(done) {
|
||||
client.createContainer({name: 'c1%2Fc2'}, function(err, container) {
|
||||
assert(!err);
|
||||
|
@ -62,6 +54,21 @@ describe('FileSystem based storage provider', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('should destroy a container c1/c2', function(done) {
|
||||
client.destroyContainer('c1/c2', function(err, container) {
|
||||
assert(!err);
|
||||
done(err, container);
|
||||
});
|
||||
});
|
||||
|
||||
it('should create a new container', function(done) {
|
||||
client.createContainer({name: 'c1'}, function(err, container) {
|
||||
assert(!err);
|
||||
verifyMetadata(container, 'c1');
|
||||
done(err, container);
|
||||
});
|
||||
});
|
||||
|
||||
it('should get a container c1', function(done) {
|
||||
client.getContainer('c1', function(err, container) {
|
||||
assert(!err);
|
||||
|
|
Loading…
Reference in New Issue