Hi Brandon,Yes.In the main recipe, it iterates through the userlist and decrypts each encrypted data bag.What I would like to do is to stub the code that performs the decryption (have refactored my code so have put the decryption into a method) so essentially pass it a canned encrypted data bag and have it spit out a canned id and password. This will ensure that this error Failed to read the private key C:\chef\client.pem: #<Errno::ENOENT: No such file or directory - C:\chef\client.pem> doens't arise as the method that calls the decryption will be stubbed.Hope that helps.ThanksSent from iCloudAngela, Are you loading more than one encrypted data bag item in that recipe? From the backtrace, it looks like you might be iterating through a list of users.On Mon, Mar 16, 2015 at 7:47 AM, ANGELA EBIRIM < " target="_blank"> > wrote:Still getting the same error which means the stub isn't working.thanks anywaySent from iCloudQuoting the README of ChefSpec on this subject: (https://github.com/sethvargo/chefspec#data-bag--data-bag-item)
If you are using Encrypted Data Bag Items, you'll need to dive into the RSpec layer and stub that class method instead:
describe 'example::default' do before do allow(Chef::EncryptedDataBagItem).to receive(:load).with('users', 'svargo').and_return(...) end end
Seems it had to be done in the before block.
Another entry of how to: https://github.com/sethvargo/chefspec/issues/249
Hope this helpsLe 2015-03-16 13:52, ANGELA EBIRIM a écrit :
Hello everyone,Does anyone here use ChefSpec regularly? If so, please help!I've got a situation where I have encrypted databags which I decrypt to find the passwords for users (in my local_users recipe). I have generated an encrypted_data_bag_secret that I use with my Chef Solo.This is my spec file:#local_users_spec.rbrequire 'spec_helper'describe 'core::local_users' dolet(:chef_run) { ChefSpec::SoloRunner.new.converge(described_recipe)}context 'windows' dolet(:chef_run) dorunner = ChefSpec::SoloRunner.new('platform' => 'windows','version' => '2012')runner.node.set['core']['install_flavor'] = 'windows'runner.converge('core::local_users')endit 'stubbed databag does not raise error' doplain_pass = "London2014"allow(Chef::EncryptedDataBagItem).to receive(:load).with("aws-admin-passwords", "svc_goagent")["password"].and_return(plain_pass)expect(chef_run).to_not raise_errorendendendWhen I run this, I get the following:-C:\git\cookbook-core>rspec spec/local_users_spec.rbffi-yajl/json_gem is deprecated, these monkeypatches will be dropped shortly[2015-03-16T12:24:31+00:00] WARN: Failed to read the private key C:\chef\client.pem: #<Errno::ENOENT: No such file or directory - C:\chef\client.pem>[2015-03-16T12:24:31+00:00] WARN: Can't decrypt password for svc_goagent"Plain password for svc_goagent is "C:/git/cookbook-core/recipes/local_users.rb:32:in `block in <top (required)>': undefined local variable or method `node' for main:Object (NameError)from C:/git/cookbook-core/recipes/local_users.rb:22:in `each'from C:/git/cookbook-core/recipes/local_users.rb:22:in `<top (required)>'from C:/git/cookbook-core/spec/spec_helper.rb:8:in `require_relative'from C:/git/cookbook-core/spec/spec_helper.rb:8:in `<top (required)>'from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'from C:/git/cookbook-core/spec/local_users_spec.rb:1:in `<top (required)>'...I expect the test to pass and not generate an error. However I receive an error which indicates the test is not stubbing my encrypted data bag (especially the No such file or directory - C:\chef\client.pem> errror). Can anyone help me with this?Thanks
Archive powered by MHonArc 2.6.16.