summaryrefslogtreecommitdiff
path: root/spec/unit/provider/user/solaris_spec.rb
diff options
context:
space:
mode:
authordanielsdeleo <dan@opscode.com>2013-06-20 16:15:26 -0700
committerdanielsdeleo <dan@opscode.com>2013-06-20 16:15:26 -0700
commit3e371c251db704884f5999057bc769785e4c75b2 (patch)
tree885a46e44a4f539ea4c9491a75ede1cc0cfbe1c0 /spec/unit/provider/user/solaris_spec.rb
parent1f316fcbd885f579d1b7e89efe6621bf2b759959 (diff)
downloadchef-3e371c251db704884f5999057bc769785e4c75b2.tar.gz
[CHEF-4204] Fix solaris tests to not access shadow file.
- Update useradd shared examples to rely on let block defined provider object so custom method stubs can be added. - Stub methods that manipulate shadow file on the solaris provider in the shared examples. - Remove unnecessary test setup from solaris provider specific tests.
Diffstat (limited to 'spec/unit/provider/user/solaris_spec.rb')
-rw-r--r--spec/unit/provider/user/solaris_spec.rb46
1 files changed, 19 insertions, 27 deletions
diff --git a/spec/unit/provider/user/solaris_spec.rb b/spec/unit/provider/user/solaris_spec.rb
index 92a73cd4c8..5500eac812 100644
--- a/spec/unit/provider/user/solaris_spec.rb
+++ b/spec/unit/provider/user/solaris_spec.rb
@@ -21,6 +21,16 @@
require 'spec_helper'
describe Chef::Provider::User::Solaris do
+
+ subject(:provider) do
+ p = described_class.new(@new_resource, @run_context)
+ p.current_resource = @current_resource
+
+ # Prevent the useradd-based provider tests from trying to write /etc/shadow
+ p.stub!(:write_shadow_file)
+ p
+ end
+
supported_useradd_options = {
'comment' => "-c",
'gid' => "-g",
@@ -37,49 +47,31 @@ describe Chef::Provider::User::Solaris do
@run_context = Chef::RunContext.new(@node, {}, @events)
@new_resource = Chef::Resource::User.new("adam", @run_context)
- @new_resource.comment "Adam Jacob"
- @new_resource.uid 1000
- @new_resource.gid 1000
- @new_resource.home "/home/adam"
- @new_resource.shell "/usr/bin/zsh"
- @new_resource.password "abracadabra"
- @new_resource.system false
- @new_resource.manage_home false
- @new_resource.non_unique false
@current_resource = Chef::Resource::User.new("adam", @run_context)
- @current_resource.comment "Adam Jacob"
- @current_resource.uid 1000
- @current_resource.gid 1000
- @current_resource.home "/home/adam"
- @current_resource.shell "/usr/bin/zsh"
- @current_resource.password "abracadabra"
- @current_resource.system false
- @current_resource.manage_home false
- @current_resource.non_unique false
- @current_resource.supports({:manage_home => false, :non_unique => false})
- @provider = Chef::Provider::User::Solaris.new(@new_resource, @run_context)
- @provider.current_resource = @current_resource
@new_resource.password "hocus-pocus"
+
+ # Let these tests run #write_shadow_file
+ provider.unstub!(:write_shadow_file)
end
it "should use its own shadow file writer to set the password" do
- @provider.should_receive(:write_shadow_file)
- @provider.stub!(:shell_out!).and_return(true)
- @provider.manage_user
+ provider.should_receive(:write_shadow_file)
+ provider.stub!(:shell_out!).and_return(true)
+ provider.manage_user
end
it "should write out a modified version of the password file" do
password_file = Tempfile.new("shadow")
password_file.puts "adam:existingpassword:15441::::::"
password_file.close
- @provider.password_file = password_file.path
- @provider.stub!(:shell_out!).and_return(true)
+ provider.password_file = password_file.path
+ provider.stub!(:shell_out!).and_return(true)
# may not be able to write to /etc for tests...
temp_file = Tempfile.new("shadow")
Tempfile.stub!(:new).with("shadow", "/etc").and_return(temp_file)
@new_resource.password "verysecurepassword"
- @provider.manage_user
+ provider.manage_user
::File.open(password_file.path, "r").read.should =~ /adam:verysecurepassword:/
password_file.unlink
end