From 989e6a8c069ab7534663f096c42b28b0a3f4cef0 Mon Sep 17 00:00:00 2001 From: "Sebastian.Meinhardt" Date: Thu, 22 May 2025 17:32:21 +0200 Subject: [PATCH] Set the current host in the SASL configs --- kafka/conn.py | 1 + test/test_conn.py | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/kafka/conn.py b/kafka/conn.py index c9cdd595f..b396b9778 100644 --- a/kafka/conn.py +++ b/kafka/conn.py @@ -256,6 +256,7 @@ def __init__(self, host, port, afi, **configs): for key in self.config: if key in configs: self.config[key] = configs[key] + self.config['host'] = host self.node_id = self.config.pop('node_id') diff --git a/test/test_conn.py b/test/test_conn.py index 037cd015e..8d56668c5 100644 --- a/test/test_conn.py +++ b/test/test_conn.py @@ -386,3 +386,13 @@ def test_maybe_throttle(conn): time.return_value = 3000 assert not conn.throttled() + + +def test_host_in_sasl_config(): + hostname = 'example.org' + port = 9092 + for security_protocol in ('SASL_PLAINTEXT', 'SASL_SSL'): + with mock.patch("kafka.conn.get_sasl_mechanism") as get_sasl_mechanism: + BrokerConnection(hostname, port, socket.AF_UNSPEC, security_protocol=security_protocol) + call_config = get_sasl_mechanism.mock_calls[1].kwargs + assert call_config['host'] == hostname