discourse/spec/support/integration_helpers.rb
Loïc Guitaut b4e4833d2a DEV: Rename SecureSession to ServerSession
This patch will be followed by
https://github.com/discourse/discourse/pull/34747.

`SecureSession` doesn’t make a lot of sense anymore and can be confusing
as the current cookie store used for the session is actually secure
since it’s encrypted.

Renaming it to `ServerSession` better conveys what it does: providing a
session but on the server side only.

This patch also makes some improvements, like injecting that server
session into Rack-like request objects, allowing the server session to
be available virtually everywhere.
2025-09-18 16:31:03 +02:00

57 lines
1.2 KiB
Ruby
Vendored

# 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[:server_session_id]
rescue NoMethodError
nil
end
# This route will init the secure_session for us
get "/session/hp.json" if id.nil?
ServerSession.new(session[:server_session_id])
end
def write_secure_session(key, value)
secure_session = read_secure_session
secure_session[key] = value
secure_session
end
end