mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[openstack] Add tests for subtree_as_list and parents_as_list in hierarchical projects
Also enhanced identity service to make the ID of the current user accessible as current_user_id. Note that the returned lists are empty (even if *_as_ids return values) unless the calling user has a role in the projects - i.e. the only projects returned are those for which the user has a role.
This commit is contained in:
parent
600bb4fb77
commit
ecf4ec15b8
6 changed files with 459 additions and 125 deletions
|
@ -59,6 +59,7 @@ module Fog
|
|||
attr_reader :auth_token
|
||||
attr_reader :auth_token_expiration
|
||||
attr_reader :current_user
|
||||
attr_reader :current_user_id
|
||||
attr_reader :current_tenant
|
||||
attr_reader :openstack_domain_name
|
||||
attr_reader :openstack_user_domain
|
||||
|
@ -109,6 +110,7 @@ module Fog
|
|||
end
|
||||
|
||||
@current_user = options[:current_user]
|
||||
@current_user_id = options[:current_user_id]
|
||||
@current_tenant = options[:current_tenant]
|
||||
|
||||
end
|
||||
|
@ -127,6 +129,7 @@ module Fog
|
|||
:openstack_identity_endpoint => @openstack_identity_public_endpoint,
|
||||
:openstack_region => @openstack_region,
|
||||
:current_user => @current_user,
|
||||
:current_user_id => @current_user_id,
|
||||
:current_tenant => @current_tenant }
|
||||
end
|
||||
|
||||
|
@ -158,6 +161,7 @@ module Fog
|
|||
credentials = Fog::OpenStack.authenticate(options, @connection_options)
|
||||
|
||||
@current_user = credentials[:user]
|
||||
@current_user_id = credentials[:current_user_id]
|
||||
@current_tenant = credentials[:tenant]
|
||||
|
||||
@openstack_must_reauthenticate = false
|
||||
|
|
|
@ -44,6 +44,7 @@ module Fog
|
|||
credentials = Fog::OpenStack.authenticate(options, @connection_options)
|
||||
|
||||
@current_user = credentials[:user]
|
||||
@current_user_id = credentials[:current_user_id]
|
||||
@current_tenant = credentials[:tenant]
|
||||
|
||||
@openstack_must_reauthenticate = false
|
||||
|
|
|
@ -13,7 +13,7 @@ module Fog
|
|||
:openstack_user_domain, :openstack_project_domain,
|
||||
:openstack_user_domain_id, :openstack_project_domain_id,
|
||||
:openstack_api_key, :openstack_current_user_id, :openstack_userid, :openstack_username,
|
||||
:current_user, :current_tenant,
|
||||
:current_user, :current_user_id, :current_tenant,
|
||||
:provider
|
||||
|
||||
model_path 'fog/openstack/models/identity_v3'
|
||||
|
@ -149,6 +149,7 @@ module Fog
|
|||
|
||||
class Real
|
||||
attr_reader :current_user
|
||||
attr_reader :current_user_id
|
||||
attr_reader :current_tenant
|
||||
attr_reader :unscoped_token
|
||||
attr_accessor :auth_token
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -628,7 +628,13 @@ RSpec.describe Fog::Identity::OpenStack::V3 do
|
|||
booboo_project = @service.projects.create(:name => 'p-booboo67', :parent_id => boo_id)
|
||||
booboo_id = booboo_project.id
|
||||
|
||||
# Get the children of foobar
|
||||
# Make sure we have a role on all these projects (needed for subtree_as_list and parents_as_list)
|
||||
prj_role = @service.roles.create(:name => 'r-project67')
|
||||
[foobar_project, baz_project, boo_project, booboo_project].each do |project|
|
||||
project.grant_role_to_user(prj_role.id, @service.current_user_id)
|
||||
end
|
||||
|
||||
# Get the children of foobar, as a tree of IDs
|
||||
foobar_kids = @service.projects.find_by_id(foobar_id, :subtree_as_ids).subtree
|
||||
expect(foobar_kids.keys.length).to eq 2
|
||||
|
||||
|
@ -640,7 +646,13 @@ RSpec.describe Fog::Identity::OpenStack::V3 do
|
|||
foobar_grandchild_id = foobar_kids[foobar_child_id].keys.first
|
||||
expect(foobar_grandchild_id).to eq booboo_id
|
||||
|
||||
# Get the parents of booboo
|
||||
# Get the children of foobar, as a list of objects
|
||||
foobar_kids = @service.projects.find_by_id(foobar_id, :subtree_as_list).subtree
|
||||
expect(foobar_kids.length).to eq 3
|
||||
expect([foobar_kids[0]['project']['id'],foobar_kids[1]['project']['id'],foobar_kids[2]['project']['id']].sort
|
||||
).to eq [baz_id, boo_id, booboo_id].sort
|
||||
|
||||
# Get the parents of booboo, as a tree of IDs
|
||||
booboo_parents = @service.projects.find_by_id(booboo_id, :parents_as_ids).parents
|
||||
expect(booboo_parents.keys.length).to eq 1
|
||||
booboo_parent_id = booboo_parents.keys.first
|
||||
|
@ -649,13 +661,19 @@ RSpec.describe Fog::Identity::OpenStack::V3 do
|
|||
expect(booboo_grandparent_id).to eq foobar_id
|
||||
expect(booboo_parents[booboo_parent_id][booboo_grandparent_id]).to be_nil
|
||||
|
||||
# Get the parents of booboo, as a list of objects
|
||||
booboo_parents = @service.projects.find_by_id(booboo_id, :parents_as_list).parents
|
||||
expect(booboo_parents.length).to eq 2
|
||||
expect([booboo_parents[0]['project']['id'],booboo_parents[1]['project']['id']].sort
|
||||
).to eq [foobar_id, boo_id].sort
|
||||
ensure
|
||||
# Delete the projects
|
||||
booboo_project.destroy if booboo_project
|
||||
boo_project.destroy if boo_project
|
||||
baz_project.destroy if baz_project
|
||||
foobar_project.destroy if foobar_project
|
||||
|
||||
prj_role = @service.roles.all(:name => 'r-project67').first unless prj_role
|
||||
prj_role.destroy if prj_role
|
||||
# Check that the deletion worked
|
||||
expect { @service.projects.find_by_id foobar_id }.to raise_error(Fog::Identity::OpenStack::NotFound)
|
||||
['p-foobar67', 'p-baz67', 'p-boo67', 'p-booboo67'].each do |project_name|
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
require 'rspec/core'
|
||||
require 'rspec/expectations'
|
||||
require 'vcr'
|
||||
require 'fog/openstack/identity'
|
||||
require 'fog/openstack/identity_v3'
|
||||
require 'fog/openstack/network'
|
||||
|
||||
#
|
||||
# There are basically two modes of operation for these specs.
|
||||
|
|
Loading…
Add table
Reference in a new issue