Skip to content

Commit

Permalink
Fix for #147, breaking out from #598
Browse files Browse the repository at this point in the history
  • Loading branch information
William Yardley committed Sep 12, 2017
1 parent 111532c commit d241d64
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
2 changes: 2 additions & 0 deletions lib/puppet/provider/rabbitmq_user/rabbitmqctl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def self.instances
end

def create
raise Puppet::Error, "Password is a required parameter for rabbitmq_user (user: #{name})" if @resource[:password].nil?

rabbitmqctl('add_user', resource[:name], resource[:password])
make_user_admin if resource[:admin] == :true
set_user_tags(resource[:tags]) unless resource[:tags].empty?
Expand Down
6 changes: 0 additions & 6 deletions lib/puppet/type/rabbitmq_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,4 @@ def should_to_s(newvalue = @should)
end
end
end

validate do
if self[:ensure] == :present && !self[:password]
raise ArgumentError, 'must set password when creating user' unless self[:password]
end
end
end
19 changes: 13 additions & 6 deletions spec/unit/puppet/provider/rabbitmq_user/rabbitmqctl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@
end
it 'does not match if no users on system' do
provider.expects(:rabbitmqctl).with('-q', 'list_users').returns <<-EOT
EOT
expect(provider.exists?).to be_nil
end
it 'does not match if no matching users on system' do
provider.expects(:rabbitmqctl).with('-q', 'list_users').returns <<-EOT
fooey
EOT
expect(provider.exists?).to be_nil
end
Expand All @@ -41,6 +35,19 @@
EOT
expect(provider.exists?).to eq('foo')
end
context 'when no password is given' do
let(:resource) do
Puppet::Type::Rabbitmq_user.new(
name: 'rmq_x'
)
end

it 'raises an error' do
expect do
provider.create
end.to raise_error(Puppet::Error, 'Password is a required parameter for rabbitmq_user (user: rmq_x)')
end
end
it 'creates user and set password' do
resource[:password] = 'bar'
provider.expects(:rabbitmqctl).with('add_user', 'foo', 'bar')
Expand Down
5 changes: 0 additions & 5 deletions spec/unit/puppet/type/rabbitmq_user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@
user[:password] = 'foo'
expect(user[:password]).to eq('foo')
end
it 'requires a password' do
expect do
Puppet::Type.type(:rabbitmq_user).new(name: 'foo')
end.to raise_error(%r{must set password})
end
it 'requires a name' do
expect do
Puppet::Type.type(:rabbitmq_user).new({})
Expand Down

0 comments on commit d241d64

Please sign in to comment.