FIX: Updating presence status in readonly mode should fail gracefully (#24333)

This commit is contained in:
Daniel Waterworth 2023-11-10 14:27:43 -06:00 committed by GitHub
parent bed4b3ee91
commit e845138bc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 0 deletions

View File

@ -11,3 +11,15 @@ Discourse/NoResetColumnInformationInMigrations:
Lint/Debugger:
Exclude:
- script/**/*
RSpec/ContextWording:
Prefixes:
- when
- with
- without
- for
- while
- if
- as
- after
- in

View File

@ -42,6 +42,8 @@ class PresenceController < ApplicationController
end
def update
raise Discourse::ReadOnly if @readonly_mode
client_id = params[:client_id]
if !client_id.is_a?(String) || client_id.blank?
raise Discourse::InvalidParameters.new(:client_id)

View File

@ -44,6 +44,25 @@ RSpec.describe PresenceController do
end
describe "#update" do
context "in readonly mode" do
use_redis_snapshotting
before { Discourse.enable_readonly_mode }
it "produces 503" do
sign_in(user)
client_id = SecureRandom.hex
post "/presence/update.json",
params: {
client_id: client_id,
present_channels: [ch1.name, ch2.name],
}
expect(response.status).to eq(503)
end
end
it "works" do
sign_in(user)
client_id = SecureRandom.hex