Skip to content

Commit

Permalink
Support regular expressions in allowlist
Browse files Browse the repository at this point in the history
  • Loading branch information
bpo committed Jun 30, 2020
1 parent 855abc9 commit b1dbfe3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/database_cleaner/safeguard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def run
private

def database_url_not_allowed?
!DatabaseCleaner.url_allowlist.include?(ENV['DATABASE_URL'])
!DatabaseCleaner.url_allowlist.any? {|allowed| allowed.match?(ENV['DATABASE_URL']) }
end

def skip?
Expand Down
10 changes: 9 additions & 1 deletion spec/database_cleaner/safeguard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ module DatabaseCleaner
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
let(:database_url) { 'postgres://postgres@localhost' }

Expand All @@ -108,7 +116,7 @@ module DatabaseCleaner
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
before { DatabaseCleaner.url_allowlist = url_allowlist }
Expand Down

0 comments on commit b1dbfe3

Please sign in to comment.