Don't log security event to database on a read-only instance

Downloading the project source code on a Geo secondary
node tries to log a security event to the database
raising a  `PG::ReadOnlySqlTransaction` error.
parent a11fca06
......@@ -44,6 +44,8 @@ class AuditEventService
end
def log_security_event_to_database
return if Gitlab::Database.read_only?
SecurityEvent.create(base_payload.merge(details: @details))
end
end
......
......@@ -85,6 +85,16 @@ describe AuditEventService do
it 'creates an event' do
expect { service.security_event }.to change(SecurityEvent, :count).by(1)
end
context 'on a read-only instance' do
before do
allow(Gitlab::Database).to receive(:read_only?).and_return(true)
end
it 'does not create an event' do
expect { service.security_event }.not_to change(SecurityEvent, :count)
end
end
end
end
......
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