2014-08-19 05:54:33 -04:00
|
|
|
child = require "child_process"
|
|
|
|
fs = require "fs"
|
|
|
|
assert = require("assert")
|
2014-02-12 05:23:40 -05:00
|
|
|
chai = require("chai")
|
2015-05-26 05:54:55 -04:00
|
|
|
chai.should() unless Object.prototype.should?
|
2014-02-12 05:23:40 -05:00
|
|
|
expect = chai.expect
|
|
|
|
Settings = require "settings-sharelatex"
|
2017-07-04 05:32:31 -04:00
|
|
|
ownPort = Settings.internal?.web?.port or Settings.port or 3000
|
|
|
|
port = Settings.web?.web_router_port or ownPort # send requests to web router if this is the api process
|
|
|
|
cookeFilePath = "/tmp/smoke-test-cookie-#{ownPort}-to-#{port}.txt"
|
2014-08-19 10:35:34 -04:00
|
|
|
buildUrl = (path) -> " -b #{cookeFilePath} --resolve 'smoke#{Settings.cookieDomain}:#{port}:127.0.0.1' http://smoke#{Settings.cookieDomain}:#{port}/#{path}?setLng=en"
|
2014-11-24 08:33:03 -05:00
|
|
|
logger = require "logger-sharelatex"
|
2019-02-19 07:24:31 -05:00
|
|
|
LoginRateLimiter = require("../../../app/js/Features/Security/LoginRateLimiter.js")
|
|
|
|
RateLimiter = require("../../../app/js/infrastructure/RateLimiter.js")
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2015-02-17 06:21:14 -05:00
|
|
|
# Change cookie to be non secure so curl will send it
|
|
|
|
convertCookieFile = (callback) ->
|
|
|
|
fs = require("fs")
|
|
|
|
fs.readFile cookeFilePath, "utf8", (err, data) ->
|
|
|
|
return callback(err) if err
|
|
|
|
firstTrue = data.indexOf("TRUE")
|
|
|
|
secondTrue = data.indexOf("TRUE", firstTrue+4)
|
|
|
|
result = data.slice(0, secondTrue)+"FALSE"+data.slice(secondTrue+4)
|
|
|
|
fs.writeFile cookeFilePath, result, "utf8", (err) ->
|
|
|
|
return callback(err) if err
|
|
|
|
callback()
|
|
|
|
|
2014-02-12 05:23:40 -05:00
|
|
|
describe "Opening", ->
|
2014-08-19 05:54:33 -04:00
|
|
|
|
2014-02-12 05:23:40 -05:00
|
|
|
before (done) ->
|
2016-10-21 14:20:21 -04:00
|
|
|
logger.log "smoke test: setup"
|
2019-02-19 07:24:31 -05:00
|
|
|
LoginRateLimiter.recordSuccessfulLogin Settings.smokeTest.user, (err)->
|
2016-10-21 14:20:21 -04:00
|
|
|
if err?
|
|
|
|
logger.err err:err, "smoke test: error recoring successful login"
|
|
|
|
return done(err)
|
2019-02-19 07:24:31 -05:00
|
|
|
RateLimiter.clearRateLimit "open-project", "#{Settings.smokeTest.projectId}:#{Settings.smokeTest.userId}", (err)->
|
|
|
|
if err?
|
|
|
|
logger.err err:err, "smoke test: error clearing open-project rate limit"
|
|
|
|
return done(err)
|
|
|
|
RateLimiter.clearRateLimit "overleaf-login", Settings.smokeTest.rateLimitSubject, (err)->
|
|
|
|
if err?
|
|
|
|
logger.err err:err, "smoke test: error clearing overleaf-login rate limit"
|
|
|
|
return done(err)
|
|
|
|
done()
|
2018-02-27 10:57:40 -05:00
|
|
|
return
|
2014-05-19 06:53:10 -04:00
|
|
|
|
2019-02-19 07:24:31 -05:00
|
|
|
before (done) ->
|
|
|
|
logger.log "smoke test: hitting dev/csrf"
|
2014-09-04 07:35:59 -04:00
|
|
|
command = """
|
2019-02-19 07:24:31 -05:00
|
|
|
curl -H "X-Forwarded-Proto: https" -c #{cookeFilePath} #{buildUrl('dev/csrf')}
|
2014-09-04 07:35:59 -04:00
|
|
|
"""
|
|
|
|
child.exec command, (err, stdout, stderr)->
|
2019-02-19 07:24:31 -05:00
|
|
|
if err? then done(err)
|
|
|
|
csrf = stdout
|
|
|
|
logger.log "smoke test: converting cookie file 1"
|
|
|
|
convertCookieFile (err) ->
|
|
|
|
return done(err) if err?
|
|
|
|
logger.log "smoke test: hitting /login with csrf"
|
|
|
|
command = """
|
|
|
|
curl -c #{cookeFilePath} -H "Content-Type: application/json" -H "X-Forwarded-Proto: https" -d '{"_csrf":"#{csrf}", "email":"#{Settings.smokeTest.user}", "password":"#{Settings.smokeTest.password}"}' #{buildUrl('login')}
|
|
|
|
"""
|
|
|
|
child.exec command, (err) ->
|
|
|
|
return done(err) if err?
|
|
|
|
logger.log "smoke test: finishing setup"
|
|
|
|
convertCookieFile done
|
|
|
|
return
|
|
|
|
|
|
|
|
after (done)->
|
|
|
|
logger.log "smoke test: converting cookie file 2"
|
|
|
|
convertCookieFile (err) ->
|
|
|
|
return done(err) if err?
|
|
|
|
logger.log "smoke test: cleaning up"
|
|
|
|
command = """
|
|
|
|
curl -H "X-Forwarded-Proto: https" -c #{cookeFilePath} #{buildUrl('dev/csrf')}
|
|
|
|
"""
|
|
|
|
child.exec command, (err, stdout, stderr)->
|
|
|
|
if err? then done(err)
|
|
|
|
csrf = stdout
|
|
|
|
logger.log "smoke test: converting cookie file 3"
|
|
|
|
convertCookieFile (err) ->
|
|
|
|
return done(err) if err?
|
|
|
|
command = """
|
|
|
|
curl -H "Content-Type: application/json" -H "X-Forwarded-Proto: https" -d '{"_csrf":"#{csrf}"}' -c #{cookeFilePath} #{buildUrl('logout')}
|
|
|
|
"""
|
|
|
|
child.exec command, (err, stdout, stderr)->
|
|
|
|
if err?
|
|
|
|
return done(err)
|
|
|
|
fs.unlink cookeFilePath, done
|
2018-02-27 10:57:40 -05:00
|
|
|
return
|
2014-05-19 06:53:10 -04:00
|
|
|
|
2014-02-12 05:23:40 -05:00
|
|
|
it "a project", (done) ->
|
2016-10-21 14:20:21 -04:00
|
|
|
logger.log "smoke test: Checking can load a project"
|
2014-08-19 06:17:51 -04:00
|
|
|
@timeout(4000)
|
|
|
|
command = """
|
2014-08-19 10:35:34 -04:00
|
|
|
curl -H "X-Forwarded-Proto: https" -v #{buildUrl("project/#{Settings.smokeTest.projectId}")}
|
2014-08-19 06:17:51 -04:00
|
|
|
"""
|
|
|
|
child.exec command, (error, stdout, stderr)->
|
|
|
|
expect(error, "smoke test: error in getting project").to.not.exist
|
|
|
|
|
|
|
|
statusCodeMatch = !!stderr.match("200 OK")
|
|
|
|
expect(statusCodeMatch, "smoke test: response code is not 200 getting project").to.equal true
|
|
|
|
|
|
|
|
# Check that the project id is present in the javascript that loads up the project
|
|
|
|
match = !!stdout.match("window.project_id = \"#{Settings.smokeTest.projectId}\"")
|
|
|
|
expect(match, "smoke test: project page html does not have project_id").to.equal true
|
|
|
|
done()
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2014-08-08 08:11:49 -04:00
|
|
|
|
2014-02-12 05:23:40 -05:00
|
|
|
it "the project list", (done) ->
|
2016-10-21 14:20:21 -04:00
|
|
|
logger.log "smoke test: Checking can load project list"
|
2014-08-19 06:17:51 -04:00
|
|
|
@timeout(4000)
|
|
|
|
command = """
|
2014-08-19 10:35:34 -04:00
|
|
|
curl -H "X-Forwarded-Proto: https" -v #{buildUrl("project")}
|
2014-08-19 06:17:51 -04:00
|
|
|
"""
|
|
|
|
child.exec command, (error, stdout, stderr)->
|
|
|
|
|
|
|
|
expect(error, "smoke test: error returned in getting project list").to.not.exist
|
|
|
|
expect(!!stderr.match("200 OK"), "smoke test: response code is not 200 getting project list").to.equal true
|
2017-08-08 06:31:36 -04:00
|
|
|
expect(!!stdout.match("<title>Your Projects - .*, Online LaTeX Editor</title>"), "smoke test: body does not have correct title").to.equal true
|
2014-08-19 06:17:51 -04:00
|
|
|
expect(!!stdout.match("ProjectPageController"), "smoke test: body does not have correct angular controller").to.equal true
|
|
|
|
done()
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2014-08-19 05:54:33 -04:00
|
|
|
|