Skip to content

Commit

Permalink
GemSpec: Update RuboCop to version 0.29.1 (new offenses fixed)
Browse files Browse the repository at this point in the history
  • Loading branch information
zuazo committed Apr 2, 2015
1 parent 369d86f commit abaf568
Show file tree
Hide file tree
Showing 35 changed files with 188 additions and 297 deletions.
2 changes: 1 addition & 1 deletion chef-encrypted-attributes.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Gem::Specification.new do |s|
s.add_development_dependency 'coveralls', '~> 0.7'
s.add_development_dependency 'simplecov', '~> 0.9'
s.add_development_dependency 'should_not', '~> 1.1'
s.add_development_dependency 'rubocop', '= 0.27.1' if RUBY_VERSION >= '1.9.3'
s.add_development_dependency 'rubocop', '= 0.29.1' if RUBY_VERSION >= '1.9.3'

s.cert_chain = [::File.join('certs', 'team_onddo.crt')]
end
9 changes: 3 additions & 6 deletions lib/chef/encrypted_attribute/cache_lru.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,9 @@ def max_size(arg = nil)
# @param key [String, Symbol] cache key to read.
# @return [Mixed] cache key value.
def [](key)
if key?(key)
val = super(key)
self[key] = val
else
nil
end
return nil unless key?(key)
val = super(key)
self[key] = val
end

# Sets a cache key.
Expand Down
2 changes: 0 additions & 2 deletions lib/chef/encrypted_attribute/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,6 @@ def config_valid_key?(k)
rescue OpenSSL::PKey::RSAError, TypeError
nil
end
else
nil
end
return false if rsa_k.nil?
rsa_k.public?
Expand Down
7 changes: 3 additions & 4 deletions lib/chef/encrypted_attribute/remote_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,10 @@ def delete_attribute(attr_ary)
# @param res [Array<Hash>] {SearchHelper#search} result.
# @return [Mixed] final search result value.
def parse_search_result(res)
if res.is_a?(Array) && res[0].is_a?(Hash) && res[0].key?('value')
res[0]['value']
else
nil
unless res.is_a?(Array) && res[0].is_a?(Hash) && res[0].key?('value')
return nil
end
res[0]['value']
end

# Generates the cache key.
Expand Down
1 change: 0 additions & 1 deletion lib/chef/knife/core/encrypted_attribute_editor_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ module EncryptedAttributeEditorOptions
# @param includer [Class] includer class.
def self.included(includer)
includer.class_eval do

# Helper method to set the encrypted attributes configuration.
def self.encrypted_attributes_option_set(key, value)
Chef::Config[:knife][:encrypted_attributes][key] = value
Expand Down
5 changes: 2 additions & 3 deletions lib/chef/knife/encrypted_attribute_update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ def run
parse_args

# update encrypted attribute
enc_attr = Chef::EncryptedAttribute.new(
Chef::Config[:knife][:encrypted_attributes]
)
knife_config = Chef::Config[:knife][:encrypted_attributes]
enc_attr = Chef::EncryptedAttribute.new(knife_config)
if enc_attr.update_on_node(@node_name, @attr_ary)
ui.info('Encrypted attribute updated.')
else
Expand Down
1 change: 0 additions & 1 deletion spec/benchmark/benchmarks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,5 @@
Chef::EncryptedDataBagItem.load('encrypted', 'data_bag_id')
enc_data_bag_item['data']
end

end # when_the_chef_server is ready to rock!
end
68 changes: 28 additions & 40 deletions spec/integration/encrypted_attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
after { Chef::Config[:encrypted_attributes] = Mash.new }

when_the_chef_server 'is ready to rock!' do

versions = %w(default 0 1)
versions << '2' if ruby_gte_20? && openssl_gte_101?

Expand Down Expand Up @@ -83,7 +82,6 @@
"Chef::EncryptedAttribute::EncryptedMash::Version#{version}"
)
end

end # context #create

context 'loading the encrypted attribute' do
Expand All @@ -103,8 +101,9 @@
end

it 'decrypts the attribute to the correct value' do
expect(Chef::EncryptedAttribute.load(@enc_attr))
.to eql(@clear_attr)
expect(
Chef::EncryptedAttribute.load(@enc_attr)
).to eql(@clear_attr)
end
end # context using #load

