mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge branch 'master' of github.com:sharelatex/web-sharelatex
This commit is contained in:
commit
50df82697a
4 changed files with 14 additions and 11 deletions
|
@ -46,5 +46,6 @@ module.exports = ProjectZipStreamManager =
|
||||||
return callback(err)
|
return callback(err)
|
||||||
path = path.slice(1) if path[0] == "/"
|
path = path.slice(1) if path[0] == "/"
|
||||||
archive.append stream, name: path
|
archive.append stream, name: path
|
||||||
|
stream.on "end", () ->
|
||||||
callback()
|
callback()
|
||||||
async.series jobs, callback
|
async.series jobs, callback
|
||||||
|
|
|
@ -2,7 +2,7 @@ Settings = require('settings-sharelatex')
|
||||||
redis = require('redis')
|
redis = require('redis')
|
||||||
rclient = redis.createClient(Settings.redis.web.port, Settings.redis.web.host)
|
rclient = redis.createClient(Settings.redis.web.port, Settings.redis.web.host)
|
||||||
rclient.auth(Settings.redis.web.password)
|
rclient.auth(Settings.redis.web.password)
|
||||||
uuid = require("node-uuid")
|
crypto = require("crypto")
|
||||||
logger = require("logger-sharelatex")
|
logger = require("logger-sharelatex")
|
||||||
|
|
||||||
ONE_HOUR_IN_S = 60 * 60
|
ONE_HOUR_IN_S = 60 * 60
|
||||||
|
@ -13,7 +13,7 @@ module.exports =
|
||||||
|
|
||||||
getNewToken: (user_id, callback)->
|
getNewToken: (user_id, callback)->
|
||||||
logger.log user_id:user_id, "generating token for password reset"
|
logger.log user_id:user_id, "generating token for password reset"
|
||||||
token = uuid.v4()
|
token = crypto.randomBytes(32).toString("hex")
|
||||||
multi = rclient.multi()
|
multi = rclient.multi()
|
||||||
multi.set buildKey(token), user_id
|
multi.set buildKey(token), user_id
|
||||||
multi.expire buildKey(token), ONE_HOUR_IN_S
|
multi.expire buildKey(token), ONE_HOUR_IN_S
|
||||||
|
|
|
@ -4,6 +4,7 @@ should = chai.should()
|
||||||
expect = chai.expect
|
expect = chai.expect
|
||||||
modulePath = "../../../../app/js/Features/Downloads/ProjectZipStreamManager.js"
|
modulePath = "../../../../app/js/Features/Downloads/ProjectZipStreamManager.js"
|
||||||
SandboxedModule = require('sandboxed-module')
|
SandboxedModule = require('sandboxed-module')
|
||||||
|
EventEmitter = require("events").EventEmitter
|
||||||
|
|
||||||
describe "ProjectZipStreamManager", ->
|
describe "ProjectZipStreamManager", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
|
@ -112,14 +113,16 @@ describe "ProjectZipStreamManager", ->
|
||||||
"/folder/picture.png":
|
"/folder/picture.png":
|
||||||
_id: "file-id-2"
|
_id: "file-id-2"
|
||||||
@streams =
|
@streams =
|
||||||
"file-id-1" : "stream-mock-1"
|
"file-id-1" : new EventEmitter()
|
||||||
"file-id-2" : "stream-mock-2"
|
"file-id-2" : new EventEmitter()
|
||||||
@ProjectEntityHandler.getAllFiles = sinon.stub().callsArgWith(1, null, @files)
|
@ProjectEntityHandler.getAllFiles = sinon.stub().callsArgWith(1, null, @files)
|
||||||
@archive.append = sinon.stub()
|
@archive.append = sinon.stub()
|
||||||
@FileStoreHandler.getFileStream = (project_id, file_id, {}, callback) =>
|
@FileStoreHandler.getFileStream = (project_id, file_id, {}, callback) =>
|
||||||
callback null, @streams[file_id]
|
callback null, @streams[file_id]
|
||||||
sinon.spy @FileStoreHandler, "getFileStream"
|
sinon.spy @FileStoreHandler, "getFileStream"
|
||||||
@ProjectZipStreamManager.addAllFilesToArchive @project_id, @archive, @callback
|
@ProjectZipStreamManager.addAllFilesToArchive @project_id, @archive, @callback
|
||||||
|
for path, stream of @streams
|
||||||
|
stream.emit "end"
|
||||||
|
|
||||||
it "should get the files for the project", ->
|
it "should get the files for the project", ->
|
||||||
@ProjectEntityHandler.getAllFiles.calledWith(@project_id).should.equal true
|
@ProjectEntityHandler.getAllFiles.calledWith(@project_id).should.equal true
|
||||||
|
|
|
@ -10,7 +10,7 @@ describe "PasswordResetTokenHandler", ->
|
||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@user_id = "user id here"
|
@user_id = "user id here"
|
||||||
@stubbedToken = "dsajdiojlklksda"
|
@stubbedToken = require("crypto").randomBytes(32)
|
||||||
|
|
||||||
@settings =
|
@settings =
|
||||||
redis:
|
redis:
|
||||||
|
@ -21,7 +21,6 @@ describe "PasswordResetTokenHandler", ->
|
||||||
del:sinon.stub()
|
del:sinon.stub()
|
||||||
expire:sinon.stub()
|
expire:sinon.stub()
|
||||||
exec:sinon.stub()
|
exec:sinon.stub()
|
||||||
@uuid = v4 : -> return @stubbedToken
|
|
||||||
self = @
|
self = @
|
||||||
@PasswordResetTokenHandler = SandboxedModule.require modulePath, requires:
|
@PasswordResetTokenHandler = SandboxedModule.require modulePath, requires:
|
||||||
"redis" :
|
"redis" :
|
||||||
|
@ -31,7 +30,7 @@ describe "PasswordResetTokenHandler", ->
|
||||||
|
|
||||||
"settings-sharelatex":@settings
|
"settings-sharelatex":@settings
|
||||||
"logger-sharelatex": log:->
|
"logger-sharelatex": log:->
|
||||||
"node-uuid":@uuid
|
"crypto": randomBytes: () => @stubbedToken
|
||||||
|
|
||||||
|
|
||||||
describe "getNewToken", ->
|
describe "getNewToken", ->
|
||||||
|
@ -39,8 +38,8 @@ describe "PasswordResetTokenHandler", ->
|
||||||
it "should set a new token into redis with a ttl", (done)->
|
it "should set a new token into redis with a ttl", (done)->
|
||||||
@redisMulti.exec.callsArgWith(0)
|
@redisMulti.exec.callsArgWith(0)
|
||||||
@PasswordResetTokenHandler.getNewToken @user_id, (err, token) =>
|
@PasswordResetTokenHandler.getNewToken @user_id, (err, token) =>
|
||||||
@redisMulti.set "password_token:#{@stubbedToken}", @user_id
|
@redisMulti.set.calledWith("password_token:#{@stubbedToken.toString("hex")}", @user_id).should.equal true
|
||||||
@redisMulti.expire "password_token:#{@stubbedToken}", 60 * 60
|
@redisMulti.expire.calledWith("password_token:#{@stubbedToken.toString("hex")}", 60 * 60).should.equal true
|
||||||
done()
|
done()
|
||||||
|
|
||||||
it "should return if there was an error", (done)->
|
it "should return if there was an error", (done)->
|
||||||
|
|
Loading…
Reference in a new issue