diff options
author | Moser, Kevin <Kevin.Moser@nordstrom.com> | 2013-01-22 10:25:14 -0800 |
---|---|---|
committer | Moser, Kevin <Kevin.Moser@nordstrom.com> | 2013-01-22 10:25:14 -0800 |
commit | ea9c00c93268e840c3bed0c05db9c2827ece4e90 (patch) | |
tree | 84f9918ab542a0984f2e81322fa229e55f6c07c4 /spec/mixlib | |
parent | 6fd71d85c67f5a8ee5722ee2d8ec83babfd1fb08 (diff) | |
download | mixlib-shellout-ea9c00c93268e840c3bed0c05db9c2827ece4e90.tar.gz |
Add tests for running as different user in windows
Diffstat (limited to 'spec/mixlib')
-rw-r--r-- | spec/mixlib/shellout/windows_spec.rb | 2 | ||||
-rw-r--r-- | spec/mixlib/shellout_spec.rb | 71 |
2 files changed, 70 insertions, 3 deletions
diff --git a/spec/mixlib/shellout/windows_spec.rb b/spec/mixlib/shellout/windows_spec.rb index be515be..4d9359f 100644 --- a/spec/mixlib/shellout/windows_spec.rb +++ b/spec/mixlib/shellout/windows_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe 'Mixlib::ShellOut::Windows', :windows_only do - + describe 'Utils' do describe '.should_run_under_cmd?' do subject { Mixlib::ShellOut::Windows::Utils.should_run_under_cmd?(command) } diff --git a/spec/mixlib/shellout_spec.rb b/spec/mixlib/shellout_spec.rb index 16bef29..c44a9c3 100644 --- a/spec/mixlib/shellout_spec.rb +++ b/spec/mixlib/shellout_spec.rb @@ -79,7 +79,33 @@ describe Mixlib::ShellOut do shell_cmd.uid.should eql(expected_uid) end end + end + + context 'when setting with_logon' do + let(:accessor) { :with_logon } + let(:value) { 'root' } + + it "should set the with_logon" do + should eql(value) + end + end + context 'when setting domain' do + let(:accessor) { :domain } + let(:value) { 'localhost' } + + it "should set the domain" do + should eql(value) + end + end + + context 'when setting password' do + let(:accessor) { :password } + let(:value) { 'vagrant' } + + it "should set the password" do + should eql(value) + end end context 'when setting group' do @@ -177,12 +203,15 @@ describe Mixlib::ShellOut do context "with options hash" do let(:cmd) { 'brew install couchdb' } - let(:options) { { :cwd => cwd, :user => user, :group => group, :umask => umask, - :timeout => timeout, :environment => environment, :returns => valid_exit_codes, + let(:options) { { :cwd => cwd, :user => user, :domain => domain, :password => password, :group => group, + :umask => umask, :timeout => timeout, :environment => environment, :returns => valid_exit_codes, :live_stream => stream, :input => input } } let(:cwd) { '/tmp' } let(:user) { 'toor' } + let(:with_logon) { user } + let(:domain) { 'localhost' } + let(:password) { 'vagrant' } let(:group) { 'wheel' } let(:umask) { '2222' } let(:timeout) { 5 } @@ -199,6 +228,18 @@ describe Mixlib::ShellOut do shell_cmd.user.should eql(user) end + it "should set the with_logon" do + shell_cmd.with_logon.should eql(with_logon) + end + + it "should set the domain" do + shell_cmd.domain.should eql(domain) + end + + it "should set the password" do + shell_cmd.password.should eql(password) + end + it "should set the group" do shell_cmd.group.should eql(group) end @@ -361,6 +402,32 @@ describe Mixlib::ShellOut do end end + context "when running under Windows", :windows_only do + let(:cmd) { 'whoami.exe' } + let(:running_user) { shell_cmd.run_command.stdout.strip.downcase } + + context "when no user is set" do + # Need to adjust the username and domain if running as local system + # to match how whoami returns the information + local_system = (ENV['USERNAME'].downcase == "x3v7-vagrant$") + let(:domain) { local_system ? 'nt authority' : ENV['COMPUTERNAME'].downcase } + let(:user) { local_system ? 'system' : ENV['USERNAME'].downcase } + it "should run as current user" do + running_user.should eql("#{domain}\\#{user}") + end + end + + context "when user is set to Administrator" do + let(:user) { 'administrator' } + let(:domain) { ENV['COMPUTERNAME'].downcase } + let(:options) { { :domain => domain, :user => user, :password => 'vagrant' } } + + it "should run as Administrator" do + running_user.should eql("#{domain}\\#{user}") + end + end + end + context "with a live stream" do let(:stream) { StringIO.new } let(:ruby_code) { 'puts "hello"' } |