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 #8200 from Fryguy/update_permissions_template
Update permissions template
- Loading branch information
Showing
4 changed files
with
104 additions
and
66 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,35 @@ | ||
--- | ||
- :vi | ||
- :aut | ||
- :clo | ||
- :cnt | ||
- :compute | ||
- :con | ||
- :conf | ||
- :svc | ||
- :clo | ||
- :inf | ||
- :con | ||
- :cnt | ||
- :sto | ||
- :mdl | ||
- :net | ||
- :aut | ||
- :opt | ||
- :set | ||
- ems-type:foreman_configuration | ||
- ems-type:scvmm | ||
- ems-type:openstack_infra | ||
- ems-type:openstack_network | ||
- ems-type:rhevm | ||
- ems-type:vmwarews | ||
- :sto | ||
- :svc | ||
- :vi | ||
- ems-type:ansible_tower_configuration | ||
- ems-type:atomic | ||
- ems-type:atomic_enterprise | ||
- ems-type:azure | ||
- ems-type:azure_network | ||
- ems-type:ec2 | ||
- ems-type:openstack | ||
- ems-type:ec2_network | ||
- ems-type:foreman_configuration | ||
- ems-type:foreman_provisioning | ||
- ems-type:gce | ||
- ems-type:hawkular | ||
- ems-type:kubernetes | ||
- ems-type:openshift | ||
- ems-type:atomic | ||
- ems-type:openshift_enterprise | ||
- ems-type:atomic_enterprise | ||
- ems-type:foreman_provisioning | ||
- ems-type:gce | ||
- ems-type:openstack | ||
- ems-type:openstack_infra | ||
- ems-type:openstack_network | ||
- ems-type:rhevm | ||
- ems-type:scvmm | ||
- ems-type:vmwarews |
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 |
---|---|---|
@@ -1,73 +1,67 @@ | ||
require 'vmdb/permission_stores' | ||
require 'tempfile' | ||
|
||
describe Vmdb::PermissionStores do | ||
before(:each) do | ||
@original_store = Vmdb::PermissionStores.instance | ||
end | ||
|
||
after(:each) do | ||
Vmdb::PermissionStores.instance = @original_store | ||
end | ||
|
||
it 'should be configurable' do | ||
Vmdb::PermissionStores.configure do |config| | ||
config.backend = 'yaml' | ||
config.options[:filename] = 'some file' | ||
end | ||
config = Vmdb::PermissionStores.configuration | ||
stub_vmdb_permission_store do | ||
Vmdb::PermissionStores.configure do |config| | ||
config.backend = 'yaml' | ||
config.options[:filename] = 'some file' | ||
end | ||
config = Vmdb::PermissionStores.configuration | ||
|
||
expect(config.backend).to eq('yaml') | ||
expect(config.options[:filename]).to eq('some file') | ||
expect(config.backend).to eq('yaml') | ||
expect(config.options[:filename]).to eq('some file') | ||
end | ||
end | ||
|
||
context 'configuration' do | ||
it 'requires the backend' do | ||
required_file = nil | ||
stub_vmdb_permission_store do | ||
required_file = nil | ||
|
||
klass = Class.new(Vmdb::PermissionStores::Configuration) do | ||
define_method(:require) do |file| | ||
required_file = file | ||
klass = Class.new(Vmdb::PermissionStores::Configuration) do | ||
define_method(:require) do |file| | ||
required_file = file | ||
end | ||
end | ||
end | ||
|
||
config = klass.new | ||
config.backend = 'yaml' | ||
config.load | ||
|
||
expect(required_file).to eq('vmdb/permission_stores/yaml') | ||
end | ||
|
||
it 'can initialize the yaml back end' do | ||
Tempfile.create(['config', 'yml']) do |f| | ||
f.write Psych.dump(['foo']) | ||
f.close | ||
|
||
config = Vmdb::PermissionStores::Configuration.new | ||
config = klass.new | ||
config.backend = 'yaml' | ||
config.options[:filename] = f.path | ||
config.load | ||
expect(config.create).to be_truthy | ||
|
||
expect(required_file).to eq('vmdb/permission_stores/yaml') | ||
end | ||
end | ||
end | ||
|
||
context 'backend' do | ||
it 'can be asked about permissions' do | ||
Tempfile.create(['config', 'yml']) do |f| | ||
f.write Psych.dump(['foo']) | ||
f.close | ||
it 'can initialize the yaml back end' do | ||
stub_vmdb_permission_store do | ||
Tempfile.create(%w(config yml)) do |f| | ||
f.write(['foo'].to_yaml) | ||
f.close | ||
|
||
Vmdb::PermissionStores.configure do |config| | ||
config = Vmdb::PermissionStores::Configuration.new | ||
config.backend = 'yaml' | ||
config.options[:filename] = f.path | ||
config.load | ||
expect(config.create).to be_truthy | ||
end | ||
end | ||
end | ||
end | ||
|
||
Vmdb::PermissionStores.initialize! | ||
describe '::YAML' do | ||
it '#can?' do | ||
stub_vmdb_permission_store_with_types(["foo"]) do | ||
instance = Vmdb::PermissionStores.instance | ||
expect(instance.can?('foo')).to be_truthy | ||
expect(instance.can?('bar')).to be_falsey | ||
end | ||
end | ||
|
||
it '#supported_ems_type?' do | ||
stub_vmdb_permission_store_with_types(["ems-type:foo"]) do | ||
instance = Vmdb::PermissionStores.instance | ||
expect(instance.supported_ems_type?('foo')).to be_truthy | ||
expect(instance.supported_ems_type?('bar')).to be_falsey | ||
end | ||
end | ||
end | ||
end |
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,25 @@ | ||
require 'tempfile' | ||
|
||
def stub_vmdb_permission_store | ||
original_store = Vmdb::PermissionStores.instance | ||
yield | ||
ensure | ||
Vmdb::PermissionStores.instance = original_store | ||
end | ||
|
||
def stub_vmdb_permission_store_with_types(types) | ||
stub_vmdb_permission_store do | ||
Tempfile.create(%w(config yml)) do |f| | ||
f.write(types.to_yaml) | ||
f.close | ||
|
||
Vmdb::PermissionStores.configure do |config| | ||
config.backend = 'yaml' | ||
config.options[:filename] = f.path | ||
end | ||
Vmdb::PermissionStores.initialize! | ||
|
||
yield | ||
end | ||
end | ||
end |