create separate function for path checking
This commit is contained in:
@@ -157,6 +157,19 @@ describe "ResourceWriter", ->
|
||||
.calledWith(new Error("resource path is outside root directory"))
|
||||
.should.equal true
|
||||
|
||||
|
||||
describe "checkPath", ->
|
||||
describe "with a valid path", ->
|
||||
beforeEach ->
|
||||
@ResourceWriter.checkPath("foo", "bar", @callback)
|
||||
|
||||
|
||||
it "should return the joined path", ->
|
||||
@callback.calledWith(null, "foo/bar")
|
||||
.should.equal true
|
||||
|
||||
describe "with an invalid path", ->
|
||||
beforeEach ->
|
||||
@ResourceWriter.checkPath("foo", "baz/../../bar", @callback)
|
||||
|
||||
it "should return an error", ->
|
||||
@callback.calledWith(new Error("resource path is outside root directory"))
|
||||
.should.equal true
|
||||
|
||||
@@ -6,6 +6,7 @@ modulePath = require('path').join __dirname, '../../../app/js/TikzManager'
|
||||
describe 'TikzManager', ->
|
||||
beforeEach ->
|
||||
@TikzManager = SandboxedModule.require modulePath, requires:
|
||||
"./ResourceWriter": @ResourceWriter = {}
|
||||
"fs": @fs = {}
|
||||
"logger-sharelatex": @logger = {log: () ->}
|
||||
|
||||
@@ -49,8 +50,13 @@ describe 'TikzManager', ->
|
||||
'''
|
||||
@fs.readFile = sinon.stub().callsArgWith(2, null, @content)
|
||||
@fs.writeFile = sinon.stub().callsArg(3)
|
||||
@ResourceWriter.checkPath = sinon.stub().callsArgWith(2, null, "#{@rootDir}/#{@filename}")
|
||||
@TikzManager.injectOutputFile @rootDir, @filename, @callback
|
||||
|
||||
it "sould check the path", ->
|
||||
@ResourceWriter.checkPath.calledWith(@rootDir, @filename)
|
||||
.should.equal true
|
||||
|
||||
it "should read the file", ->
|
||||
@fs.readFile
|
||||
.calledWith("#{@rootDir}/#{@filename}", "utf8")
|
||||
|
||||
Reference in New Issue
Block a user