fix filename length check

This commit is contained in:
Brian Gough 2018-02-09 15:05:52 +00:00
parent 14ef9a2c49
commit 2c2b6e5f36
2 changed files with 25 additions and 3 deletions

View file

@ -631,6 +631,9 @@ module.exports = ProjectEntityHandler =
newPath = newPath =
fileSystem: "#{path.fileSystem}/#{element.name}" fileSystem: "#{path.fileSystem}/#{element.name}"
mongo: path.mongo mongo: path.mongo
# check if the path would be too long
if not SafePath.isAllowedLength newPath.fileSystem
return callback new Errors.InvalidNameError("path too long")
ProjectEntityHandler.checkValidElementName folder, element.name, (err) => ProjectEntityHandler.checkValidElementName folder, element.name, (err) =>
return callback(err) if err? return callback(err) if err?
id = element._id+'' id = element._id+''
@ -648,9 +651,6 @@ module.exports = ProjectEntityHandler =
checkValidElementName: (folder, name, callback = (err) ->) -> checkValidElementName: (folder, name, callback = (err) ->) ->
# # # check if the path would be too long
# # if not SafePath.isAllowedLength "#{folder}/#{name}"
# # return callback new Error.InvalidNameError("path too long")
# check if the name is already taken by a doc, file or # check if the name is already taken by a doc, file or
# folder. If so, return an error "file already exists". # folder. If so, return an error "file already exists".
err = new Errors.InvalidNameError("file already exists") err = new Errors.InvalidNameError("file already exists")

View file

@ -1399,6 +1399,28 @@ describe 'ProjectEntityHandler', ->
@ProjectModel.findOneAndUpdate.called.should.equal false @ProjectModel.findOneAndUpdate.called.should.equal false
done() done()
it "should error if element name is too long", (done)->
doc =
_id: ObjectId()
name: new Array(200).join("long-") + "something"
@ProjectEntityHandler._putElement @project, @folder._id, doc, "doc", (err)=>
@ProjectModel.findOneAndUpdate.called.should.equal false
err.should.deep.equal new Errors.InvalidNameError("invalid element name")
done()
it "should error if the folder name is too long", (done)->
@path =
mongo: "mongo.path",
fileSystem: new Array(200).join("subdir/") + "foo"
@projectLocator.findElement.callsArgWith(1, null, @folder, @path)
doc =
_id: ObjectId()
name: "something"
@ProjectEntityHandler._putElement @project, @folder._id, doc, "doc", (err)=>
@ProjectModel.findOneAndUpdate.called.should.equal false
err.should.deep.equal new Errors.InvalidNameError("path too long")
done()
it "should error if a document already exists with the same name", (done)-> it "should error if a document already exists with the same name", (done)->
doc = doc =
_id: ObjectId() _id: ObjectId()