2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-12-16 11:21:28 -05:00
|
|
|
module IntegrationHelpers
|
2017-08-31 00:06:56 -04:00
|
|
|
def create_user
|
2020-10-01 19:01:40 -04:00
|
|
|
get "/session/hp.json"
|
2017-08-31 00:06:56 -04:00
|
|
|
|
2018-06-07 04:11:09 -04:00
|
|
|
expect(response.status).to eq(200)
|
2017-08-31 00:06:56 -04:00
|
|
|
|
2020-05-07 11:04:12 -04:00
|
|
|
body = response.parsed_body
|
2017-08-31 00:06:56 -04:00
|
|
|
honeypot = body["value"]
|
|
|
|
challenge = body["challenge"]
|
|
|
|
user = Fabricate.build(:user)
|
|
|
|
|
|
|
|
post "/u.json",
|
|
|
|
params: {
|
|
|
|
username: user.username,
|
|
|
|
email: user.email,
|
|
|
|
password: "asdasljdhaiosdjioaeiow",
|
|
|
|
password_confirmation: honeypot,
|
|
|
|
challenge: challenge.reverse,
|
|
|
|
}
|
|
|
|
|
2018-06-07 04:11:09 -04:00
|
|
|
expect(response.status).to eq(200)
|
2017-08-31 00:06:56 -04:00
|
|
|
|
2020-05-07 11:04:12 -04:00
|
|
|
body = response.parsed_body
|
2017-08-31 00:06:56 -04:00
|
|
|
User.find(body["user_id"])
|
|
|
|
end
|
|
|
|
|
2016-12-16 11:21:28 -05:00
|
|
|
def sign_in(user)
|
2020-06-05 12:31:58 -04:00
|
|
|
get "/session/#{user.encoded_username}/become"
|
2017-12-13 21:53:21 -05:00
|
|
|
user
|
2016-12-16 11:21:28 -05:00
|
|
|
end
|
2020-01-09 19:45:56 -05:00
|
|
|
|
2020-04-08 02:33:50 -04:00
|
|
|
def sign_out
|
|
|
|
delete "/session"
|
|
|
|
end
|
|
|
|
|
2020-01-09 19:45:56 -05:00
|
|
|
def read_secure_session
|
2021-02-18 05:35:10 -05:00
|
|
|
id =
|
|
|
|
begin
|
|
|
|
session[:secure_session_id]
|
|
|
|
rescue NoMethodError
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
# This route will init the secure_session for us
|
|
|
|
get "/session/hp.json" if id.nil?
|
|
|
|
|
2020-01-09 19:45:56 -05:00
|
|
|
SecureSession.new(session[:secure_session_id])
|
|
|
|
end
|
2021-03-18 20:20:10 -04:00
|
|
|
|
|
|
|
def write_secure_session(key, value)
|
|
|
|
secure_session = read_secure_session
|
|
|
|
secure_session[key] = value
|
|
|
|
secure_session
|
|
|
|
end
|
2016-12-16 11:21:28 -05:00
|
|
|
end
|