Skip to content

Commit e3b9e48

Browse files
authored
Merge pull request #6853 from d3flex/fix/verbose_amqp_debug_logs
Prevent logging AMQP credentials in debug output
2 parents 9eb96c2 + 842dd0f commit e3b9e48

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

lib/OpenQA/WebAPI/Plugin/AMQP.pm

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,15 @@ sub publish_amqp ($self, $topic, $event_data, $headers = {}, $remaining_attempts
5858
# create publisher and keep reference to avoid early destruction
5959
log_debug("Sending AMQP event: $topic");
6060
my $config = $self->{config}->{amqp};
61-
my $url = Mojo::URL->new($config->{url});
62-
$url->query({exchange => $config->{exchange}});
61+
my $unsanitized_url = Mojo::URL->new($config->{url});
62+
$unsanitized_url->query({exchange => $config->{exchange}});
6363
# append optional parameters
64-
$url->query([cacertfile => $config->{cacertfile}]) if ($config->{cacertfile});
65-
$url->query([certfile => $config->{certfile}]) if ($config->{certfile});
66-
$url->query([keyfile => $config->{keyfile}]) if ($config->{keyfile});
67-
$url = $url->to_unsafe_string;
68-
my $publisher = Mojo::RabbitMQ::Client::Publisher->new(url => $url);
64+
$unsanitized_url->query([cacertfile => $config->{cacertfile}]) if ($config->{cacertfile});
65+
$unsanitized_url->query([certfile => $config->{certfile}]) if ($config->{certfile});
66+
$unsanitized_url->query([keyfile => $config->{keyfile}]) if ($config->{keyfile});
67+
my $url = $unsanitized_url->clone;
68+
$unsanitized_url = $unsanitized_url->to_unsafe_string;
69+
my $publisher = Mojo::RabbitMQ::Client::Publisher->new(url => $unsanitized_url);
6970
log_debug("AMQP URL: $url");
7071

7172
$remaining_attempts //= $config->{publish_attempts};

t/23-amqp.t

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,8 @@ my $amqp = OpenQA::WebAPI::Plugin::AMQP->new;
276276
$amqp->register($app);
277277

278278
subtest 'amqp_publish call without headers' => sub {
279-
$amqp->publish_amqp('some.topic', 'some message');
279+
combined_like { $amqp->publish_amqp('some.topic', 'some message') } qr/AMQP URL: amqp:\/\/localhost:5672/,
280+
'URL is logged without credentials';
280281
is($last_publisher->url, 'amqp://guest:guest@localhost:5672/?exchange=pubsub', 'url specified');
281282
is($published{body}, 'some message', 'message body correctly passed');
282283
is_deeply($published{headers}, {}, 'headers is empty hashref');

0 commit comments

Comments
 (0)