summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoradamedx <adamedx@gmail.com>2016-02-15 07:48:47 -0800
committernimisha <nimisha.sharad@msystechnologies.com>2017-02-02 18:00:30 +0530
commitaa155445b92e87baf1895ce092da3ae4c93117e6 (patch)
treecbb3f01bafeb456866e63674231f64386dc86f41
parentf0809fbb1c08ad14faed9c51f861a94373a39d27 (diff)
downloadchef-aa155445b92e87baf1895ce092da3ae4c93117e6.tar.gz
Rubocop violations in execute resource alternate user implementation
-rw-r--r--lib/chef/mixin/user_identity.rb2
-rw-r--r--lib/chef/provider/execute.rb10
-rw-r--r--lib/chef/provider/script.rb14
-rw-r--r--spec/functional/resource/batch_spec.rb2
-rw-r--r--spec/support/shared/functional/windows_script.rb2
-rw-r--r--spec/support/shared/unit/execute_resource.rb14
-rw-r--r--spec/unit/provider/execute_spec.rb22
-rw-r--r--spec/unit/provider/script_spec.rb30
8 files changed, 49 insertions, 47 deletions
diff --git a/lib/chef/mixin/user_identity.rb b/lib/chef/mixin/user_identity.rb
index 6218b44ac2..c037adb441 100644
--- a/lib/chef/mixin/user_identity.rb
+++ b/lib/chef/mixin/user_identity.rb
@@ -57,7 +57,7 @@ class Chef
domain_and_user = user.split('\\')
if domain_and_user.length == 1
- domain_and_user = user.split('@')
+ domain_and_user = user.split("@")
end
if domain_and_user.length == 2
diff --git a/lib/chef/provider/execute.rb b/lib/chef/provider/execute.rb
index c8e3d2732b..1b032a939e 100644
--- a/lib/chef/provider/execute.rb
+++ b/lib/chef/provider/execute.rb
@@ -16,10 +16,10 @@
# limitations under the License.
#
-require 'chef/log'
-require 'chef/provider'
-require 'forwardable'
-require 'chef/mixin/user_identity'
+require "chef/log"
+require "chef/provider"
+require "forwardable"
+require "chef/mixin/user_identity"
class Chef
class Provider
@@ -46,7 +46,7 @@ class Chef
end
def define_resource_requirements
- # @todo: this should change to raise in some appropriate major version bump.
+ # @todo: this should change to raise in some appropriate major version bump.
if creates && creates_relative? && !cwd
Chef::Log.warn "Providing a relative path for the creates attribute without the cwd is deprecated and will be changed to fail in the future (CHEF-3819)"
end
diff --git a/lib/chef/provider/script.rb b/lib/chef/provider/script.rb
index 9aee6fe442..3f89672f21 100644
--- a/lib/chef/provider/script.rb
+++ b/lib/chef/provider/script.rb
@@ -16,10 +16,10 @@
# limitations under the License.
#
-require 'tempfile'
-require 'chef/provider/execute'
-require 'chef/win32/security' if Chef::Platform.windows?
-require 'forwardable'
+require "tempfile"
+require "chef/provider/execute"
+require "chef/win32/security" if Chef::Platform.windows?
+require "forwardable"
class Chef
class Provider
@@ -83,7 +83,7 @@ class Chef
# Duplicate the script file's existing DACL
# so we can add an ACE later
securable_object = Chef::ReservedNames::Win32::Security::SecurableObject.new(script_file.path)
- aces = securable_object.security_descriptor.dacl.reduce([]) { | result, current | result.push(current) }
+ aces = securable_object.security_descriptor.dacl.reduce([]) { |result, current| result.push(current) }
username = new_resource.user
@@ -99,7 +99,9 @@ class Chef
acl = Chef::ReservedNames::Win32::Security::ACL.create(aces)
# This actually applies the modified DACL to the file
- securable_object.dacl = acl
+ # Use parentheses to bypass RuboCop / ChefStyle warning
+ # about useless setter
+ (securable_object.dacl = acl)
end
def script_file
diff --git a/spec/functional/resource/batch_spec.rb b/spec/functional/resource/batch_spec.rb
index 2f15984964..2b176ed06c 100644
--- a/spec/functional/resource/batch_spec.rb
+++ b/spec/functional/resource/batch_spec.rb
@@ -23,7 +23,7 @@ describe Chef::Resource::WindowsScript::Batch, :windows_only do
let(:output_command) { " > " }
- let(:architecture_command) { '@echo %PROCESSOR_ARCHITECTURE%' }
+ let(:architecture_command) { "@echo %PROCESSOR_ARCHITECTURE%" }
let(:resource) do
Chef::Resource::WindowsScript::Batch.new("Batch resource functional test", @run_context)
diff --git a/spec/support/shared/functional/windows_script.rb b/spec/support/shared/functional/windows_script.rb
index 361e5a71e0..4bd6bdf230 100644
--- a/spec/support/shared/functional/windows_script.rb
+++ b/spec/support/shared/functional/windows_script.rb
@@ -142,7 +142,7 @@ shared_context Chef::Resource::WindowsScript do
before do
expect(script_provider).to receive(:unlink_script_file)
- resource.code('echo hi')
+ resource.code("echo hi")
script_provider.action_run
end
diff --git a/spec/support/shared/unit/execute_resource.rb b/spec/support/shared/unit/execute_resource.rb
index 275b327b86..ab6ed2b86b 100644
--- a/spec/support/shared/unit/execute_resource.rb
+++ b/spec/support/shared/unit/execute_resource.rb
@@ -107,13 +107,13 @@ shared_examples_for "an execute resource" do
end
it "should accept a string for the domain" do
- @resource.domain 'mothership'
- expect(@resource.domain).to eql('mothership')
+ @resource.domain "mothership"
+ expect(@resource.domain).to eql("mothership")
end
it "should accept a string for the password" do
- @resource.password 'we.funk!'
- expect(@resource.password).to eql('we.funk!')
+ @resource.password "we.funk!"
+ expect(@resource.password).to eql("we.funk!")
end
it "should accept a string for creates" do
@@ -139,13 +139,13 @@ shared_examples_for "an execute resource" do
it "should be true if the password is non-nil" do
expect(@resource.sensitive).to eq(false)
- @resource.password('we.funk!')
+ @resource.password("we.funk!")
expect(@resource.sensitive).to eq(true)
end
it "should be true if the password is non-nil but the value is explicitly set to false" do
expect(@resource.sensitive).to eq(false)
- @resource.password('we.funk!')
+ @resource.password("we.funk!")
expect(@resource.sensitive).to eq(true)
@resource.sensitive false
expect(@resource.sensitive).to eq(true)
@@ -153,7 +153,7 @@ shared_examples_for "an execute resource" do
end
- describe "when it has cwd, environment, group, path, return value, and a user" do
+ describe "when it has cwd, environment, group, path, return value, and a user" do
before do
@resource.command("grep")
@resource.cwd("/tmp/")
diff --git a/spec/unit/provider/execute_spec.rb b/spec/unit/provider/execute_spec.rb
index e83e347fb6..a579b389df 100644
--- a/spec/unit/provider/execute_spec.rb
+++ b/spec/unit/provider/execute_spec.rb
@@ -251,12 +251,12 @@ describe Chef::Provider::Execute do
context "when the username is specified" do
before do
- new_resource.user('starchild')
+ new_resource.user("starchild")
end
context "when the domain is specified" do
before do
- new_resource.domain('mydomain')
+ new_resource.domain("mydomain")
end
it "should raise an error if the password is not specified" do
@@ -265,7 +265,7 @@ describe Chef::Provider::Execute do
end
it "should not raise an error if the password is specified" do
- expect(new_resource).to receive(:password).at_least(1).times.and_return('we.funk!')
+ expect(new_resource).to receive(:password).at_least(1).times.and_return("we.funk!")
expect { provider.run_action(:run) }.not_to raise_error
end
end
@@ -281,7 +281,7 @@ describe Chef::Provider::Execute do
end
it "should not raise an error if the password is specified" do
- expect(new_resource).to receive(:password).at_least(1).times.and_return('we.funk!')
+ expect(new_resource).to receive(:password).at_least(1).times.and_return("we.funk!")
expect { provider.run_action(:run) }.not_to raise_error
end
@@ -294,18 +294,18 @@ describe Chef::Provider::Execute do
end
it "should raise an error if the password is specified" do
- expect(new_resource).to receive(:password).at_least(1).times.and_return('we.funk!')
+ expect(new_resource).to receive(:password).at_least(1).times.and_return("we.funk!")
expect { provider.run_action(:run) }.to raise_error(ArgumentError)
end
it "should raise an error if the domain is specified" do
- expect(new_resource).to receive(:domain).at_least(1).times.and_return('mothership')
+ expect(new_resource).to receive(:domain).at_least(1).times.and_return("mothership")
expect { provider.run_action(:run) }.to raise_error(ArgumentError)
end
it "should raise an error if the domain and password are specified" do
- expect(new_resource).to receive(:password).at_least(1).times.and_return('we.funk!')
- expect(new_resource).to receive(:domain).at_least(1).times.and_return('mothership')
+ expect(new_resource).to receive(:password).at_least(1).times.and_return("we.funk!")
+ expect(new_resource).to receive(:domain).at_least(1).times.and_return("mothership")
expect { provider.run_action(:run) }.to raise_error(ArgumentError)
end
end
@@ -317,16 +317,16 @@ describe Chef::Provider::Execute do
end
it "should not raise an error if the user is specified" do
- new_resource.user('starchild')
+ new_resource.user("starchild")
end
it "should raise an error if the password is specified" do
- expect(new_resource).to receive(:password).and_return('we.funk!')
+ expect(new_resource).to receive(:password).and_return("we.funk!")
expect { provider.run_action(:run) }.to raise_error(Chef::Exceptions::UnsupportedPlatform)
end
it "should raise an error if the domain is specified" do
- expect(new_resource).to receive(:domain).and_return('we.funk!')
+ expect(new_resource).to receive(:domain).and_return("we.funk!")
expect { provider.run_action(:run) }.to raise_error(Chef::Exceptions::UnsupportedPlatform)
end
end
diff --git a/spec/unit/provider/script_spec.rb b/spec/unit/provider/script_spec.rb
index e7f09cf275..2f024c4c29 100644
--- a/spec/unit/provider/script_spec.rb
+++ b/spec/unit/provider/script_spec.rb
@@ -57,31 +57,31 @@ describe Chef::Provider::Script, "action_run" do
end
context "when configuring the script file's security" do
- context 'when not running on Windows' do
+ context "when not running on Windows" do
before do
allow(::Chef::Platform).to receive(:windows?).and_return(false)
end
context "#set_owner_and_group" do
it "sets the owner and group for the script file" do
- new_resource.user 'toor'
- new_resource.group 'wheel'
- expect(FileUtils).to receive(:chown).with('toor', 'wheel', tempfile.path)
+ new_resource.user "toor"
+ new_resource.group "wheel"
+ expect(FileUtils).to receive(:chown).with("toor", "wheel", tempfile.path)
provider.set_owner_and_group
end
end
end
- context 'when running on Windows' do
+ context "when running on Windows" do
before do
allow(::Chef::Platform).to receive(:windows?).and_return(true)
expect(new_resource.user).to eq(nil)
- stub_const('Chef::ReservedNames::Win32::API::Security::GENERIC_READ', 1)
- stub_const('Chef::ReservedNames::Win32::API::Security::GENERIC_EXECUTE', 4)
- stub_const('Chef::ReservedNames::Win32::Security', Class.new)
- stub_const('Chef::ReservedNames::Win32::Security::SecurableObject', Class.new)
- stub_const('Chef::ReservedNames::Win32::Security::SID', Class.new)
- stub_const('Chef::ReservedNames::Win32::Security::ACE', Class.new)
- stub_const('Chef::ReservedNames::Win32::Security::ACL', Class.new)
+ stub_const("Chef::ReservedNames::Win32::API::Security::GENERIC_READ", 1)
+ stub_const("Chef::ReservedNames::Win32::API::Security::GENERIC_EXECUTE", 4)
+ stub_const("Chef::ReservedNames::Win32::Security", Class.new)
+ stub_const("Chef::ReservedNames::Win32::Security::SecurableObject", Class.new)
+ stub_const("Chef::ReservedNames::Win32::Security::SID", Class.new)
+ stub_const("Chef::ReservedNames::Win32::Security::ACE", Class.new)
+ stub_const("Chef::ReservedNames::Win32::Security::ACL", Class.new)
end
context "when an alternate user is not specified" do
@@ -93,10 +93,10 @@ describe Chef::Provider::Script, "action_run" do
end
context "when an alternate user is specified" do
- let(:security_descriptor) { instance_double('Chef::ReservedNames::Win32::Security::SecurityDescriptor', :dacl => []) }
- let(:securable_object) { instance_double('Chef::ReservedNames::Win32::Security::SecurableObject', :security_descriptor => security_descriptor, :dacl= => nil) }
+ let(:security_descriptor) { instance_double("Chef::ReservedNames::Win32::Security::SecurityDescriptor", :dacl => []) }
+ let(:securable_object) { instance_double("Chef::ReservedNames::Win32::Security::SecurableObject", :security_descriptor => security_descriptor, :dacl= => nil) }
it "sets the script file's security descriptor" do
- new_resource.user('toor')
+ new_resource.user("toor")
expect(Chef::ReservedNames::Win32::Security::SecurableObject).to receive(:new).and_return(securable_object)
expect(Chef::ReservedNames::Win32::Security::SID).to receive(:from_account).and_return(nil)
expect(Chef::ReservedNames::Win32::Security::ACE).to receive(:access_allowed).and_return(nil)