mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
Support regular expressions in allowlist
This commit is contained in:
parent
855abc968d
commit
d3078d14de
2 changed files with 18 additions and 2 deletions
|
@ -29,7 +29,7 @@ module DatabaseCleaner
|
||||||
private
|
private
|
||||||
|
|
||||||
def database_url_not_allowed?
|
def database_url_not_allowed?
|
||||||
!DatabaseCleaner.url_allowlist.include?(ENV['DATABASE_URL'])
|
!DatabaseCleaner.url_allowlist.any? {|allowed| allowed === ENV['DATABASE_URL'] }
|
||||||
end
|
end
|
||||||
|
|
||||||
def skip?
|
def skip?
|
||||||
|
|
|
@ -91,6 +91,22 @@ module DatabaseCleaner
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'A similar url not explicitly matched as a pattern' do
|
||||||
|
let(:database_url) { 'postgres://foo.bar?pool=8' }
|
||||||
|
|
||||||
|
it 'raises an allowlist error' do
|
||||||
|
expect { cleaner.start }.to raise_error(Safeguard::Error::UrlNotAllowed)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'A remote url matches a pattern on the allowlist' do
|
||||||
|
let(:database_url) { 'postgres://bar.baz?pool=16' }
|
||||||
|
|
||||||
|
it 'does not raise' do
|
||||||
|
expect { cleaner.start }.to_not raise_error
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe 'A local url is on the allowlist' do
|
describe 'A local url is on the allowlist' do
|
||||||
let(:database_url) { 'postgres://postgres@localhost' }
|
let(:database_url) { 'postgres://postgres@localhost' }
|
||||||
|
|
||||||
|
@ -108,7 +124,7 @@ module DatabaseCleaner
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:url_allowlist) { ['postgres://postgres@localhost', 'postgres://foo.bar'] }
|
let(:url_allowlist) { ['postgres://postgres@localhost', 'postgres://foo.bar', %r{^postgres://bar.baz}] }
|
||||||
|
|
||||||
describe 'url_allowlist' do
|
describe 'url_allowlist' do
|
||||||
before { DatabaseCleaner.url_allowlist = url_allowlist }
|
before { DatabaseCleaner.url_allowlist = url_allowlist }
|
||||||
|
|
Loading…
Reference in a new issue