2014-06-19 12:07:50 -04:00
|
|
|
assert = require("chai").assert
|
|
|
|
sinon = require('sinon')
|
|
|
|
chai = require('chai')
|
|
|
|
should = chai.should()
|
|
|
|
expect = chai.expect
|
|
|
|
modulePath = "../../../app/js/LocalFileWriter.js"
|
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
fs = require("fs")
|
|
|
|
request = require("request")
|
|
|
|
settings = require("settings-sharelatex")
|
2018-05-21 04:37:54 -04:00
|
|
|
FilestoreApp = require "./FilestoreApp"
|
2014-06-19 12:07:50 -04:00
|
|
|
|
2014-06-19 12:32:04 -04:00
|
|
|
describe "Filestore", ->
|
2014-06-19 12:07:50 -04:00
|
|
|
|
|
|
|
before (done)->
|
|
|
|
@localFileReadPath = "/tmp/filestore_acceptence_tests_file_read.txt"
|
|
|
|
@localFileWritePath = "/tmp/filestore_acceptence_tests_file_write.txt"
|
|
|
|
|
|
|
|
@constantFileContent = [
|
|
|
|
"hello world"
|
|
|
|
"line 2 goes here #{Math.random()}"
|
|
|
|
"there are 3 lines in all"
|
|
|
|
].join("\n")
|
|
|
|
|
|
|
|
fs.writeFile(@localFileReadPath, @constantFileContent, done)
|
|
|
|
@filestoreUrl = "http://localhost:#{settings.internal.filestore.port}"
|
|
|
|
|
|
|
|
beforeEach (done)->
|
2018-05-21 04:37:54 -04:00
|
|
|
FilestoreApp.ensureRunning =>
|
|
|
|
fs.unlink @localFileWritePath, ->
|
|
|
|
done()
|
2014-06-19 12:07:50 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "should send a 200 for status endpoing", (done)->
|
2015-08-28 09:20:14 -04:00
|
|
|
request "#{@filestoreUrl}/status", (err, response, body)->
|
2014-06-19 12:07:50 -04:00
|
|
|
response.statusCode.should.equal 200
|
|
|
|
body.indexOf("filestore").should.not.equal -1
|
|
|
|
body.indexOf("up").should.not.equal -1
|
|
|
|
done()
|
|
|
|
|
2014-06-19 12:16:45 -04:00
|
|
|
describe "with a file on the server", ->
|
2014-06-19 12:07:50 -04:00
|
|
|
|
2014-06-19 12:16:45 -04:00
|
|
|
beforeEach (done)->
|
2014-06-19 12:32:04 -04:00
|
|
|
@timeout(1000 * 10)
|
|
|
|
@file_id = Math.random()
|
|
|
|
@fileUrl = "#{@filestoreUrl}/project/acceptence_tests/file/#{@file_id}"
|
2014-06-19 12:07:50 -04:00
|
|
|
|
2014-06-19 12:16:45 -04:00
|
|
|
writeStream = request.post(@fileUrl)
|
|
|
|
|
2014-06-19 12:32:04 -04:00
|
|
|
writeStream.on "end", done
|
2014-06-19 12:16:45 -04:00
|
|
|
fs.createReadStream(@localFileReadPath).pipe writeStream
|
|
|
|
|
2015-08-31 11:47:16 -04:00
|
|
|
it "should return 404 for a non-existant id", (done) ->
|
|
|
|
@timeout(1000 * 20)
|
|
|
|
options =
|
|
|
|
uri: @fileUrl + '___this_is_clearly_wrong___'
|
|
|
|
request.get options, (err, response, body) =>
|
|
|
|
response.statusCode.should.equal 404
|
|
|
|
done()
|
|
|
|
|
2014-06-19 12:16:45 -04:00
|
|
|
it "should be able get the file back", (done)->
|
|
|
|
@timeout(1000 * 10)
|
2014-06-19 12:07:50 -04:00
|
|
|
request.get @fileUrl, (err, response, body)=>
|
|
|
|
body.should.equal @constantFileContent
|
|
|
|
done()
|
|
|
|
|
2015-08-28 09:20:14 -04:00
|
|
|
it "should be able to get back the first 8 bytes of the file", (done) ->
|
|
|
|
@timeout(1000 * 10)
|
|
|
|
options =
|
|
|
|
uri: @fileUrl
|
|
|
|
headers:
|
|
|
|
'Range': 'bytes=0-8'
|
|
|
|
request.get options, (err, response, body)=>
|
|
|
|
body.should.equal 'hello wor'
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should be able to get back bytes 4 through 10 of the file", (done) ->
|
|
|
|
@timeout(1000 * 10)
|
|
|
|
options =
|
|
|
|
uri: @fileUrl
|
|
|
|
headers:
|
|
|
|
'Range': 'bytes=4-10'
|
|
|
|
request.get options, (err, response, body)=>
|
|
|
|
body.should.equal 'o world'
|
|
|
|
done()
|
|
|
|
|
2014-06-19 12:16:45 -04:00
|
|
|
it "should be able to delete the file", (done)->
|
2014-06-19 12:32:04 -04:00
|
|
|
@timeout(1000 * 20)
|
2014-06-19 12:16:45 -04:00
|
|
|
request.del @fileUrl, (err, response, body)=>
|
|
|
|
response.statusCode.should.equal 204
|
|
|
|
request.get @fileUrl, (err, response, body)=>
|
2015-08-31 11:47:16 -04:00
|
|
|
response.statusCode.should.equal 404
|
2014-06-19 12:16:45 -04:00
|
|
|
done()
|
|
|
|
|
2014-06-19 12:32:04 -04:00
|
|
|
it "should be able to copy files", (done)->
|
|
|
|
@timeout(1000 * 20)
|
|
|
|
|
|
|
|
newProjectID = "acceptence_tests_copyied_project"
|
|
|
|
newFileId = Math.random()
|
|
|
|
newFileUrl = "#{@filestoreUrl}/project/#{newProjectID}/file/#{newFileId}"
|
2014-12-22 06:27:48 -05:00
|
|
|
opts =
|
|
|
|
method: 'put'
|
2014-06-19 12:32:04 -04:00
|
|
|
uri: newFileUrl
|
|
|
|
json:
|
|
|
|
source:
|
|
|
|
project_id:"acceptence_tests"
|
|
|
|
file_id: @file_id
|
2014-12-22 06:27:48 -05:00
|
|
|
request opts, (err, response, body)=>
|
|
|
|
response.statusCode.should.equal 200
|
2014-06-19 12:32:04 -04:00
|
|
|
request.del @fileUrl, (err, response, body)=>
|
2014-12-22 06:34:13 -05:00
|
|
|
response.statusCode.should.equal 204
|
2014-06-19 12:32:04 -04:00
|
|
|
request.get newFileUrl, (err, response, body)=>
|
|
|
|
body.should.equal @constantFileContent
|
|
|
|
done()
|
2015-09-08 05:32:41 -04:00
|
|
|
|
2015-09-08 06:43:19 -04:00
|
|
|
describe "with a pdf file", ->
|
|
|
|
|
|
|
|
beforeEach (done)->
|
|
|
|
@timeout(1000 * 10)
|
|
|
|
@file_id = Math.random()
|
|
|
|
@fileUrl = "#{@filestoreUrl}/project/acceptence_tests/file/#{@file_id}"
|
|
|
|
@localFileReadPath = __dirname + '/../../fixtures/test.pdf'
|
|
|
|
|
|
|
|
writeStream = request.post(@fileUrl)
|
|
|
|
|
|
|
|
writeStream.on "end", done
|
|
|
|
fs.createReadStream(@localFileReadPath).pipe writeStream
|
|
|
|
|
|
|
|
it "should be able get the file back", (done)->
|
|
|
|
@timeout(1000 * 10)
|
|
|
|
request.get @fileUrl, (err, response, body)=>
|
|
|
|
expect(body.substring(0, 8)).to.equal '%PDF-1.5'
|
|
|
|
done()
|
|
|
|
|
2015-09-08 05:32:41 -04:00
|
|
|
describe "getting the preview image", ->
|
|
|
|
|
|
|
|
beforeEach ->
|
2018-05-21 08:40:03 -04:00
|
|
|
@previewFileUrl = "#{@fileUrl}?style=preview"
|
2015-09-08 05:32:41 -04:00
|
|
|
|
|
|
|
it "should not time out", (done) ->
|
|
|
|
@timeout(1000 * 20)
|
2018-05-21 08:40:03 -04:00
|
|
|
request.get @previewFileUrl, (err, response, body) =>
|
2015-09-08 05:32:41 -04:00
|
|
|
expect(response).to.not.equal null
|
|
|
|
done()
|
2015-09-08 06:43:19 -04:00
|
|
|
|
|
|
|
it "should respond with image data", (done) ->
|
|
|
|
# note: this test relies of the imagemagick conversion working
|
|
|
|
@timeout(1000 * 20)
|
2018-05-21 08:40:03 -04:00
|
|
|
request.get @previewFileUrl, (err, response, body) =>
|
2015-09-08 06:43:19 -04:00
|
|
|
expect(response.statusCode).to.equal 200
|
2015-09-08 06:50:43 -04:00
|
|
|
expect(body.length).to.be.greaterThan 400
|
2015-09-08 06:43:19 -04:00
|
|
|
done()
|
2015-09-08 06:47:43 -04:00
|
|
|
|
|
|
|
describe "warming the cache", ->
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
@fileUrl = @fileUrl + '?style=preview&cacheWarm=true'
|
|
|
|
|
|
|
|
it "should not time out", (done) ->
|
|
|
|
@timeout(1000 * 20)
|
|
|
|
request.get @fileUrl, (err, response, body) =>
|
|
|
|
expect(response).to.not.equal null
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should respond with only an 'OK'", (done) ->
|
|
|
|
# note: this test relies of the imagemagick conversion working
|
|
|
|
@timeout(1000 * 20)
|
|
|
|
request.get @fileUrl, (err, response, body) =>
|
|
|
|
expect(response.statusCode).to.equal 200
|
|
|
|
body.should.equal 'OK'
|
|
|
|
done()
|