From 432cf992f7807b5541a07e533c735826432c1c7b Mon Sep 17 00:00:00 2001 From: Seth Chisamore Date: Thu, 29 Dec 2011 23:20:45 -0500 Subject: [PATCH] unit tests for windows-specific 'rights' and 'inherits' attributes --- chef/spec/unit/mixin/securable_spec.rb | 172 +++++++++++++++++-------- 1 file changed, 120 insertions(+), 52 deletions(-) diff --git a/chef/spec/unit/mixin/securable_spec.rb b/chef/spec/unit/mixin/securable_spec.rb index 892e1880346..8c68ddad19e 100644 --- a/chef/spec/unit/mixin/securable_spec.rb +++ b/chef/spec/unit/mixin/securable_spec.rb @@ -19,77 +19,145 @@ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper")) describe Chef::Mixin::Securable do - describe "Unix" do - before do - Chef::Platform.stub!(:windows?).and_return(false) - with_constants :RUBY_PLATFORM => 'x86_64-darwin11.2.0' do + before(:each) do + @securable = Object.new + @securable.send(:extend, Chef::Mixin::Securable) + @securable.send(:extend, Chef::Mixin::ParamsValidate) + end + + it "should accept a group name or id for group" do + lambda { @securable.group "root" }.should_not raise_error(ArgumentError) + lambda { @securable.group 123 }.should_not raise_error(ArgumentError) + lambda { @securable.group 'test\ group' }.should_not raise_error(ArgumentError) + lambda { @securable.group "root*goo" }.should raise_error(ArgumentError) + end + + it "should accept a unix file mode in string form as an octal number" do + lambda { @securable.mode "0" }.should_not raise_error(ArgumentError) + lambda { @securable.mode "0000" }.should_not raise_error(ArgumentError) + lambda { @securable.mode "0111" }.should_not raise_error(ArgumentError) + lambda { @securable.mode "0444" }.should_not raise_error(ArgumentError) + + lambda { @securable.mode "111" }.should_not raise_error(ArgumentError) + lambda { @securable.mode "444" }.should_not raise_error(ArgumentError) + lambda { @securable.mode "7777" }.should_not raise_error(ArgumentError) + lambda { @securable.mode "07777" }.should_not raise_error(ArgumentError) + + lambda { @securable.mode "-01" }.should raise_error(ArgumentError) + lambda { @securable.mode "010000" }.should raise_error(ArgumentError) + lambda { @securable.mode "-1" }.should raise_error(ArgumentError) + lambda { @securable.mode "10000" }.should raise_error(ArgumentError) + + lambda { @securable.mode "07778" }.should raise_error(ArgumentError) + lambda { @securable.mode "7778" }.should raise_error(ArgumentError) + lambda { @securable.mode "4095" }.should raise_error(ArgumentError) + + lambda { @securable.mode "0foo1234" }.should raise_error(ArgumentError) + lambda { @securable.mode "foo1234" }.should raise_error(ArgumentError) + end + + it "should accept a unix file mode in numeric form as a ruby-interpreted integer" do + lambda { @securable.mode 0 }.should_not raise_error(ArgumentError) + lambda { @securable.mode 0000 }.should_not raise_error(ArgumentError) + lambda { @securable.mode 444 }.should_not raise_error(ArgumentError) + lambda { @securable.mode 0444 }.should_not raise_error(ArgumentError) + lambda { @securable.mode 07777 }.should_not raise_error(ArgumentError) + + lambda { @securable.mode 292 }.should_not raise_error(ArgumentError) + lambda { @securable.mode 4095 }.should_not raise_error(ArgumentError) + + lambda { @securable.mode 0111 }.should_not raise_error(ArgumentError) + lambda { @securable.mode 73 }.should_not raise_error(ArgumentError) + + lambda { @securable.mode -01 }.should raise_error(ArgumentError) + lambda { @securable.mode 010000 }.should raise_error(ArgumentError) + lambda { @securable.mode -1 }.should raise_error(ArgumentError) + lambda { @securable.mode 4096 }.should raise_error(ArgumentError) + end + + it "should accept a user name or id for owner" do + lambda { @securable.owner "root" }.should_not raise_error(ArgumentError) + lambda { @securable.owner 123 }.should_not raise_error(ArgumentError) + lambda { @securable.owner "root*goo" }.should raise_error(ArgumentError) + end + + it "allows the owner to be specified as #user" do + @securable.should respond_to(:user) + end + + describe "windows-specific methods" do + before(:all) do + platform_mock :windows do load File.join(File.dirname(__FILE__), "..", "..", "..", "lib", "chef", "config.rb") load File.join(File.dirname(__FILE__), "..", "..", "..", "lib", "chef", "mixin", "securable.rb") - @securable = Object.new - @securable.send(:extend, Chef::Mixin::Securable) - @securable.send(:extend, Chef::Mixin::ParamsValidate) end end - it "should accept a group name or id for group" do - lambda { @securable.group "root" }.should_not raise_error(ArgumentError) - lambda { @securable.group 123 }.should_not raise_error(ArgumentError) - lambda { @securable.group 'test\ group' }.should_not raise_error(ArgumentError) - lambda { @securable.group "root*goo" }.should raise_error(ArgumentError) + before(:each) do + @securable = Object.new + @securable.send(:extend, Chef::Mixin::Securable) + @securable.send(:extend, Chef::Mixin::ParamsValidate) end - it "should accept a unix file mode in string form as an octal number" do - lambda { @securable.mode "0" }.should_not raise_error(ArgumentError) - lambda { @securable.mode "0000" }.should_not raise_error(ArgumentError) - lambda { @securable.mode "0111" }.should_not raise_error(ArgumentError) - lambda { @securable.mode "0444" }.should_not raise_error(ArgumentError) - - lambda { @securable.mode "111" }.should_not raise_error(ArgumentError) - lambda { @securable.mode "444" }.should_not raise_error(ArgumentError) - lambda { @securable.mode "7777" }.should_not raise_error(ArgumentError) - lambda { @securable.mode "07777" }.should_not raise_error(ArgumentError) - - lambda { @securable.mode "-01" }.should raise_error(ArgumentError) - lambda { @securable.mode "010000" }.should raise_error(ArgumentError) - lambda { @securable.mode "-1" }.should raise_error(ArgumentError) - lambda { @securable.mode "10000" }.should raise_error(ArgumentError) + it "should allow you to specify :read, :deny, :full_control and :write rights" do + lambda { @securable.rights :read, "The Dude" }.should_not raise_error(ArgumentError) + lambda { @securable.rights :deny, "The Dude" }.should_not raise_error(ArgumentError) + lambda { @securable.rights :full_control, "The Dude" }.should_not raise_error(ArgumentError) + lambda { @securable.rights :write, "The Dude" }.should_not raise_error(ArgumentError) + lambda { @securable.rights :to_party, "The Dude" }.should raise_error(ArgumentError) + end - lambda { @securable.mode "07778" }.should raise_error(ArgumentError) - lambda { @securable.mode "7778" }.should raise_error(ArgumentError) - lambda { @securable.mode "4095" }.should raise_error(ArgumentError) + it "should accept a principal as a string or an array" do + lambda { @securable.rights :read, "The Dude" }.should_not raise_error(ArgumentError) + lambda { @securable.rights :read, ["The Dude","Donny"] }.should_not raise_error(ArgumentError) + lambda { @securable.rights :read, 3 }.should raise_error(ArgumentError) + end - lambda { @securable.mode "0foo1234" }.should raise_error(ArgumentError) - lambda { @securable.mode "foo1234" }.should raise_error(ArgumentError) + it "should allow you to specify whether the permissions applies_to_children with true/false/:containers_only/:objects_only" do + lambda { @securable.rights :read, "The Dude", :applies_to_children => false }.should_not raise_error(ArgumentError) + lambda { @securable.rights :read, "The Dude", :applies_to_children => true }.should_not raise_error(ArgumentError) + lambda { @securable.rights :read, "The Dude", :applies_to_children => :containers_only }.should_not raise_error(ArgumentError) + lambda { @securable.rights :read, "The Dude", :applies_to_children => :objects_only }.should_not raise_error(ArgumentError) + lambda { @securable.rights :read, "The Dude", :applies_to_children => 'poop' }.should raise_error(ArgumentError) end - it "should accept a unix file mode in numeric form as a ruby-interpreted integer" do - lambda { @securable.mode 0 }.should_not raise_error(ArgumentError) - lambda { @securable.mode 0000 }.should_not raise_error(ArgumentError) - lambda { @securable.mode 444 }.should_not raise_error(ArgumentError) - lambda { @securable.mode 0444 }.should_not raise_error(ArgumentError) - lambda { @securable.mode 07777 }.should_not raise_error(ArgumentError) + it "should allow you to specify whether the permissions applies_to_self with true/false" do + lambda { @securable.rights :read, "The Dude", :applies_to_children => true, :applies_to_self => false }.should_not raise_error(ArgumentError) + lambda { @securable.rights :read, "The Dude", :applies_to_self => true }.should_not raise_error(ArgumentError) + lambda { @securable.rights :read, "The Dude", :applies_to_self => 'poop' }.should raise_error(ArgumentError) + end - lambda { @securable.mode 292 }.should_not raise_error(ArgumentError) - lambda { @securable.mode 4095 }.should_not raise_error(ArgumentError) + it "should allow you to specify whether the permissions applies one_level_deep with true/false" do + lambda { @securable.rights :read, "The Dude", :applies_to_children => true, :one_level_deep => false }.should_not raise_error(ArgumentError) + lambda { @securable.rights :read, "The Dude", :applies_to_children => true, :one_level_deep => true }.should_not raise_error(ArgumentError) + lambda { @securable.rights :read, "The Dude", :applies_to_children => true, :one_level_deep => 'poop' }.should raise_error(ArgumentError) + end - lambda { @securable.mode 0111 }.should_not raise_error(ArgumentError) - lambda { @securable.mode 73 }.should_not raise_error(ArgumentError) + it "should allow multiple rights declarations" do + @securable.rights :read, "The Dude" + @securable.rights :deny, "The Dude" + @securable.rights :full_control, "The Dude" + @securable.rights :write, "The Dude" + @securable.rights.size.should == 4 + end - lambda { @securable.mode -01 }.should raise_error(ArgumentError) - lambda { @securable.mode 010000 }.should raise_error(ArgumentError) - lambda { @securable.mode -1 }.should raise_error(ArgumentError) - lambda { @securable.mode 4096 }.should raise_error(ArgumentError) + it "should allow you to specify whether the permission applies_to_self only if you specified it applies_to_children" do + lambda { @securable.rights :read, "The Dude", :applies_to_children => true, :applies_to_self => true }.should_not raise_error(ArgumentError) + lambda { @securable.rights :read, "The Dude", :applies_to_children => false, :applies_to_self => false }.should raise_error(ArgumentError) + lambda { @securable.rights :read, "The Dude", :applies_to_self => false }.should raise_error(ArgumentError) end - it "should accept a user name or id for owner" do - lambda { @securable.owner "root" }.should_not raise_error(ArgumentError) - lambda { @securable.owner 123 }.should_not raise_error(ArgumentError) - lambda { @securable.owner "root*goo" }.should raise_error(ArgumentError) + it "should allow you to specify whether the permission applies one_level_deep only if you specified it applies_to_children" do + lambda { @securable.rights :read, "The Dude", :applies_to_children => true, :one_level_deep => true }.should_not raise_error(ArgumentError) + lambda { @securable.rights :read, "The Dude", :applies_to_children => false, :one_level_deep => true }.should raise_error(ArgumentError) + lambda { @securable.rights :read, "The Dude", :one_level_deep => true }.should raise_error(ArgumentError) end - it "allows the owner to be specified as #user" do - @securable.should respond_to(:user) + it "should allow you to specify whether the permissions inherit with true/false" do + lambda { @securable.inherits true }.should_not raise_error(ArgumentError) + lambda { @securable.inherits false }.should_not raise_error(ArgumentError) + lambda { @securable.inherits "monkey" }.should raise_error(ArgumentError) end end end