mirror of https://github.com/rails/rails
ActionCable: don't allowlist keys passed to the Redis initializer
Support all Redis features without needing to maintain a list of valid options that must stay in sync with the upstream client library.
This commit is contained in:
parent
70e255b9f2
commit
70d64169ae
|
@ -5,6 +5,8 @@ require "thread"
|
|||
gem "redis", ">= 3", "< 5"
|
||||
require "redis"
|
||||
|
||||
require "active_support/core_ext/hash/except"
|
||||
|
||||
module ActionCable
|
||||
module SubscriptionAdapter
|
||||
class Redis < Base # :nodoc:
|
||||
|
@ -14,7 +16,7 @@ module ActionCable
|
|||
# This is needed, for example, when using Makara proxies for distributed Redis.
|
||||
cattr_accessor :redis_connector, default: ->(config) do
|
||||
config[:id] ||= "ActionCable-PID-#{$$}"
|
||||
::Redis.new(config.slice(:url, :host, :port, :db, :password, :id))
|
||||
::Redis.new(config.except(:adapter, :channel_prefix))
|
||||
end
|
||||
|
||||
def initialize(*)
|
||||
|
|
|
@ -34,11 +34,11 @@ class RedisAdapterTest::AlternateConfiguration < RedisAdapterTest
|
|||
end
|
||||
|
||||
class RedisAdapterTest::Connector < ActionCable::TestCase
|
||||
test "slices url, host, port, db, password and id from config" do
|
||||
test "excludes adapter and channel prefix" do
|
||||
config = { url: 1, host: 2, port: 3, db: 4, password: 5, id: "Some custom ID" }
|
||||
|
||||
assert_called_with ::Redis, :new, [ config ] do
|
||||
connect config.merge(other: "unrelated", stuff: "here")
|
||||
connect config.merge(adapter: "redis", channel_prefix: "custom")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue