2019-05-29 05:21:06 -04:00
|
|
|
/* eslint-disable
|
|
|
|
max-len,
|
|
|
|
no-unused-vars,
|
|
|
|
no-useless-escape,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
|
|
|
const child = require('child_process')
|
|
|
|
let fs = require('fs')
|
|
|
|
const assert = require('assert')
|
|
|
|
const chai = require('chai')
|
|
|
|
if (Object.prototype.should == null) {
|
|
|
|
chai.should()
|
|
|
|
}
|
|
|
|
const { expect } = chai
|
|
|
|
const Settings = require('settings-sharelatex')
|
2019-07-15 09:09:04 -04:00
|
|
|
let ownPort = Settings.internal.web.port || Settings.port || 3000
|
2020-10-27 11:46:59 -04:00
|
|
|
const port = (Settings.web && Settings.web.web_router_port) || ownPort // send requests to web router if this is the api process
|
2019-05-29 05:21:06 -04:00
|
|
|
const cookeFilePath = `/tmp/smoke-test-cookie-${ownPort}-to-${port}.txt`
|
|
|
|
const buildUrl = path =>
|
|
|
|
` -b ${cookeFilePath} --resolve 'smoke${
|
|
|
|
Settings.cookieDomain
|
2020-09-17 04:30:08 -04:00
|
|
|
}:${port}:127.0.0.1' http://smoke${Settings.cookieDomain}:${port}/${path}`
|
2019-05-29 05:21:06 -04:00
|
|
|
const logger = require('logger-sharelatex')
|
|
|
|
const LoginRateLimiter = require('../../../app/src/Features/Security/LoginRateLimiter.js')
|
|
|
|
const RateLimiter = require('../../../app/src/infrastructure/RateLimiter.js')
|
|
|
|
|
|
|
|
// Change cookie to be non secure so curl will send it
|
|
|
|
const convertCookieFile = function(callback) {
|
|
|
|
fs = require('fs')
|
2019-08-07 10:04:04 -04:00
|
|
|
return fs.readFile(cookeFilePath, 'utf8', (err, data) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (err) {
|
|
|
|
return callback(err)
|
|
|
|
}
|
|
|
|
const firstTrue = data.indexOf('TRUE')
|
|
|
|
const secondTrue = data.indexOf('TRUE', firstTrue + 4)
|
|
|
|
const result =
|
|
|
|
data.slice(0, secondTrue) + 'FALSE' + data.slice(secondTrue + 4)
|
2019-08-07 10:04:04 -04:00
|
|
|
return fs.writeFile(cookeFilePath, result, 'utf8', err => {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (err) {
|
|
|
|
return callback(err)
|
|
|
|
}
|
|
|
|
return callback()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('Opening', function() {
|
|
|
|
before(function(done) {
|
|
|
|
logger.log('smoke test: setup')
|
2019-08-07 10:04:04 -04:00
|
|
|
LoginRateLimiter.recordSuccessfulLogin(Settings.smokeTest.user, err => {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (err != null) {
|
|
|
|
logger.err({ err }, 'smoke test: error recoring successful login')
|
|
|
|
return done(err)
|
|
|
|
}
|
|
|
|
return RateLimiter.clearRateLimit(
|
|
|
|
'open-project',
|
|
|
|
`${Settings.smokeTest.projectId}:${Settings.smokeTest.userId}`,
|
2019-08-07 10:04:04 -04:00
|
|
|
err => {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (err != null) {
|
|
|
|
logger.err(
|
|
|
|
{ err },
|
|
|
|
'smoke test: error clearing open-project rate limit'
|
|
|
|
)
|
|
|
|
return done(err)
|
|
|
|
}
|
|
|
|
return RateLimiter.clearRateLimit(
|
|
|
|
'overleaf-login',
|
|
|
|
Settings.smokeTest.rateLimitSubject,
|
2019-08-07 10:04:04 -04:00
|
|
|
err => {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (err != null) {
|
|
|
|
logger.err(
|
|
|
|
{ err },
|
|
|
|
'smoke test: error clearing overleaf-login rate limit'
|
|
|
|
)
|
|
|
|
return done(err)
|
|
|
|
}
|
|
|
|
return done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
before(function(done) {
|
|
|
|
logger.log('smoke test: hitting dev/csrf')
|
|
|
|
let command = `\
|
|
|
|
curl -H "X-Forwarded-Proto: https" -c ${cookeFilePath} ${buildUrl('dev/csrf')}\
|
|
|
|
`
|
2019-08-07 10:04:04 -04:00
|
|
|
child.exec(command, (err, stdout, stderr) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (err != null) {
|
|
|
|
done(err)
|
|
|
|
}
|
|
|
|
const csrf = stdout
|
|
|
|
logger.log('smoke test: converting cookie file 1')
|
2019-08-07 10:04:04 -04:00
|
|
|
return convertCookieFile(err => {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (err != null) {
|
|
|
|
return done(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')}\
|
|
|
|
`
|
2019-08-07 10:04:04 -04:00
|
|
|
return child.exec(command, err => {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (err != null) {
|
|
|
|
return done(err)
|
|
|
|
}
|
|
|
|
logger.log('smoke test: finishing setup')
|
|
|
|
return convertCookieFile(done)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
after(function(done) {
|
|
|
|
logger.log('smoke test: converting cookie file 2')
|
2019-08-07 10:04:04 -04:00
|
|
|
convertCookieFile(err => {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (err != null) {
|
|
|
|
return done(err)
|
|
|
|
}
|
|
|
|
logger.log('smoke test: cleaning up')
|
|
|
|
let command = `\
|
|
|
|
curl -H "X-Forwarded-Proto: https" -c ${cookeFilePath} ${buildUrl('dev/csrf')}\
|
|
|
|
`
|
2019-08-07 10:04:04 -04:00
|
|
|
return child.exec(command, (err, stdout, stderr) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (err != null) {
|
|
|
|
done(err)
|
|
|
|
}
|
|
|
|
const csrf = stdout
|
|
|
|
logger.log('smoke test: converting cookie file 3')
|
2019-08-07 10:04:04 -04:00
|
|
|
return convertCookieFile(err => {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (err != null) {
|
|
|
|
return done(err)
|
|
|
|
}
|
|
|
|
command = `\
|
|
|
|
curl -H "Content-Type: application/json" -H "X-Forwarded-Proto: https" -d '{"_csrf":"${csrf}"}' -c ${cookeFilePath} ${buildUrl(
|
|
|
|
'logout'
|
|
|
|
)}\
|
|
|
|
`
|
2019-08-07 10:04:04 -04:00
|
|
|
return child.exec(command, (err, stdout, stderr) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
if (err != null) {
|
|
|
|
return done(err)
|
|
|
|
}
|
|
|
|
return fs.unlink(cookeFilePath, done)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('a project', function(done) {
|
|
|
|
logger.log('smoke test: Checking can load a project')
|
|
|
|
this.timeout(4000)
|
|
|
|
const command = `\
|
|
|
|
curl -H "X-Forwarded-Proto: https" -v ${buildUrl(
|
|
|
|
`project/${Settings.smokeTest.projectId}`
|
|
|
|
)}\
|
|
|
|
`
|
2019-08-07 10:04:04 -04:00
|
|
|
return child.exec(command, (error, stdout, stderr) => {
|
2019-05-29 05:21:06 -04:00
|
|
|
expect(error, 'smoke test: error in getting project').to.not.exist
|
|
|
|
|
|
|
|
const 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
|
|
|
|
const match = !!stdout.match(
|
|
|
|
`window.project_id = \"${Settings.smokeTest.projectId}\"`
|
|
|
|
)
|
|
|
|
expect(
|
|
|
|
match,
|
|
|
|
'smoke test: project page html does not have project_id'
|
|
|
|
).to.equal(true)
|
|
|
|
return done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('the project list', function(done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
logger.log('smoke test: Checking can load project list')
|
|
|
|
this.timeout(4000)
|
|
|
|
const command = `\
|
|
|
|
curl -H "X-Forwarded-Proto: https" -v ${buildUrl('project')}\
|
|
|
|
`
|
2019-08-07 10:04:04 -04:00
|
|
|
return child.exec(command, (error, stdout, stderr) => {
|
|
|
|
expect(error, 'smoke test: error returned in getting project list').to.not
|
|
|
|
.exist
|
2019-05-29 05:21:06 -04:00
|
|
|
expect(
|
|
|
|
!!stderr.match('200 OK'),
|
|
|
|
'smoke test: response code is not 200 getting project list'
|
|
|
|
).to.equal(true)
|
|
|
|
expect(
|
|
|
|
!!stdout.match(
|
|
|
|
'<title>Your Projects - .*, Online LaTeX Editor</title>'
|
|
|
|
),
|
|
|
|
'smoke test: body does not have correct title'
|
|
|
|
).to.equal(true)
|
|
|
|
expect(
|
|
|
|
!!stdout.match('ProjectPageController'),
|
|
|
|
'smoke test: body does not have correct angular controller'
|
|
|
|
).to.equal(true)
|
|
|
|
return done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|