In my cookbook I'm using code like this
node.set['ssl_keystore_pass'] = secure_password
I would like to stub secure_password method in my spec files to make it work with my tests.
it 'should include required java/ark recipes' do
with these settings in place it still doesn't work and I'm getting same error
1) rsdtomcat::default should include required java/ark recipes
undefined method `secure_password' for Opscode::OpenSSL::Password:Module
# /var/folders/yq/_h9bmb6x1qxb7p4_w5xhkgx80000gn/T/d20150107-31232-9gzxp7/cookbooks/rsdtomcat/recipes/default.rb:30:in `block in from_file'
# /var/folders/yq/_h9bmb6x1qxb7p4_w5xhkgx80000gn/T/d20150107-31232-9gzxp7/cookbooks/rsdtomcat/recipes/default.rb:24:in `from_file'
# ./spec/unit/recipes/default.rb:8:in `block (2 levels) in <top (required)>'
# ./spec/unit/recipes/default.rb:19:in `block (2 levels) in <top (required)>'
@haad does this recipe actually converge? It looks like you have a bug in that module.
For Chef, I don't recommend every mixing a module into a recipe as I think it's horrible practice and makes things like this more difficult to test. Why not make Opscode::OpenSSL::Password a self-extending module or class?
Then invoke it like Opscode::OpenSSL::Password.secure_password and stub it like allow(Opscode::OpenSSL::Password).to receive(:secure_password).
This would require that I would fork community openssl cookbook which is not what I want if it's not necessary. Is there any other way to get this working ?
@haad blah omg that code is so horrible inefficient! (sorry I digress). Do this instead:
node.set['ssl_keystore_pass'] = SecureRandom.hex(20) # or SecureRandom.base64(20)
Then you can stub SecureRandom pretty easily:
SecureRandom is also a far-better implementation (and more secure) than what is current in the OpenSSL cookbook.
It bugged me so much that I even submitted a PR to make it better: chef-cookbooks/openssl#18