Commit 2b4bd317 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'cat-prevent-group-wiki-readonly-db-writes' into 'master'

Prevent group wiki writes on read-only DBs

See merge request gitlab-org/gitlab!71314
parents f2dd23a7 900b0719
......@@ -12,6 +12,8 @@ class GroupWiki < Wiki
end
def track_wiki_repository(shard)
return unless ::Gitlab::Database.read_write?
storage_record = container.group_wiki_repository || container.build_group_wiki_repository
storage_record.update!(shard_name: shard, disk_path: storage.disk_path)
end
......
......@@ -47,6 +47,16 @@ RSpec.describe GroupWiki do
shard_name: shard
)
end
context 'on a read-only instance' do
before do
allow(Gitlab::Database).to receive(:read_only?).and_return(true)
end
it 'does not attempt to create a new entry' do
expect { subject.track_wiki_repository(shard) }.not_to change(wiki_container, :group_wiki_repository)
end
end
end
context 'when a tracking entry exists' do
......@@ -64,6 +74,23 @@ RSpec.describe GroupWiki do
shard_name: shard
)
end
context 'on a read-only instance' do
before do
allow(Gitlab::Database).to receive(:read_only?).and_return(true)
end
it 'does not update the storage location' do
allow(subject.storage).to receive(:disk_path).and_return('fancy/new/path')
subject.track_wiki_repository(shard)
expect(wiki_container.group_wiki_repository).not_to have_attributes(
disk_path: 'fancy/new/path',
shard_name: shard
)
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