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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
# frozen_string_literal: true
require_relative '../helper'
describe 'authentication options' do
it 'warns when username is provided' do
logged_messages = []
original_logger = Dalli.logger
Dalli.logger = Logger.new(StringIO.new).tap do |logger|
logger.define_singleton_method(:warn) { |msg| logged_messages << msg }
end
begin
memcached_persistent(:meta, 21_345, '') do |_dc, port|
# Create client with auth options that should trigger warnings
client = Dalli::Client.new("localhost:#{port}", username: 'user', password: 'pass')
client.flush
client.set('key1', 'abcd')
assert_equal 'abcd', client.get('key1')
end
assert_includes logged_messages, 'Dalli 5.0 removed SASL authentication support. The :username option is ignored.'
assert_includes logged_messages, 'Dalli 5.0 removed SASL authentication support. The :password option is ignored.'
ensure
Dalli.logger = original_logger
end
end
it 'warns when protocol: :binary option is provided' do
logged_messages = []
original_logger = Dalli.logger
Dalli.logger = Logger.new(StringIO.new).tap do |logger|
logger.define_singleton_method(:warn) { |msg| logged_messages << msg }
end
begin
memcached_persistent(:meta, 21_346, '') do |_dc, port|
# Create client with binary protocol option that should trigger warning
# This is the more common case - users upgrading from 4.x with explicit binary protocol
client = Dalli::Client.new("localhost:#{port}", protocol: :binary)
client.flush
client.set('key1', 'value')
assert_equal 'value', client.get('key1')
end
assert_includes logged_messages,
'Dalli 5.0 only supports the meta protocol. The :protocol option has been removed.'
ensure
Dalli.logger = original_logger
end
end
it 'warns when credentials are embedded in memcached:// URI' do
logged_messages = []
original_logger = Dalli.logger
Dalli.logger = Logger.new(StringIO.new).tap do |logger|
logger.define_singleton_method(:warn) { |msg| logged_messages << msg }
end
begin
memcached_persistent(:meta, 21_347, '') do |_dc, port|
# Create client with credentials in URI that should trigger warning
client = Dalli::Client.new("memcached://user:pass@localhost:#{port}")
client.flush
client.set('key1', 'value')
assert_equal 'value', client.get('key1')
end
assert_includes logged_messages,
'Dalli 5.0 removed SASL authentication. Credentials in memcached:// URIs are ignored.'
ensure
Dalli.logger = original_logger
end
end
end
|