forked from discourse/discourse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintegration_helpers.rb
57 lines (45 loc) · 1.16 KB
/
integration_helpers.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# frozen_string_literal: true
module IntegrationHelpers
def create_user
get "/session/hp.json"
expect(response.status).to eq(200)
body = response.parsed_body
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,
}
expect(response.status).to eq(200)
body = response.parsed_body
User.find(body["user_id"])
end
def sign_in(user)
get "/session/#{user.encoded_username}/become"
user
end
def sign_out
delete "/session"
end
def read_secure_session
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?
SecureSession.new(session[:secure_session_id])
end
def write_secure_session(key, value)
secure_session = read_secure_session
secure_session[key] = value
secure_session
end
end