-
Notifications
You must be signed in to change notification settings - Fork 484
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #660 from bpo/allowlist-regex
Support regular expressions in allowlist
- Loading branch information
Showing
4 changed files
with
44 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,11 +86,27 @@ module DatabaseCleaner | |
describe 'A remote url is not on the allowlist' do | ||
let(:database_url) { 'postgress://bar.baz' } | ||
|
||
it 'raises a allowlist error' do | ||
it 'raises a not allowed error' do | ||
expect { cleaner.start }.to raise_error(Safeguard::Error::UrlNotAllowed) | ||
end | ||
end | ||
|
||
describe 'A similar url not explicitly matched as a pattern' do | ||
let(:database_url) { 'postgres://foo.bar?pool=8' } | ||
|
||
it 'raises a not allowed 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 | ||
let(:database_url) { 'postgres://postgres@localhost' } | ||
|
||
|
@@ -106,9 +122,24 @@ module DatabaseCleaner | |
expect { cleaner.start }.to raise_error(Safeguard::Error::UrlNotAllowed) | ||
end | ||
end | ||
|
||
describe 'A url that matches a proc' do | ||
let(:database_url) { 'redis://test:[email protected]' } | ||
|
||
it 'does not raise' do | ||
expect { cleaner.start }.to_not raise_error | ||
end | ||
end | ||
end | ||
|
||
let(:url_allowlist) { ['postgres://postgres@localhost', 'postgres://foo.bar'] } | ||
let(:url_allowlist) do | ||
[ | ||
'postgres://postgres@localhost', | ||
'postgres://foo.bar', | ||
%r{^postgres://bar.baz}, | ||
proc { |x| URI.parse(x).user == 'test' } | ||
] | ||
end | ||
|
||
describe 'url_allowlist' do | ||
before { DatabaseCleaner.url_allowlist = url_allowlist } | ||
|