2019-04-30 08:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-12-17 00:21:28 +08:00
|
|
|
module IntegrationHelpers
|
2017-08-31 12:06:56 +08:00
|
|
|
def create_user
|
2020-10-02 07:01:40 +08:00
|
|
|
get "/session/hp.json"
|
2017-08-31 12:06:56 +08:00
|
|
|
|
2018-06-07 16:11:09 +08:00
|
|
|
expect(response.status).to eq(200)
|
2017-08-31 12:06:56 +08:00
|
|
|
|
2020-05-07 23:04:12 +08:00
|
|
|
body = response.parsed_body
|
2017-08-31 12:06:56 +08: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 16:11:09 +08:00
|
|
|
expect(response.status).to eq(200)
|
2017-08-31 12:06:56 +08:00
|
|
|
|
2020-05-07 23:04:12 +08:00
|
|
|
body = response.parsed_body
|
2017-08-31 12:06:56 +08:00
|
|
|
User.find(body["user_id"])
|
|
|
|
end
|
|
|
|
|
2016-12-17 00:21:28 +08:00
|
|
|
def sign_in(user)
|
2020-06-06 00:31:58 +08:00
|
|
|
get "/session/#{user.encoded_username}/become"
|
2017-12-14 10:53:21 +08:00
|
|
|
user
|
2016-12-17 00:21:28 +08:00
|
|
|
end
|
2020-01-10 08:45:56 +08:00
|
|
|
|
2020-04-08 14:33:50 +08:00
|
|
|
def sign_out
|
|
|
|
delete "/session"
|
|
|
|
end
|
|
|
|
|
2020-01-10 08:45:56 +08:00
|
|
|
def read_secure_session
|
|
|
|
SecureSession.new(session[:secure_session_id])
|
|
|
|
end
|
2016-12-17 00:21:28 +08:00
|
|
|
end
|