Conversation
connection_credentials_from_server only ever extracted credentials
from userinfo embedded in the server's url (e.g.
"amqp://user:pass@host:port/vhost"). When an app instead configures
credentials as separate fields, as EventSource.configure's DSL
explicitly supports:
config.servers do |server|
server.amqp do |rabbitmq|
rabbitmq.url = ENV["RABBITMQ_URL_EVENT_SOURCE"]
rabbitmq.user_name = ENV["RABBITMQ_USERNAME"]
rabbitmq.password = ENV["RABBITMQ_PASSWORD"]
end
end
...those fields were silently ignored whenever url was also present,
and the real Bunny connection fell back to ConnectDefaults' guest/guest
unless the url happened to also embed working credentials. This made
connection_params (and the real running connection) look correct in
some environments purely by coincidence, and wrong in others with no
error raised.
Now server[:user_name]/server[:password] take precedence when both are
present, falling back to url-embedded credentials otherwise. Existing
url-embedded-credential behavior is unchanged (see the "given a url
with non-default credentials" spec, still passing).
connection_uri is untouched by this change - it stays a display-only,
credential-free string (used for logging and as the connection
registry key), so nothing about what gets logged changes.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Found while tracking down dchbx/edi_journal#194 — a consumer app was misusing
connection_uri(a display-only, credential-free string) to open a manual Bunny connection. While tracing why the correct API (connection_params) is guaranteed to work, found a real gap underneath it.The bug
BunnyConnectionProxy.connection_credentials_from_serveronly ever pulled credentials from userinfo embedded in the server'surl(amqp://user:pass@host:port/vhost). ButEventSource.configure's own DSL explicitly supports configuring credentials as separate fields:Whenever
urlwas also present (which it almost always is), those separately-configureduser_name/passwordfields were silently ignored, and the real connection fell back toConnectDefaults'guest/guestunlessurlalso happened to embed working credentials. That meansconnection_params(and the actual Bunny connection built from it) only worked correctly by coincidence in some environments, and would silently authenticate asguest/guestin others — no error raised, just a connection that may or may not be to the right account.The fix
server[:user_name]/server[:password]now take precedence when both are present, falling back to URL-embedded credentials otherwise. Existing URL-embedded-credential behavior is unchanged — the existing "given a url with non-default credentials" spec still passes.connection_uriis untouched — it stays a display-only, credential-free string (used for logging and as the connection registry key inConnectionManager), so nothing about what gets logged changes, and there's no risk of leaking credentials into logs.Test plan
user_name/passwordfields with a credential-freeurl.nio4r/Rails 6.1 native-extension issue on this Gemfile.lock).🤖 Generated with Claude Code