changed smoke tests to work with curl

this was needed as there is a bug with request/tough cookie with
multi subdomain cookies ie .sharelatex.com

https://github.com/goinstant/tough-cookie/issues/16

moving it to request in the future is probably a good idea, if we do move to
request then with the current issues we would we need to set

jar._jar.rejectPublicSuffixes = false
This commit is contained in:
Henry Oswald 2014-08-19 11:17:51 +01:00
parent 0dc4b3a01b
commit 523694c4ff
2 changed files with 31 additions and 34 deletions

View file

@ -68,6 +68,7 @@ app.configure () ->
next() next()
app.use (req, res, next) -> app.use (req, res, next) ->
console.log req.sessionID
for route in ignoreCsrfRoutes for route in ignoreCsrfRoutes
if route.method == req.method?.toLowerCase() and route.match(req.path) if route.method == req.method?.toLowerCase() and route.match(req.path)
return next() return next()

View file

@ -5,59 +5,55 @@ chai = require("chai")
chai.should() chai.should()
expect = chai.expect expect = chai.expect
Settings = require "settings-sharelatex" Settings = require "settings-sharelatex"
port = Settings.internal?.web?.port or Settings.port or 3000 port = Settings.internal?.web?.port or Settings.port or 3000
buildUrl = (path) -> "http://www.sharelatex.dev:#{port}/#{path}" buildUrl = (path) -> "-b cookies.txt -c cookies.txt --resolve 'smoke.sharelatex.dev:#{port}:127.0.0.1' http://smoke.sharelatex.dev:#{port}/#{path}?setLng=en"
describe "Opening", -> describe "Opening", ->
before (done) -> before (done) ->
command = "curl -b cookies.txt -c cookies.txt #{buildUrl('register')}" command = "curl #{buildUrl('register')}"
child.exec command, (err, stdout, stderr)-> child.exec command, (err, stdout, stderr)->
if err? then done(err)
csrf = stdout.match("<input name=\"_csrf\" type=\"hidden\" value=\"(.*?)\">")[1] csrf = stdout.match("<input name=\"_csrf\" type=\"hidden\" value=\"(.*?)\">")[1]
command = """ command = """
curl -b cookies.txt -c cookies.txt -H "Content-Type: application/json" -d '{"_csrf":"#{csrf}", "email":"#{Settings.smokeTest.user}", "password":"#{Settings.smokeTest.password}"}' http://www.sharelatex.dev:3000/register curl -H "Content-Type: application/json" -d '{"_csrf":"#{csrf}", "email":"#{Settings.smokeTest.user}", "password":"#{Settings.smokeTest.password}"}' #{buildUrl('register')}
""" """
console.log csrf
child.exec command, (err, stdout, stderr)-> child.exec command, (err, stdout, stderr)->
done() done(err)
after (done)-> after (done)->
fs.unlink "cookies.txt", done fs.unlink "cookies.txt", done
it "a project", (done) -> it "a project", (done) ->
@timeout(4000)
# request { command = """
# url: buildUrl("project/#{Settings.smokeTest.projectId}") curl -H 'X-Forwarded-Proto: https' -v #{buildUrl("project/#{Settings.smokeTest.projectId}")}
# headers: """
# "X-Forwarded-Proto": "https" child.exec command, (error, stdout, stderr)->
# }, (error, response, body) -> expect(error, "smoke test: error in getting project").to.not.exist
# expect(error, "smoke test: error in getting project").to.not.exist
# expect(response.statusCode, "smoke test: response code is not 200 getting project").to.equal(200) statusCodeMatch = !!stderr.match("200 OK")
# # Check that the project id is present in the javascript that loads up the project expect(statusCodeMatch, "smoke test: response code is not 200 getting project").to.equal true
# match = !!body.match("window.project_id = \"#{Settings.smokeTest.projectId}\"")
# expect(match, "smoke test: project page html does not have project_id").to.equal true # Check that the project id is present in the javascript that loads up the project
# done() match = !!stdout.match("window.project_id = \"#{Settings.smokeTest.projectId}\"")
done() expect(match, "smoke test: project page html does not have project_id").to.equal true
done()
it "the project list", (done) -> it "the project list", (done) ->
# request { @timeout(4000)
# url: buildUrl("project") command = """
# headers: curl -H 'X-Forwarded-Proto: https' -v #{buildUrl("project")}
# "X-Forwarded-Proto": "https" """
# }, (error, response, body) -> child.exec command, (error, stdout, stderr)->
# expect(error, "smoke test: error returned in getting project list").to.not.exist
# expect(response.statusCode, "smoke test: response code is not 200 getting project list").to.equal(200) expect(error, "smoke test: error returned in getting project list").to.not.exist
# expect(!!body.match("<title>Your Projects - ShareLaTeX, Online LaTeX Editor</title>"), "smoke test: body does not have correct title").to.equal true expect(!!stderr.match("200 OK"), "smoke test: response code is not 200 getting project list").to.equal true
# expect(!!body.match("ProjectPageController"), "smoke test: body does not have correct angular controller").to.equal true expect(!!stdout.match("<title>Your Projects - ShareLaTeX, Online LaTeX Editor</title>"), "smoke test: body does not have correct title").to.equal true
# done() expect(!!stdout.match("ProjectPageController"), "smoke test: body does not have correct angular controller").to.equal true
done() done()