Expand Down Expand Up @@ -144,7 +143,6 @@
)
end
end # context using #load_from_node

end # context loading the encrypted attribute

context '#create & #load testing some basic types' do
Expand All @@ -164,7 +162,6 @@
]

objects_to_test.each do |o|

it "#load encrypts and decrypts correctly: #{o.inspect} "\
"(#{o.class})" do
enc_o = Chef::EncryptedAttribute.create(o)
Expand All @@ -185,7 +182,6 @@
).to eql(o)
node.destroy
end

end # objects_to_test.each
end # context #create & #load testing some basic types

Expand Down Expand Up @@ -296,16 +292,14 @@
node2.destroy
@node1.save # avoid error 404 on after { node1.destroy }
end

end # context #update

context '#exist?' do

clear_attributes = [
nil,
2,
'Spoon-bender',
Hash.new,
{},
Mash.new,
Mash.new('version' => '1'),
begin
Expand All @@ -317,12 +311,10 @@
]

clear_attributes.each do |a|

it "returns false for #{a.inspect}" do
expect(Chef::Log).to_not receive(:warn)
expect(Chef::EncryptedAttribute.exist?(a)).to eql(false)
end

end

it 'returns true for an encrypted attribute' do
Expand All @@ -343,16 +335,14 @@
Chef::EncryptedAttribute.exist?(node['encrypted']['attribute'])
).to eql(true)
end

end # context #exist?

context '#exists?' do

clear_attributes = [
nil,
2,
'Spoon-bender',
Hash.new,
{},
Mash.new,
Mash.new('version' => '1'),
begin
Expand All @@ -364,13 +354,11 @@
]

clear_attributes.each do |a|

it "returns false for #{a.inspect}" do
expect(Chef::Log).to receive(:warn).once
.with(/is deprecated in favor of/)
expect(Chef::EncryptedAttribute.exists?(a)).to eql(false)
end

end

it 'returns true for an encrypted attribute' do
Expand All @@ -389,11 +377,10 @@

expect(Chef::Log).to receive(:warn).once
.with(/is deprecated in favor of/)
expect(Chef::EncryptedAttribute.exists?(
node['encrypted']['attribute']
)).to eql(true)
expect(
Chef::EncryptedAttribute.exists?(node['encrypted']['attribute'])
).to eql(true)
end

end # context #exists?

context 'working with multiple clients' do
Expand All @@ -419,18 +406,18 @@
end

it 'original client is able to read the attribute' do
expect(Chef::EncryptedAttribute.load(
@node['encrypted']['attribute']
)).to eql(@attr_clear)
expect(
Chef::EncryptedAttribute.load(@node['encrypted']['attribute'])
).to eql(@attr_clear)
end

