Commit 4671a965 authored by Ash McKenzie's avatar Ash McKenzie

Merge branch...

Merge branch '202084-downloading-source-code-on-geo-secondary-attempts-to-write-to-the-database' into 'master'

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

Closes #202084

See merge request gitlab-org/gitlab!24537
parents 90e5f60d 55b9f01a
...@@ -44,6 +44,8 @@ class AuditEventService ...@@ -44,6 +44,8 @@ class AuditEventService
end end
def log_security_event_to_database def log_security_event_to_database
return if Gitlab::Database.read_only?
SecurityEvent.create(base_payload.merge(details: @details)) SecurityEvent.create(base_payload.merge(details: @details))
end end
end end
......
...@@ -85,6 +85,16 @@ describe AuditEventService do ...@@ -85,6 +85,16 @@ describe AuditEventService do
it 'creates an event' do it 'creates an event' do
expect { service.security_event }.to change(SecurityEvent, :count).by(1) expect { service.security_event }.to change(SecurityEvent, :count).by(1)
end 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
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