Commit a03429aa authored by Sean McGivern's avatar Sean McGivern

Fix display of IP addresses in audit logs

The `ip_address` column returns an IPAddr, which doesn't specify a JSON
representation so we get the Rails default of a hash of its instance
variables. We need an explicit `to_s` to show it in human-readable form.
parent c3caf581
...@@ -18,7 +18,7 @@ class AuditEventPresenter < Gitlab::View::Presenter::Simple ...@@ -18,7 +18,7 @@ class AuditEventPresenter < Gitlab::View::Presenter::Simple
end end
def ip_address def ip_address
audit_event.ip_address || details[:ip_address] audit_event.ip_address&.to_s || details[:ip_address]
end end
def details def details
......
---
title: Fix display of IP addresses in audit logs
merge_request: 35356
author:
type: fixed
...@@ -107,6 +107,10 @@ RSpec.describe AuditEventPresenter do ...@@ -107,6 +107,10 @@ RSpec.describe AuditEventPresenter do
expect(presenter.ip_address).to eq('10.2.1.1') expect(presenter.ip_address).to eq('10.2.1.1')
end end
it 'survives a round trip from JSON' do
expect(Gitlab::Json.parse(presenter.ip_address.to_json)).to eq(presenter.ip_address)
end
it 'falls back to the details hash' do it 'falls back to the details hash' do
audit_event.update(ip_address: nil) audit_event.update(ip_address: nil)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment