Skip to content

Commit

Permalink
add code and cucumber support for running on multiple chef versions
Browse files Browse the repository at this point in the history
  • Loading branch information
korishev committed May 14, 2014
1 parent a6e174e commit 9f20947
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 24 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ source 'https://rubygems.org'

gemspec :development_group => :test

gem "chef", "= 11.4.0"

group :development do
gem "growl"
gem "guard"
Expand Down
32 changes: 16 additions & 16 deletions features/encrypt.feature
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,27 @@ Scenario: Usage

Scenario: Encrypting a String
Given a knife configuration with en encrypted data bag secret "my secret"
When I successfully run `knife encrypt -VV -c .chef/knife.rb '"foo"' '"3EnQL7IItwtknz5p7TVlTQ=="'`
Then the stdout should contain exactly:
"""
9ZgVemCtbgVxJO8gmP7y8oXDUaYAYxQzkI5acgHm4Kw=
"""
When I successfully run `knife encrypt -c .chef/knife.rb '"foo"' '"3EnQL7IItwtknz5p7TVlTQ=="'`
Then the stdout should be one of:
|chef_version|encrypted_string |
|0.10.10 |e4ibEHAinGltDjYNQPV4rw==\n |
|10.32.2 |e4ibEHAinGltDjYNQPV4rw==\n |
|11.4.0 |9ZgVemCtbgVxJO8gmP7y8oXDUaYAYxQzkI5acgHm4Kw=\n|

Scenario: Encrypting an Array
Given a knife configuration with en encrypted data bag secret "my secret"
When I successfully run `knife encrypt -c .chef/knife.rb '["foo", "bar"]' '"3EnQL7IItwtknz5p7TVlTQ=="'`
Then the stdout should contain exactly:
"""
9ZgVemCtbgVxJO8gmP7y8uGwkFOaRPd0s74enPmPLhg=
"""
Then the stdout should be one of:
|chef_version|encrypted_string |
|0.10.10 |7wrizj9MAjmSVWWq69DUql0hNHFv7Hp/1tnQ/NJuD08=\n|
|10.32.2 |7wrizj9MAjmSVWWq69DUql0hNHFv7Hp/1tnQ/NJuD08=\n|
|11.4.0 |9ZgVemCtbgVxJO8gmP7y8uGwkFOaRPd0s74enPmPLhg=\n|

Scenario: Encrypting a Hash
Given a knife configuration with en encrypted data bag secret "my secret"
When I successfully run `knife encrypt -c .chef/knife.rb '{"foo"=>{"bar"=>"baz"}}' '"3EnQL7IItwtknz5p7TVlTQ=="'`
Then the stdout should contain exactly:
"""
9ZgVemCtbgVxJO8gmP7y8qJWD5s+Mz808peVZbMfalYVzNylYukjQTf+h791\nOdSv
"""
Then the stdout should be one of:
|chef_version|encrypted_string |
|0.10.10 |nsXFeAANrmnBNu+QPfOHZFB5szSRA+Ezu94fmrJnNhk=\n|
|10.32.2 |nsXFeAANrmnBNu+QPfOHZFB5szSRA+Ezu94fmrJnNhk=\n|
|11.4.0 |9ZgVemCtbgVxJO8gmP7y8qJWD5s+Mz808peVZbMfalYVzNylYukjQTf+h791\nOdSv\n|
5 changes: 5 additions & 0 deletions features/step_definitions/knife_encryption_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Then(/^the stdout should be one of:$/) do |table|
# table is a Cucumber::Ast::Table
data = table.rows_hash
step "the stdout should contain exactly:", data[Chef::VERSION]
end
2 changes: 1 addition & 1 deletion features/support/env.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
require "bundler/setup"
require "aruba/cucumber"
require "debugger"
require "chef/version"
1 change: 0 additions & 1 deletion knife-crypt.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@ Gem::Specification.new do |gem|
gem.add_development_dependency "aruba", "~> 0.4.11"
gem.add_development_dependency "bundler", "~> 1.0"
gem.add_development_dependency "cucumber", "~> 1.2.0"
gem.add_development_dependency "debugger", "= 1.6.6"
gem.add_development_dependency "rake", "~> 0.9.0"
end
2 changes: 1 addition & 1 deletion lib/chef/knife/decrypt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def run

encrypted_value = @name_args[0]
secret = Chef::EncryptedDataBagItem.load_secret
decrypted_value = if Chef::EncryptedDataBagItem.method_defined?(:decrypt_value)
decrypted_value = if Chef::EncryptedDataBagItem.methods.include?(:decrypt_value)
Chef::EncryptedDataBagItem.decrypt_value encrypted_value, secret
else
Chef::EncryptedDataBagItem::Decryptor.for(encrypted_value, secret).for_decrypted_item
Expand Down
10 changes: 5 additions & 5 deletions lib/chef/knife/encrypt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ def run
decrypted_value = eval @name_args[0]
initialization_vector = @name_args[1]
secret = Chef::EncryptedDataBagItem.load_secret
encrypted_value = if Chef::EncryptedDataBagItem.method_defined?(:encrypt_value)
Chef::EncryptedDataBagItem.encrypt_value(decrypted_value, secret)
else
Chef::EncryptedDataBagItem::Encryptor.new(decrypted_value, secret, initialization_vector).for_encrypted_item["encrypted_data"]
end
encrypted_value = if Chef::EncryptedDataBagItem.methods.include? :encrypt_value
Chef::EncryptedDataBagItem.encrypt_value(decrypted_value, secret)
else
Chef::EncryptedDataBagItem::Encryptor.new(decrypted_value, secret, initialization_vector).for_encrypted_item["encrypted_data"]
end
puts encrypted_value
end
end
Expand Down

0 comments on commit 9f20947

Please sign in to comment.