From 938d22da3f6a99ed66fb614e700b68a991f49098 Mon Sep 17 00:00:00 2001 From: Hayden Faulds Date: Fri, 1 Dec 2017 16:47:38 +0000 Subject: [PATCH 1/3] get csrf token from /dev/csrf not /register --- services/web/test/acceptance/coffee/helpers/User.coffee | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/services/web/test/acceptance/coffee/helpers/User.coffee b/services/web/test/acceptance/coffee/helpers/User.coffee index d9f0b1409a..6dde67849d 100644 --- a/services/web/test/acceptance/coffee/helpers/User.coffee +++ b/services/web/test/acceptance/coffee/helpers/User.coffee @@ -161,13 +161,10 @@ class User getCsrfToken: (callback = (error) ->) -> @request.get { - url: "/register" + url: "/dev/csrf" }, (err, response, body) => return callback(err) if err? - csrfMatches = body.match("window.csrfToken = \"(.*?)\";") - if !csrfMatches? - return callback(new Error("no csrf token found")) - @csrfToken = csrfMatches[1] + @csrfToken = body @request = @request.defaults({ headers: "x-csrf-token": @csrfToken From eacb19fac91aa8018c498137a7a1971d9da4198e Mon Sep 17 00:00:00 2001 From: Hayden Faulds Date: Fri, 1 Dec 2017 16:54:45 +0000 Subject: [PATCH 2/3] create user in db and use login endpoint instead of register --- .../acceptance/coffee/helpers/User.coffee | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/services/web/test/acceptance/coffee/helpers/User.coffee b/services/web/test/acceptance/coffee/helpers/User.coffee index 6dde67849d..61d8b8328c 100644 --- a/services/web/test/acceptance/coffee/helpers/User.coffee +++ b/services/web/test/acceptance/coffee/helpers/User.coffee @@ -1,6 +1,9 @@ request = require("./request") +_ = require("underscore") settings = require("settings-sharelatex") {db, ObjectId} = require("../../../../app/js/infrastructure/mongojs") +UserModel = require("../../../../app/js/models/User").User +AuthenticationManager = require("../../../../app/js/Features/Authentication/AuthenticationManager") count = 0 @@ -17,20 +20,20 @@ class User login: (callback = (error) ->) -> @getCsrfToken (error) => return callback(error) if error? - @request.post { - url: "/register" # Register will log in, but also ensure user exists - json: - email: @email - password: @password - }, (error, response, body) => + filter = {@email} + options = {upsert: true, new: true, setDefaultsOnInsert: true} + UserModel.findOneAndUpdate filter, {}, options, (error, user) => return callback(error) if error? - db.users.findOne {email: @email}, (error, user) => + AuthenticationManager.setUserPassword user._id, @password, (error) => return callback(error) if error? @id = user?._id?.toString() @_id = user?._id?.toString() @first_name = user?.first_name @referal_id = user?.referal_id - callback() + @request.post { + url: "/login" + json: { @email, @password } + }, callback logout: (callback = (error) ->) -> @getCsrfToken (error) => From 28bcf83d873f09eea11a425ca7752fc97eb46919 Mon Sep 17 00:00:00 2001 From: Hayden Faulds Date: Fri, 1 Dec 2017 17:21:54 +0000 Subject: [PATCH 3/3] better error when project creation fails --- services/web/test/acceptance/coffee/helpers/User.coffee | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/services/web/test/acceptance/coffee/helpers/User.coffee b/services/web/test/acceptance/coffee/helpers/User.coffee index 61d8b8328c..6cd7edd7d4 100644 --- a/services/web/test/acceptance/coffee/helpers/User.coffee +++ b/services/web/test/acceptance/coffee/helpers/User.coffee @@ -107,8 +107,10 @@ class User }, (error, response, body) -> return callback(error) if error? if !body?.project_id? - console.error "SOMETHING WENT WRONG CREATING PROJECT", response.statusCode, response.headers["location"], body - callback(null, body.project_id) + error = new Error("SOMETHING WENT WRONG CREATING PROJECT", response.statusCode, response.headers["location"], body) + callback error + else + callback(null, body.project_id) deleteProject: (project_id, callback=(error)) -> @request.delete {