From 9b2078a6e5a892626a40be462bf7a8f88c2254da Mon Sep 17 00:00:00 2001 From: Valery Tschopp Date: Tue, 22 Jul 2014 14:46:00 +0200 Subject: [PATCH] keystone_user_role supports email as username When defining the keystone user with the email address, the keystone_user_role doesn't handle it correctly. user: "user@example.org" tenant: "test" keystone_user_role { "user@example.org@test": roles = '_member_' } Because of the use of the split('@',2) method, user and tenant will be parsed as: user: "user" tenant: "example.org@test" By using rpartition('@'), it will be correctly parsed as: user: "user@example.org" tenant: "test" A unit test for the keystone_user_role provider is available. Change-Id: I68139910bb82c62f26ba3433456e5406c99541a2 Closes-Bug: 1341552 --- .../provider/keystone_user_role/keystone.rb | 3 +- lib/puppet/type/keystone_user_role.rb | 8 ++-- .../keystone_user_role/keystone_spec.rb | 40 +++++++++++++++++++ 3 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 spec/unit/provider/keystone_user_role/keystone_spec.rb diff --git a/lib/puppet/provider/keystone_user_role/keystone.rb b/lib/puppet/provider/keystone_user_role/keystone.rb index e9d77fa5a..0b2d81b05 100644 --- a/lib/puppet/provider/keystone_user_role/keystone.rb +++ b/lib/puppet/provider/keystone_user_role/keystone.rb @@ -56,7 +56,8 @@ def self.get_user_and_tenant(user, tenant) end def get_user_and_tenant - user, tenant = resource[:name].split('@', 2) + user = resource[:name].rpartition('@').first + tenant = resource[:name].rpartition('@').last self.class.get_user_and_tenant(user, tenant) end diff --git a/lib/puppet/type/keystone_user_role.rb b/lib/puppet/type/keystone_user_role.rb index 0198cc299..60715fb8f 100644 --- a/lib/puppet/type/keystone_user_role.rb +++ b/lib/puppet/type/keystone_user_role.rb @@ -4,8 +4,8 @@ This is currently used to model the creation of keystone users roles. - User roles are an assigment of a role to a user on - a certain tenant. The combintation of all of these + User roles are an assignment of a role to a user on + a certain tenant. The combination of all of these attributes is unique. EOT @@ -32,11 +32,11 @@ end autorequire(:keystone_user) do - self[:name].split('@', 2).first + self[:name].rpartition('@').first end autorequire(:keystone_tenant) do - self[:name].split('@', 2).last + self[:name].rpartition('@').last end autorequire(:keystone_role) do diff --git a/spec/unit/provider/keystone_user_role/keystone_spec.rb b/spec/unit/provider/keystone_user_role/keystone_spec.rb new file mode 100644 index 000000000..04bac7241 --- /dev/null +++ b/spec/unit/provider/keystone_user_role/keystone_spec.rb @@ -0,0 +1,40 @@ +require 'puppet' +require 'spec_helper' +require 'puppet/provider/keystone_user_role/keystone' + +provider_class = Puppet::Type.type(:keystone_user_role).provider(:keystone) + +describe provider_class do + + describe '#get_user_and_tenant' do + + let :user do + 'username@example.org' + end + + let :tenant do + 'test' + end + + let :resource do + Puppet::Type::Keystone_user_role.new( + { + :name => "#{user}@#{tenant}", + :roles => [ '_member_' ], + } + ) + end + + let :provider do + provider_class.new(resource) + end + + before :each do + provider_class.expects(:get_user_and_tenant).with(user,tenant).returns([user,tenant]) + end + + it 'should handle an email address as username' do + provider.get_user_and_tenant.should == [ user, tenant ] + end + end +end