-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ACLs to use block & allowlists (#795)
ACLs to use block & allowlists
- Loading branch information
Showing
3 changed files
with
82 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
require 'spec_helper' | ||
require 'ood_core/acl/adapters/group' | ||
|
||
describe OodCore::Acl::Adapters::Group do | ||
|
||
def build_group_acl(opts = {}) | ||
OodCore::Acl::Factory.build_group(opts) | ||
end | ||
|
||
describe "#new" do | ||
context 'when nothing is provided' do | ||
it 'raises an error' do | ||
expect { subject }.to raise_error(ArgumentError) | ||
end | ||
end | ||
end | ||
|
||
describe '#allow' do | ||
context 'when allowlist is provided' do | ||
subject { build_group_acl({ groups: ['group-a', 'group-x'], type: 'allowlist' }) } | ||
|
||
it 'allows users in that group' do | ||
allow_any_instance_of(OodSupport::User).to receive(:groups).and_return(['group-a', 'group-b']) | ||
expect(subject.allow?).to eql(true) | ||
end | ||
|
||
it 'blocks uses not in that group' do | ||
allow_any_instance_of(OodSupport::User).to receive(:groups).and_return(['group-c', 'group-d']) | ||
expect(subject.allow?).to eql(false) | ||
end | ||
end | ||
|
||
context 'when blocklist is provided' do | ||
subject { build_group_acl({ groups: ['group-a', 'group-x'], type: 'blocklist' }) } | ||
|
||
it 'blocks users in that group' do | ||
allow_any_instance_of(OodSupport::User).to receive(:groups).and_return(['group-a', 'group-b']) | ||
expect(subject.allow?).to eql(false) | ||
end | ||
|
||
it 'allows uses not in that group' do | ||
allow_any_instance_of(OodSupport::User).to receive(:groups).and_return(['group-c', 'group-d']) | ||
expect(subject.allow?).to eql(true) | ||
end | ||
end | ||
|
||
context 'when whitelist is provided' do | ||
subject { build_group_acl({ groups: ['group-a', 'group-x'], type: 'whitelist' }) } | ||
|
||
it 'allows users in that group' do | ||
allow_any_instance_of(OodSupport::User).to receive(:groups).and_return(['group-a', 'group-b']) | ||
expect(subject.allow?).to eql(true) | ||
end | ||
|
||
it 'blocks uses not in that group' do | ||
allow_any_instance_of(OodSupport::User).to receive(:groups).and_return(['group-c', 'group-d']) | ||
expect(subject.allow?).to eql(false) | ||
end | ||
end | ||
|
||
context 'when blacklist is provided' do | ||
subject { build_group_acl({ groups: ['group-a', 'group-x'], type: 'blacklist' }) } | ||
|
||
it 'blocks users in that group' do | ||
allow_any_instance_of(OodSupport::User).to receive(:groups).and_return(['group-a', 'group-b']) | ||
expect(subject.allow?).to eql(false) | ||
end | ||
|
||
it 'allows uses not in that group' do | ||
allow_any_instance_of(OodSupport::User).to receive(:groups).and_return(['group-c', 'group-d']) | ||
expect(subject.allow?).to eql(true) | ||
end | ||
end | ||
end | ||
end |