mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
Add docs and another allowlist example
This commit is contained in:
parent
a25ae50bc1
commit
089f8dc619
3 changed files with 22 additions and 3 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
=== Changes
|
||||
* Rename `url_whitelist` to `url_allowlist`
|
||||
* Allowlist now supports regular expressions
|
||||
|
||||
=== Breaking changes
|
||||
* Failed checks against the allowlist now raise `UrlNotAllowed` rather than `NotWhitelistedUrl`
|
||||
|
|
|
@ -349,10 +349,13 @@ to one of the values specified in the url allowlist like so:
|
|||
DatabaseCleaner.url_allowlist = ['postgres://postgres@localhost', 'postgres://foo@bar']
|
||||
```
|
||||
|
||||
Allowlist elements may be specified as regular expressions if extra flexibility is required::
|
||||
Allowlist elements are matched with case equality (`===`), so regular expressions or procs may be used:
|
||||
|
||||
```ruby
|
||||
DatabaseCleaner.url_allowlist = [%r{^postgres://postgres@localhost}]
|
||||
DatabaseCleaner.url_allowlist = [
|
||||
%r{^postgres://postgres@localhost}, # match any db with this prefix
|
||||
proc {|uri| URI.parse(uri).user == "test" } # match any db authenticating with the 'test' user
|
||||
]
|
||||
```
|
||||
|
||||
## COPYRIGHT
|
||||
|
|
|
@ -122,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:test@foo.bar' }
|
||||
|
||||
it 'does not raise' do
|
||||
expect { cleaner.start }.to_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
let(:url_allowlist) { ['postgres://postgres@localhost', 'postgres://foo.bar', %r{^postgres://bar.baz}] }
|
||||
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 }
|
||||
|
|
Loading…
Reference in a new issue