Skip to content

Commit f5826c4

Browse files
committed
DEV: Fix broken specs related to the recent server session changes
1 parent c7d901e commit f5826c4

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

app/controllers/discourse_activity_pub/authorization_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,11 @@ def ensure_authorization
190190
end
191191

192192
def get_session_value(key)
193-
secure_session[key]
193+
server_session[key]
194194
end
195195

196196
def set_session_value(key, value)
197-
secure_session.set(key, value, expires: SESSION_EXPIRY_MINUTES.minutes)
197+
server_session.set(key, value, expires: SESSION_EXPIRY_MINUTES.minutes)
198198
end
199199

200200
def redirect_params

spec/requests/discourse_activity_pub/authorization_controller_spec.rb

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121

122122
it "sets the domain as the verified domain in the session" do
123123
post "/ap/auth/verify", params: { domain: external_domain1, auth_type: "mastodon" }
124-
expect(read_secure_session[described_class::DOMAIN_SESSION_KEY]).to eq(external_domain1)
124+
expect(server_session[described_class::DOMAIN_SESSION_KEY]).to eq(external_domain1)
125125
end
126126

127127
it "creates a client" do
@@ -158,7 +158,7 @@
158158

159159
it "does not set the domain in the session" do
160160
post "/ap/auth/verify", params: { domain: external_domain2, auth_type: "mastodon" }
161-
expect(read_secure_session[described_class::DOMAIN_SESSION_KEY]).to eq(nil)
161+
expect(server_session[described_class::DOMAIN_SESSION_KEY]).to eq(nil)
162162
end
163163

164164
it "does not create a client" do
@@ -211,7 +211,7 @@
211211

212212
it "sets the domain as the verified domain in the session" do
213213
post "/ap/auth/verify", params: { domain: external_domain1, auth_type: "discourse" }
214-
expect(read_secure_session[described_class::DOMAIN_SESSION_KEY]).to eq(external_domain1)
214+
expect(server_session[described_class::DOMAIN_SESSION_KEY]).to eq(external_domain1)
215215
end
216216

217217
it "creates a client" do
@@ -239,10 +239,9 @@
239239

240240
context "with a verified domain in the session" do
241241
before do
242-
write_secure_session(
243-
DiscourseActivityPub::AuthorizationController::DOMAIN_SESSION_KEY,
244-
external_domain1,
245-
)
242+
server_session[
243+
DiscourseActivityPub::AuthorizationController::DOMAIN_SESSION_KEY
244+
] = external_domain1
246245
end
247246

248247
context "with an invalid auth_type" do
@@ -288,15 +287,15 @@
288287
get "/ap/auth/authorize/discourse"
289288
expect(
290289
DiscourseActivityPubAuthorization.exists?(
291-
read_secure_session[described_class::AUTHORIZATION_SESSION_KEY].to_i,
290+
server_session[described_class::AUTHORIZATION_SESSION_KEY].to_i,
292291
),
293292
).to eq(true)
294293
end
295294

296295
it "saves a nonce to the session" do
297296
ENV["ACTIVITY_PUB_TEST_RANDOM_HEX"] = "123"
298297
get "/ap/auth/authorize/discourse"
299-
expect(read_secure_session[described_class::NONCE_SESSION_KEY]).to eq("123")
298+
expect(server_session[described_class::NONCE_SESSION_KEY]).to eq("123")
300299
end
301300

302301
it "redirects to the authorize url for the app" do
@@ -323,10 +322,9 @@
323322
let!(:authorization) { Fabricate(:discourse_activity_pub_authorization_mastodon, user: user) }
324323

325324
before do
326-
write_secure_session(
327-
DiscourseActivityPub::AuthorizationController::AUTHORIZATION_SESSION_KEY,
328-
authorization.id,
329-
)
325+
server_session[
326+
DiscourseActivityPub::AuthorizationController::AUTHORIZATION_SESSION_KEY
327+
] = authorization.id
330328
end
331329

332330
context "with mastodon" do
@@ -436,20 +434,18 @@
436434
end
437435

438436
before do
439-
write_secure_session(
440-
DiscourseActivityPub::AuthorizationController::AUTHORIZATION_SESSION_KEY,
441-
authorization.id,
442-
)
437+
server_session[
438+
DiscourseActivityPub::AuthorizationController::AUTHORIZATION_SESSION_KEY
439+
] = authorization.id
443440
end
444441

445442
context "with a nonce in the session" do
446443
let!(:nonce) { "12345" }
447444

448445
before do
449-
write_secure_session(
450-
DiscourseActivityPub::AuthorizationController::NONCE_SESSION_KEY,
451-
nonce,
452-
)
446+
server_session[
447+
DiscourseActivityPub::AuthorizationController::NONCE_SESSION_KEY
448+
] = nonce
453449
end
454450

455451
context "when the callback has a valid payload" do

0 commit comments

Comments
 (0)