diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/unit/provider/user/dscl_spec.rb | 111 | ||||
-rw-r--r-- | spec/unit/provider/user/linux_spec.rb | 10 | ||||
-rw-r--r-- | spec/unit/provider/user/pw_spec.rb | 48 | ||||
-rw-r--r-- | spec/unit/provider/user/windows_spec.rb | 8 | ||||
-rw-r--r-- | spec/unit/provider/user_spec.rb | 40 |
5 files changed, 108 insertions, 109 deletions
diff --git a/spec/unit/provider/user/dscl_spec.rb b/spec/unit/provider/user/dscl_spec.rb index 7b8be02f3a..f59709e717 100644 --- a/spec/unit/provider/user/dscl_spec.rb +++ b/spec/unit/provider/user/dscl_spec.rb @@ -116,38 +116,38 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" describe "when shelling out to dscl" do it "should run dscl with the supplied cmd /Path args" do shell_return = shellcmdresult.new("stdout", "err", 0) - expect(provider).to receive(:shell_out).with("dscl . -cmd /Path args").and_return(shell_return) - expect(provider.run_dscl("cmd /Path args")).to eq("stdout") + expect(provider).to receive(:shell_out).with("dscl", ".", "-cmd", "/Path", "args").and_return(shell_return) + expect(provider.run_dscl("cmd", "/Path", "args")).to eq("stdout") end it "returns an empty string from delete commands" do shell_return = shellcmdresult.new("out", "err", 23) - expect(provider).to receive(:shell_out).with("dscl . -delete /Path args").and_return(shell_return) - expect(provider.run_dscl("delete /Path args")).to eq("") + expect(provider).to receive(:shell_out).with("dscl", ".", "-delete", "/Path", "args").and_return(shell_return) + expect(provider.run_dscl("delete", "/Path", "args")).to eq("") end it "should raise an exception for any other command" do shell_return = shellcmdresult.new("out", "err", 23) - expect(provider).to receive(:shell_out).with("dscl . -cmd /Path arguments").and_return(shell_return) - expect { provider.run_dscl("cmd /Path arguments") }.to raise_error(Chef::Exceptions::DsclCommandFailed) + expect(provider).to receive(:shell_out).with("dscl", ".", "-cmd", "/Path", "arguments").and_return(shell_return) + expect { provider.run_dscl("cmd", "/Path", "arguments") }.to raise_error(Chef::Exceptions::DsclCommandFailed) end it "raises an exception when dscl reports 'no such key'" do shell_return = shellcmdresult.new("No such key: ", "err", 23) - expect(provider).to receive(:shell_out).with("dscl . -cmd /Path args").and_return(shell_return) - expect { provider.run_dscl("cmd /Path args") }.to raise_error(Chef::Exceptions::DsclCommandFailed) + expect(provider).to receive(:shell_out).with("dscl", ".", "-cmd", "/Path", "args").and_return(shell_return) + expect { provider.run_dscl("cmd", "/Path", "args") }.to raise_error(Chef::Exceptions::DsclCommandFailed) end it "raises an exception when dscl reports 'eDSRecordNotFound'" do shell_return = shellcmdresult.new("<dscl_cmd> DS Error: -14136 (eDSRecordNotFound)", "err", -14136) - expect(provider).to receive(:shell_out).with("dscl . -cmd /Path args").and_return(shell_return) - expect { provider.run_dscl("cmd /Path args") }.to raise_error(Chef::Exceptions::DsclCommandFailed) + expect(provider).to receive(:shell_out).with("dscl", ".", "-cmd", "/Path", "args").and_return(shell_return) + expect { provider.run_dscl("cmd", "/Path", "args") }.to raise_error(Chef::Exceptions::DsclCommandFailed) end end describe "get_free_uid" do before do - expect(provider).to receive(:run_dscl).with("list /Users uid").and_return("\nwheel 200\nstaff 201\nbrahms 500\nchopin 501\n") + expect(provider).to receive(:run_dscl).with("list", "/Users", "uid").and_return("\nwheel 200\nstaff 201\nbrahms 500\nchopin 501\n") end describe "when resource is configured as system" do @@ -177,7 +177,7 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" describe "when called with a user id" do before do - expect(provider).to receive(:run_dscl).with("list /Users uid").and_return("\naj 500\n") + expect(provider).to receive(:run_dscl).with("list", "/Users", "uid").and_return("\naj 500\n") end it "should return true for a used uid number" do @@ -198,8 +198,8 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" end it "finds a valid, unused uid when none is specified" do - expect(provider).to receive(:run_dscl).with("list /Users uid").and_return("") - expect(provider).to receive(:run_dscl).with("create /Users/toor UniqueID 501") + expect(provider).to receive(:run_dscl).with("list", "/Users", "uid").and_return("") + expect(provider).to receive(:run_dscl).with("create", "/Users/toor", "UniqueID", 501) expect(provider).to receive(:get_free_uid).and_return(501) provider.dscl_set_uid expect(new_resource.uid).to eq(501) @@ -207,8 +207,8 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" it "sets the uid specified in the resource" do new_resource.uid(1000) - expect(provider).to receive(:run_dscl).with("create /Users/toor UniqueID 1000").and_return(true) - expect(provider).to receive(:run_dscl).with("list /Users uid").and_return("") + expect(provider).to receive(:run_dscl).with("create", "/Users/toor", "UniqueID", 1000).and_return(true) + expect(provider).to receive(:run_dscl).with("list", "/Users", "uid").and_return("") provider.dscl_set_uid end end @@ -219,9 +219,7 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" end before do - Chef::Config[:treat_deprecation_warnings_as_errors] = false - Chef::Config[:treat_deprecation_warnings_as_errors] = false - new_resource.supports({ :manage_home => true }) + new_resource.manage_home true new_resource.home("/Users/toor") provider.current_resource = current_resource @@ -229,7 +227,7 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" it "deletes the home directory when resource#home is nil" do new_resource.instance_variable_set(:@home, nil) - expect(provider).to receive(:run_dscl).with("delete /Users/toor NFSHomeDirectory").and_return(true) + expect(provider).to receive(:run_dscl).with("delete", "/Users/toor", "NFSHomeDirectory").and_return(true) provider.dscl_set_home end @@ -239,40 +237,40 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" end it "moves the users home to the new location if it exists and the target location is different" do - Chef::Config[:treat_deprecation_warnings_as_errors] = false - new_resource.supports(:manage_home => true) + new_resource.manage_home true current_home = CHEF_SPEC_DATA + "/old_home_dir" current_home_files = [current_home + "/my-dot-emacs", current_home + "/my-dot-vim"] current_resource.home(current_home) new_resource.gid(23) - allow(::File).to receive(:exists?).with("/old/home/toor").and_return(true) - allow(::File).to receive(:exists?).with("/Users/toor").and_return(true) + allow(::File).to receive(:exist?).with("/old/home/toor").and_return(true) + allow(::File).to receive(:exist?).with("/Users/toor").and_return(true) + allow(::File).to receive(:exist?).with(current_home).and_return(true) expect(FileUtils).to receive(:mkdir_p).with("/Users/toor").and_return(true) expect(FileUtils).to receive(:rmdir).with(current_home) expect(::Dir).to receive(:glob).with("#{CHEF_SPEC_DATA}/old_home_dir/*", ::File::FNM_DOTMATCH).and_return(current_home_files) - expect(FileUtils).to receive(:mv).with(current_home_files, "/Users/toor", :force => true) + expect(FileUtils).to receive(:mv).with(current_home_files, "/Users/toor", force: true) expect(FileUtils).to receive(:chown_R).with("toor", "23", "/Users/toor") - expect(provider).to receive(:run_dscl).with("create /Users/toor NFSHomeDirectory '/Users/toor'") + expect(provider).to receive(:run_dscl).with("create", "/Users/toor", "NFSHomeDirectory", "/Users/toor") provider.dscl_set_home end it "should raise an exception when the systems user template dir (skel) cannot be found" do - allow(::File).to receive(:exists?).and_return(false, false, false) + allow(::File).to receive(:exist?).and_return(false, false, false) expect { provider.dscl_set_home }.to raise_error(Chef::Exceptions::User) end it "should run ditto to copy any missing files from skel to the new home dir" do - expect(::File).to receive(:exists?).with("/System/Library/User\ Template/English.lproj").and_return(true) + expect(::File).to receive(:exist?).with("/System/Library/User\ Template/English.lproj").and_return(true) expect(FileUtils).to receive(:chown_R).with("toor", "", "/Users/toor") - expect(provider).to receive(:shell_out!).with("ditto '/System/Library/User Template/English.lproj' '/Users/toor'") + expect(provider).to receive(:shell_out!).with("ditto", "/System/Library/User Template/English.lproj", "/Users/toor") provider.ditto_home end it "creates the user's NFSHomeDirectory and home directory" do - expect(provider).to receive(:run_dscl).with("create /Users/toor NFSHomeDirectory '/Users/toor'").and_return(true) + expect(provider).to receive(:run_dscl).with("create", "/Users/toor", "NFSHomeDirectory", "/Users/toor").and_return(true) expect(provider).to receive(:ditto_home) provider.dscl_set_home end @@ -283,8 +281,8 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" let(:plutil_exists) { true } before do - allow(::File).to receive(:exists?).with("/usr/bin/dscl").and_return(dscl_exists) - allow(::File).to receive(:exists?).with("/usr/bin/plutil").and_return(plutil_exists) + allow(::File).to receive(:exist?).with("/usr/bin/dscl").and_return(dscl_exists) + allow(::File).to receive(:exist?).with("/usr/bin/plutil").and_return(plutil_exists) end def run_requirements @@ -382,8 +380,8 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" let(:user_plist_file) { nil } before do - expect(provider).to receive(:shell_out).with("dscacheutil '-flushcache'") - expect(provider).to receive(:shell_out).with("plutil -convert xml1 -o - /var/db/dslocal/nodes/Default/users/toor.plist") do + expect(provider).to receive(:shell_out).with("dscacheutil", "-flushcache") + expect(provider).to receive(:shell_out).with("plutil", "-convert", "xml1", "-o", "-", "/var/db/dslocal/nodes/Default/users/toor.plist") do if user_plist_file.nil? shellcmdresult.new("Can not find the file", "Sorry!!", 1) else @@ -391,7 +389,7 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" end end - if !user_plist_file.nil? + unless user_plist_file.nil? expect(provider).to receive(:convert_binary_plist_to_xml).and_return(File.read(File.join(CHEF_SPEC_DATA, "mac_users/#{user_plist_file}.shadow.xml"))) end end @@ -726,7 +724,7 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30") expect(provider).to receive(:prepare_password_shadow_info).and_return({}) mock_shellout = double("Mock::Shellout") allow(mock_shellout).to receive(:run_command) - expect(Mixlib::ShellOut).to receive(:new).and_return(mock_shellout) + expect(provider).to receive(:shell_out).and_return(mock_shellout) expect(provider).to receive(:read_user_info) expect(provider).to receive(:dscl_set) expect(provider).to receive(:sleep).with(3) @@ -754,29 +752,29 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30") end it "creates the user and sets the comment field" do - expect(provider).to receive(:run_dscl).with("create /Users/toor").and_return(true) + expect(provider).to receive(:run_dscl).with("create", "/Users/toor").and_return(true) provider.dscl_create_user end it "sets the comment field" do - expect(provider).to receive(:run_dscl).with("create /Users/toor RealName '#mockssuck'").and_return(true) + expect(provider).to receive(:run_dscl).with("create", "/Users/toor", "RealName", "#mockssuck").and_return(true) provider.dscl_create_comment end it "sets the comment field to username" do new_resource.comment nil - expect(provider).to receive(:run_dscl).with("create /Users/toor RealName '#mockssuck'").and_return(true) + expect(provider).to receive(:run_dscl).with("create", "/Users/toor", "RealName", "#mockssuck").and_return(true) provider.dscl_create_comment expect(new_resource.comment).to eq("#mockssuck") end it "should run run_dscl with create /Users/user PrimaryGroupID to set the users primary group" do - expect(provider).to receive(:run_dscl).with("create /Users/toor PrimaryGroupID '1001'").and_return(true) + expect(provider).to receive(:run_dscl).with("create", "/Users/toor", "PrimaryGroupID", 1001).and_return(true) provider.dscl_set_gid end it "should run run_dscl with create /Users/user UserShell to set the users login shell" do - expect(provider).to receive(:run_dscl).with("create /Users/toor UserShell '/usr/bin/false'").and_return(true) + expect(provider).to receive(:run_dscl).with("create", "/Users/toor", "UserShell", "/usr/bin/false").and_return(true) provider.dscl_set_shell end end @@ -788,21 +786,21 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30") end it "should map the group name to a numeric ID when the group exists" do - expect(provider).to receive(:run_dscl).with("read /Groups/newgroup PrimaryGroupID").ordered.and_return("PrimaryGroupID: 1001\n") - expect(provider).to receive(:run_dscl).with("create /Users/toor PrimaryGroupID '1001'").ordered.and_return(true) + expect(provider).to receive(:run_dscl).with("read", "/Groups/newgroup", "PrimaryGroupID").ordered.and_return("PrimaryGroupID: 1001\n") + expect(provider).to receive(:run_dscl).with("create", "/Users/toor", "PrimaryGroupID", "1001").ordered.and_return(true) provider.dscl_set_gid end it "should raise an exception when the group does not exist" do shell_return = shellcmdresult.new("<dscl_cmd> DS Error: -14136 (eDSRecordNotFound)", "err", -14136) - expect(provider).to receive(:shell_out).with("dscl . -read /Groups/newgroup PrimaryGroupID").and_return(shell_return) + expect(provider).to receive(:shell_out).with("dscl", ".", "-read", "/Groups/newgroup", "PrimaryGroupID").and_return(shell_return) expect { provider.dscl_set_gid }.to raise_error(Chef::Exceptions::GroupIDNotFound) end end it "should set group ID to 20 if it's not specified" do new_resource.gid nil - expect(provider).to receive(:run_dscl).with("create /Users/toor PrimaryGroupID '20'").ordered.and_return(true) + expect(provider).to receive(:run_dscl).with("create", "/Users/toor", "PrimaryGroupID", 20).ordered.and_return(true) provider.dscl_set_gid expect(new_resource.gid).to eq(20) end @@ -850,8 +848,8 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30") describe "when the user exists" do before do - expect(provider).to receive(:shell_out).with("dscacheutil '-flushcache'") - expect(provider).to receive(:shell_out).with("plutil -convert xml1 -o - /var/db/dslocal/nodes/Default/users/toor.plist") do + expect(provider).to receive(:shell_out).with("dscacheutil", "-flushcache") + expect(provider).to receive(:shell_out).with("plutil", "-convert", "xml1", "-o", "-", "/var/db/dslocal/nodes/Default/users/toor.plist") do shellcmdresult.new(File.read(File.join(CHEF_SPEC_DATA, "mac_users/10.9.plist.xml")), "", 0) end provider.load_current_resource @@ -859,14 +857,13 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30") describe "when Chef is removing the user" do it "removes the user from the groups and deletes home directory when the resource is configured to manage home" do - Chef::Config[:treat_deprecation_warnings_as_errors] = false - new_resource.supports({ :manage_home => true }) - expect(provider).to receive(:run_dscl).with("list /Groups").and_return("my_group\nyour_group\nreal_group\n") - expect(provider).to receive(:run_dscl).with("read /Groups/my_group").and_raise(Chef::Exceptions::DsclCommandFailed) # Empty group - expect(provider).to receive(:run_dscl).with("read /Groups/your_group").and_return("GroupMembership: not_you") - expect(provider).to receive(:run_dscl).with("read /Groups/real_group").and_return("GroupMembership: toor") - expect(provider).to receive(:run_dscl).with("delete /Groups/real_group GroupMembership 'toor'") - expect(provider).to receive(:run_dscl).with("delete /Users/toor") + new_resource.manage_home true + expect(provider).to receive(:run_dscl).with("list", "/Groups").and_return("my_group\nyour_group\nreal_group\n") + expect(provider).to receive(:run_dscl).with("read", "/Groups/my_group").and_raise(Chef::Exceptions::DsclCommandFailed) # Empty group + expect(provider).to receive(:run_dscl).with("read", "/Groups/your_group").and_return("GroupMembership: not_you") + expect(provider).to receive(:run_dscl).with("read", "/Groups/real_group").and_return("GroupMembership: toor") + expect(provider).to receive(:run_dscl).with("delete", "/Groups/real_group", "GroupMembership", "toor") + expect(provider).to receive(:run_dscl).with("delete", "/Users/toor") expect(FileUtils).to receive(:rm_rf).with("/Users/vagrant") provider.remove_user end @@ -889,7 +886,7 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30") end it "can unlock the user" do - expect(provider).to receive(:run_dscl).with("create /Users/toor AuthenticationAuthority ';ShadowHash;HASHLIST:<SALTED-SHA512-PBKDF2>'") + expect(provider).to receive(:run_dscl).with("create", "/Users/toor", "AuthenticationAuthority", ";ShadowHash;HASHLIST:<SALTED-SHA512-PBKDF2>") provider.unlock_user end end @@ -897,7 +894,7 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30") describe "when locking the user" do it "should run run_dscl with append /Users/user AuthenticationAuthority ;DisabledUser; to lock the user account" do - expect(provider).to receive(:run_dscl).with("append /Users/toor AuthenticationAuthority ';DisabledUser;'") + expect(provider).to receive(:run_dscl).with("append", "/Users/toor", "AuthenticationAuthority", ";DisabledUser;") provider.lock_user end end diff --git a/spec/unit/provider/user/linux_spec.rb b/spec/unit/provider/user/linux_spec.rb index ce9b84ec92..b04ada2511 100644 --- a/spec/unit/provider/user/linux_spec.rb +++ b/spec/unit/provider/user/linux_spec.rb @@ -55,7 +55,7 @@ describe Chef::Provider::User::Linux do # supports is a method on the superclass so can't totally be removed, but we should aggressively NOP it to decisively break it it "disables the supports API", chef: ">= 13" do - @new_resource.supports( { manage_home: true } ) + @new_resource.supports( manage_home: true ) expect( @new_resource.supports.key?(:manage_home) ).to be false end @@ -70,13 +70,13 @@ describe Chef::Provider::User::Linux do it "throws a deprecation warning on setting supports[:non_unique]" do Chef::Config[:treat_deprecation_warnings_as_errors] = false expect(Chef).to receive(:deprecated).with(:supports_property, "supports { non_unique: true } on the user resource is deprecated and will be removed in Chef 13, set non_unique true instead") - @new_resource.supports( { :non_unique => true } ) + @new_resource.supports( non_unique: true ) end it "throws a deprecation warning on setting supports[:manage_home]" do Chef::Config[:treat_deprecation_warnings_as_errors] = false expect(Chef).to receive(:deprecated).with(:supports_property, "supports { manage_home: true } on the user resource is deprecated and will be removed in Chef 13, set manage_home true instead") - @new_resource.supports( { :manage_home => true } ) + @new_resource.supports( manage_home: true ) end it "defaults manage_home to false" do @@ -85,13 +85,13 @@ describe Chef::Provider::User::Linux do it "supports[:manage_home] (incorectly) acts like manage_home" do Chef::Config[:treat_deprecation_warnings_as_errors] = false - @new_resource.supports({ manage_home: true }) + @new_resource.supports(manage_home: true) expect( provider.useradd_options ).to eql(["-m"]) end it "supports[:manage_home] does not change behavior of manage_home: false", chef: ">= 13" do Chef::Config[:treat_deprecation_warnings_as_errors] = false - @new_resource.supports({ manage_home: true }) + @new_resource.supports(manage_home: true) expect( provider.useradd_options ).to eql(["-M"]) end diff --git a/spec/unit/provider/user/pw_spec.rb b/spec/unit/provider/user/pw_spec.rb index fb7c9211a1..2f44d6f3e3 100644 --- a/spec/unit/provider/user/pw_spec.rb +++ b/spec/unit/provider/user/pw_spec.rb @@ -34,7 +34,7 @@ describe Chef::Provider::User::Pw do # XXX: rip out in Chef-13 Chef::Config[:treat_deprecation_warnings_as_errors] = false - @new_resource.supports :manage_home => true + @new_resource.supports manage_home: true @current_resource = Chef::Resource::User::PwUser.new("adam") @current_resource.comment "Adam Jacob" @@ -65,35 +65,36 @@ describe Chef::Provider::User::Pw do it "should set the option for #{attribute} if the new resources #{attribute} is not null" do allow(@new_resource).to receive(attribute).and_return("hola") - expect(@provider.set_options).to eql(" #{@new_resource.username} #{option} '#{@new_resource.send(attribute)}' -m") + expect(@provider.set_options).to eql([ @new_resource.username, option, @new_resource.send(attribute), "-m"]) end it "should set the option for #{attribute} if the new resources #{attribute} is not null, without homedir management" do - allow(@new_resource).to receive(:supports).and_return({ :manage_home => false }) + allow(@new_resource).to receive(:supports).and_return(manage_home: false) allow(@new_resource).to receive(attribute).and_return("hola") - expect(@provider.set_options).to eql(" #{@new_resource.username} #{option} '#{@new_resource.send(attribute)}'") + expect(@provider.set_options).to eql([@new_resource.username, option, @new_resource.send(attribute)]) end end it "should combine all the possible options" do - match_string = " adam" + match_array = [ "adam" ] field_list.sort { |a, b| a[0] <=> b[0] }.each do |attribute, option| allow(@new_resource).to receive(attribute).and_return("hola") - match_string << " #{option} 'hola'" + match_array << option + match_array << "hola" end - match_string << " -m" - expect(@provider.set_options).to eql(match_string) + match_array << "-m" + expect(@provider.set_options).to eql(match_array) end end describe "create_user" do before(:each) do - allow(@provider).to receive(:run_command).and_return(true) + allow(@provider).to receive(:shell_out!).and_return(true) allow(@provider).to receive(:modify_password).and_return(true) end it "should run pw useradd with the return of set_options" do - expect(@provider).to receive(:run_command).with({ :command => "pw useradd adam -m" }).and_return(true) + expect(@provider).to receive(:shell_out!).with("pw", "useradd", "adam", "-m").and_return(true) @provider.create_user end @@ -105,12 +106,12 @@ describe Chef::Provider::User::Pw do describe "manage_user" do before(:each) do - allow(@provider).to receive(:run_command).and_return(true) + allow(@provider).to receive(:shell_out!).and_return(true) allow(@provider).to receive(:modify_password).and_return(true) end it "should run pw usermod with the return of set_options" do - expect(@provider).to receive(:run_command).with({ :command => "pw usermod adam -m" }).and_return(true) + expect(@provider).to receive(:shell_out!).with("pw", "usermod", "adam", "-m").and_return(true) @provider.manage_user end @@ -122,13 +123,13 @@ describe Chef::Provider::User::Pw do describe "remove_user" do it "should run pw userdel with the new resources user name" do - @new_resource.supports :manage_home => false - expect(@provider).to receive(:run_command).with({ :command => "pw userdel #{@new_resource.username}" }).and_return(true) + @new_resource.supports manage_home: false + expect(@provider).to receive(:shell_out!).with("pw", "userdel", @new_resource.username).and_return(true) @provider.remove_user end it "should run pw userdel with the new resources user name and -r if manage_home is true" do - expect(@provider).to receive(:run_command).with({ :command => "pw userdel #{@new_resource.username} -r" }).and_return(true) + expect(@provider).to receive(:shell_out!).with("pw", "userdel", @new_resource.username, "-r").and_return(true) @provider.remove_user end end @@ -147,23 +148,26 @@ describe Chef::Provider::User::Pw do describe "when locking the user" do it "should run pw lock with the new resources username" do - expect(@provider).to receive(:run_command).with({ :command => "pw lock #{@new_resource.username}" }) + expect(@provider).to receive(:shell_out!).with("pw", "lock", @new_resource.username) @provider.lock_user end end describe "when unlocking the user" do it "should run pw unlock with the new resources username" do - expect(@provider).to receive(:run_command).with({ :command => "pw unlock #{@new_resource.username}" }) + expect(@provider).to receive(:shell_out!).with("pw", "unlock", @new_resource.username) @provider.unlock_user end end describe "when modifying the password" do before(:each) do - @status = double("Status", :exitstatus => 0) + @status = double("Status", exitstatus: 0) allow(@provider).to receive(:popen4).and_return(@status) - @pid, @stdin, @stdout, @stderr = nil, nil, nil, nil + @pid = nil + @stdin = nil + @stdout = nil + @stderr = nil end describe "and the new password has not been specified" do @@ -210,7 +214,7 @@ describe Chef::Provider::User::Pw do end it "should run pw usermod with the username and the option -H 0" do - expect(@provider).to receive(:popen4).with("pw usermod adam -H 0", :waitlast => true).and_return(@status) + expect(@provider).to receive(:popen4).with("pw usermod adam -H 0", waitlast: true).and_return(@status) @provider.modify_password end @@ -239,12 +243,12 @@ describe Chef::Provider::User::Pw do end it "should raise an error if the required binary /usr/sbin/pw doesn't exist" do - expect(File).to receive(:exists?).with("/usr/sbin/pw").and_return(false) + expect(File).to receive(:exist?).with("/usr/sbin/pw").and_return(false) expect { @provider.load_current_resource }.to raise_error(Chef::Exceptions::User) end it "shouldn't raise an error if /usr/sbin/pw exists" do - allow(File).to receive(:exists?).and_return(true) + allow(File).to receive(:exist?).and_return(true) expect { @provider.load_current_resource }.not_to raise_error end end diff --git a/spec/unit/provider/user/windows_spec.rb b/spec/unit/provider/user/windows_spec.rb index 324b5f503f..82f3c1ab2a 100644 --- a/spec/unit/provider/user/windows_spec.rb +++ b/spec/unit/provider/user/windows_spec.rb @@ -127,19 +127,19 @@ describe Chef::Provider::User::Windows do describe "when creating the user" do it "should call @net_user.add with the return of set_options" do - allow(@provider).to receive(:set_options).and_return(:name => "monkey") - expect(@net_user).to receive(:add).with(:name => "monkey") + allow(@provider).to receive(:set_options).and_return(name: "monkey") + expect(@net_user).to receive(:add).with(name: "monkey") @provider.create_user end end describe "manage_user" do before(:each) do - allow(@provider).to receive(:set_options).and_return(:name => "monkey") + allow(@provider).to receive(:set_options).and_return(name: "monkey") end it "should call @net_user.update with the return of set_options" do - expect(@net_user).to receive(:update).with(:name => "monkey") + expect(@net_user).to receive(:update).with(name: "monkey") @provider.manage_user end end diff --git a/spec/unit/provider/user_spec.rb b/spec/unit/provider/user_spec.rb index 719dc8d492..489597445f 100644 --- a/spec/unit/provider/user_spec.rb +++ b/spec/unit/provider/user_spec.rb @@ -58,7 +58,7 @@ describe Chef::Provider::User do describe "executing load_current_resource" do before(:each) do @node = Chef::Node.new - #@new_resource = double("Chef::Resource::User", + # @new_resource = double("Chef::Resource::User", # :null_object => true, # :username => "adam", # :comment => "Adam Jacob", @@ -68,7 +68,7 @@ describe Chef::Provider::User do # :shell => "/usr/bin/zsh", # :password => nil, # :updated => nil - #) + # ) allow(Chef::Resource::User).to receive(:new).and_return(@current_resource) @pw_user = EtcPwnamIsh.new @pw_user.name = "adam" @@ -110,11 +110,11 @@ describe Chef::Provider::User do # The mapping between the Chef::Resource::User and Getpwnam struct user_attrib_map = { - :uid => :uid, - :gid => :gid, - :comment => :gecos, - :home => :dir, - :shell => :shell, + uid: :uid, + gid: :gid, + comment: :gecos, + home: :dir, + shell: :shell, } user_attrib_map.each do |user_attrib, getpwnam_attrib| it "should set the current resources #{user_attrib} based on getpwnam #{getpwnam_attrib}" do @@ -140,18 +140,16 @@ describe Chef::Provider::User do describe "and running assertions" do def self.shadow_lib_unavail? - begin - require "rubygems" - require "shadow" - rescue LoadError - skip "ruby-shadow gem not installed for dynamic load test" - true - else - false - end + require "rubygems" + require "shadow" + rescue LoadError + skip "ruby-shadow gem not installed for dynamic load test" + true + else + false end - before (:each) do + before(:each) do user = @pw_user.dup user.name = "root" user.passwd = "x" @@ -161,15 +159,15 @@ describe Chef::Provider::User do unless shadow_lib_unavail? context "and we have the ruby-shadow gem" do - skip "and we are not root (rerun this again as root)", :requires_unprivileged_user => true + skip "and we are not root (rerun this again as root)", requires_unprivileged_user: true - context "and we are root", :requires_root => true do + context "and we are root", requires_root: true do it "should pass assertions when ruby-shadow can be loaded" do @provider.action = "create" original_method = @provider.method(:require) expect(@provider).to receive(:require) { |*args| original_method.call(*args) } - passwd_info = Struct::PasswdEntry.new(:sp_namp => "adm ", :sp_pwdp => "$1$T0N0Q.lc$nyG6pFI3Dpqa5cxUz/57j0", :sp_lstchg => 14861, :sp_min => 0, :sp_max => 99999, - :sp_warn => 7, :sp_inact => -1, :sp_expire => -1, :sp_flag => -1) + passwd_info = Struct::PasswdEntry.new(sp_namp: "adm ", sp_pwdp: "$1$T0N0Q.lc$nyG6pFI3Dpqa5cxUz/57j0", sp_lstchg: 14861, sp_min: 0, sp_max: 99999, + sp_warn: 7, sp_inact: -1, sp_expire: -1, sp_flag: -1) expect(Shadow::Passwd).to receive(:getspnam).with("adam").and_return(passwd_info) @provider.load_current_resource @provider.define_resource_requirements |