it 'other clients does not be able to read it by default' do
allow_any_instance_of(Chef::EncryptedAttribute::LocalNode)
.to receive(:key).and_return(@private_key)
expect do
expect(Chef::EncryptedAttribute.load(
@node['encrypted']['attribute']
)).to eql(@attr_clear)
expect(
Chef::EncryptedAttribute.load(@node['encrypted']['attribute'])
).to eql(@attr_clear)
end.to raise_error(
Chef::EncryptedAttribute::DecryptionFailure,
/Attribute data cannot be decrypted by the provided key\./
Expand All @@ -445,23 +432,25 @@

allow_any_instance_of(Chef::EncryptedAttribute::LocalNode)
.to receive(:key).and_return(@private_key)
expect(Chef::EncryptedAttribute.load(
@node['encrypted']['attribute']
)).to eql(@attr_clear)
expect(
Chef::EncryptedAttribute.load(@node['encrypted']['attribute'])
).to eql(@attr_clear)
end

it 'other clients is able to read it if added in global config' do
Chef::Config[:encrypted_attributes][:keys] =
[@node_client.public_key]
expect(Chef::EncryptedAttribute.update(
@node.set['encrypted']['attribute']
)).to eql(true)
expect(
Chef::EncryptedAttribute.update(
@node.set['encrypted']['attribute']
)
).to eql(true)

allow_any_instance_of(Chef::EncryptedAttribute::LocalNode)
.to receive(:key).and_return(@private_key)
expect(Chef::EncryptedAttribute.load(
@node['encrypted']['attribute']
)).to eql(@attr_clear)
expect(
Chef::EncryptedAttribute.load(@node['encrypted']['attribute'])
).to eql(@attr_clear)
end

it 'other clients does not be able to read if they are removed from '\
Expand Down Expand Up @@ -500,15 +489,14 @@
allow_any_instance_of(Chef::EncryptedAttribute::LocalNode)
.to receive(:key).and_return(@private_key)
expect do
expect(Chef::EncryptedAttribute.load(
@node['encrypted']['attribute']
)).to eql(@attr_clear)
expect(
Chef::EncryptedAttribute.load(@node['encrypted']['attribute'])
).to eql(@attr_clear)
end.to raise_error(
Chef::EncryptedAttribute::DecryptionFailure,
/Attribute data cannot be decrypted by the provided key\./
)
end

end # context working with multiple clients
end # context EncryptedAttribute version #{version}
end # each do |version|
Expand Down
3 changes: 0 additions & 3 deletions spec/integration/encrypted_attribute/encrypted_mash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,13 @@
before(:all) { clear_all_caches }

when_the_chef_server 'is ready to rock!' do

context '#update' do

it 'calls RemoteClients#search_public_keys only once' do
body = Chef::EncryptedAttribute.create(0)
expect(Chef::EncryptedAttribute::RemoteClients)
.to receive(:search_public_keys).once.and_return([])
Chef::EncryptedAttribute.update(body)
end

end # context update
end # when_the_chef_server is ready to rock!
end
4 changes: 0 additions & 4 deletions spec/integration/encrypted_attribute/remote_clients.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
end

context '#get_public_key' do

it 'returns client public key' do
expect(remote_clients_class.get_public_key('admin1'))
.to eq(@admin1.public_key)
Expand All @@ -56,11 +55,9 @@
expect { remote_clients_class.get_public_key('unknown') }
.to raise_error(Chef::EncryptedAttribute::ClientNotFound)
end

end

context '#search_public_keys' do

it 'gets all client public_keys by default' do
expect(remote_clients_class.search_public_keys.sort)
.to eql(@clients.map(&:public_key).sort)
Expand All @@ -77,7 +74,6 @@
query = 'this_will_return_no_results:true'
expect(remote_clients_class.search_public_keys(query).sort).to eql([])
end

end # context #search_public_keys
end # when_the_chef_server is ready to rock!
end
8 changes: 0 additions & 8 deletions spec/integration/encrypted_attribute/remote_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
end

context '#name' do

it 'returns the node name' do
expect(remote_node.name).to eql(node_name)
end
Expand All @@ -50,11 +49,9 @@
remote_node.name(new_name)
expect(remote_node.name).to eql(new_name)
end

end # context #name

context '#load_attribute' do

it 'reads an existing node attribute' do
expect(remote_node.load_attribute(%w(attr1))).to eql(attr1)
expect(remote_node.load_attribute(%w(sub-attr attr2)))
Expand All @@ -69,11 +66,9 @@
expect { remote_node.load_attribute('incorrect-attr-ary') }
.to raise_error(ArgumentError)
end

end # context #load_attribute

context '#save_attribute' do

it 'saves the attribute' do
remote_node.save_attribute(%w(saved-attr subattr2), 'A precious value')
Chef::EncryptedAttribute::RemoteUsers.cache.clear
Expand All @@ -95,11 +90,9 @@
remote_node.save_attribute('incorrect-attr-ary', 'some value')
end.to raise_error(ArgumentError)
end

end # context #save_attribute

context '#delete_attribute' do

it 'deletes a node attribute' do
node = Chef::Node.load(node_name)
expect(node['sub-attr']['attr2']).not_to eql(nil)
Expand All @@ -120,7 +113,6 @@
expect { remote_node.delete_attribute('incorrect-attr-ary') }
.to raise_error(ArgumentError)
end

end # context #delete_attribute
end # when_the_chef_server is ready to rock!
end

0 comments on commit abaf568

Please sign in to comment.