-
- describe '#check_password' do
- context 'correct password' do
- before do
- provider.class.stubs(:rabbitmqctl).with(
- 'eval',
- 'rabbit_access_control:check_user_pass_login(list_to_binary("rmq_x"), list_to_binary("secret")).'
- ).returns <<-EOT
-{ok,{user,<<"rmq_x">>,[],rabbit_auth_backend_internal,
- {internal_user,<<"rmq_x">>,
- <<193,81,62,182,129,135,196,89,148,87,227,48,86,2,154,
- 192,52,119,214,177>>,
- []}}}
-EOT
- end
-
- it do
- provider.check_password('secret')
- end
- end
-
- context 'incorrect password' do
- before do
- provider.class.stubs(:rabbitmqctl).with(
- 'eval',
- 'rabbit_access_control:check_user_pass_login(list_to_binary("rmq_x"), list_to_binary("nottherightone")).'
- ).returns <<-EOT
-{refused,"user '~s' - invalid credentials",[<<"rmq_x">>]}
-...done.
-EOT
- end
-
- it do
- provider.check_password('nottherightone')
- end
- end
+ it 'should create user and set password' do
+ @resource[:password] = 'bar'
+ @provider.expects(:rabbitmqctl).with('add_user', 'foo', 'bar')
+ @provider.create
+ end
+ it 'should create user, set password and set to admin' do
+ @resource[:password] = 'bar'
+ @resource[:admin] = 'true'
+ @provider.expects(:rabbitmqctl).with('add_user', 'foo', 'bar')
+ @provider.expects(:rabbitmqctl).with('-q', 'list_users').returns <<-EOT
+foo []
+icinga [monitoring]
+kitchen []
+kitchen2 [abc, def, ghi]
+EOT
+ @provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', ['administrator'])
+ @provider.create
+ end
+ it 'should call rabbitmqctl to delete' do
+ @provider.expects(:rabbitmqctl).with('delete_user', 'foo')
+ @provider.destroy
+ end
+ it 'should be able to retrieve admin value' do
+ @provider.expects(:rabbitmqctl).with('-q', 'list_users').returns <<-EOT
+foo [administrator]
+EOT
+ @provider.admin.should == :true
+ @provider.expects(:rabbitmqctl).with('-q', 'list_users').returns <<-EOT
+one [administrator]
+foo []
+EOT
+ @provider.admin.should == :false
+ end
+ it 'should fail if admin value is invalid' do
+ @provider.expects(:rabbitmqctl).with('-q', 'list_users').returns <<-EOT
+foo fail
+EOT
+ expect { @provider.admin }.to raise_error(Puppet::Error, /Could not match line/)
+ end
+ it 'should be able to set admin value' do
+ @provider.expects(:rabbitmqctl).with('-q', 'list_users').returns <<-EOT
+foo []
+icinga [monitoring]
+kitchen []
+kitchen2 [abc, def, ghi]
+EOT
+ @provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', ['administrator'])
+ @provider.admin=:true
+ end
+ it 'should not interfere with existing tags on the user when setting admin value' do
+ @provider.expects(:rabbitmqctl).with('-q', 'list_users').returns <<-EOT
+foo [bar, baz]
+icinga [monitoring]
+kitchen []
+kitchen2 [abc, def, ghi]
+EOT
+ @provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', ['bar','baz', 'administrator'].sort)
+ @provider.admin=:true
+ end
+ it 'should be able to unset admin value' do
+ @provider.expects(:rabbitmqctl).with('-q', 'list_users').returns <<-EOT
+foo [administrator]
+guest [administrator]
+icinga []
+EOT
+ @provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', [])
+ @provider.admin=:false
+ end
+ it 'should not interfere with existing tags on the user when unsetting admin value' do
+ @provider.expects(:rabbitmqctl).with('-q', 'list_users').returns <<-EOT
+foo [administrator, bar, baz]
+icinga [monitoring]
+kitchen []
+kitchen2 [abc, def, ghi]
+EOT
+ @provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', ['bar','baz'].sort)
+ @provider.admin=:false