summaryrefslogtreecommitdiffstats
path: root/spec/unit
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-09-22 01:24:04 -0500
committerLuke Kanies <luke@madstop.com>2007-09-22 01:24:04 -0500
commita66699596452f88d2bc467af4cff3f9a1aec3d1e (patch)
treef24e797d1709e27374692f079980167d5f136daf /spec/unit
parentebe7290bf0c9119e268c9037c33da515e527aa5b (diff)
Adding the last tests for the ldap node terminus. I managed
to forget the tests around the main find() method.
Diffstat (limited to 'spec/unit')
-rwxr-xr-xspec/unit/indirector/ldap.rb4
-rwxr-xr-xspec/unit/indirector/ldap/node.rb156
2 files changed, 158 insertions, 2 deletions
diff --git a/spec/unit/indirector/ldap.rb b/spec/unit/indirector/ldap.rb
index a936936bc..fe9408986 100755
--- a/spec/unit/indirector/ldap.rb
+++ b/spec/unit/indirector/ldap.rb
@@ -78,7 +78,7 @@ describe Puppet::Indirector::Ldap, " when searching ldap" do
it "should call process() on the first found entry" do
@connection.expects(:search).yields("myresult")
- @searcher.expects(:process).with("myresult")
+ @searcher.expects(:process).with("yay", "myresult")
@searcher.find "yay"
end
@@ -92,7 +92,7 @@ describe Puppet::Indirector::Ldap, " when searching ldap" do
raise "failed"
end
end.yields("myresult")
- @searcher.expects(:process).with("myresult")
+ @searcher.expects(:process).with("yay", "myresult")
@searcher.find "yay"
end
diff --git a/spec/unit/indirector/ldap/node.rb b/spec/unit/indirector/ldap/node.rb
index edaf77e92..37953db19 100755
--- a/spec/unit/indirector/ldap/node.rb
+++ b/spec/unit/indirector/ldap/node.rb
@@ -4,7 +4,163 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
require 'puppet/indirector/ldap/node'
+module LdapNodeSearching
+ def setup
+ @searcher = Puppet::Indirector::Ldap::Node.new
+ @entries = {}
+ entries = @entries
+
+ @connection = mock 'connection'
+ @entry = mock 'entry'
+ @connection.stubs(:search).yields(@entry)
+ @searcher.stubs(:connection).returns(@connection)
+ @searcher.stubs(:class_attributes).returns([])
+ @searcher.stubs(:parent_attribute).returns(nil)
+ @searcher.stubs(:search_base).returns(:yay)
+ @searcher.stubs(:search_filter).returns(:filter)
+
+ @node = mock 'node'
+ @node.stubs(:fact_merge)
+ @name = "mynode"
+ Puppet::Node.stubs(:new).with(@name).returns(@node)
+ end
+end
+
describe Puppet::Indirector::Ldap::Node, " when searching for nodes" do
+ include LdapNodeSearching
+
+ it "should return nil if no results are found in ldap" do
+ @connection.stubs(:search)
+ @searcher.find("mynode").should be_nil
+ end
+
+ it "should return a node object if results are found in ldap" do
+ @entry.stubs(:to_hash).returns({})
+ @searcher.find("mynode").should equal(@node)
+ end
+
+ it "should deduplicate class values" do
+ @entry.stubs(:to_hash).returns({})
+ @searcher.stubs(:class_attributes).returns(%w{one two})
+ @entry.stubs(:vals).with("one").returns(%w{a b})
+ @entry.stubs(:vals).with("two").returns(%w{b c})
+ @node.expects(:classes=).with(%w{a b c})
+ @searcher.find("mynode")
+ end
+
+ it "should add any values stored in the class_attributes attributes to the node classes" do
+ @entry.stubs(:to_hash).returns({})
+ @searcher.stubs(:class_attributes).returns(%w{one two})
+ @entry.stubs(:vals).with("one").returns(%w{a b})
+ @entry.stubs(:vals).with("two").returns(%w{c d})
+ @node.expects(:classes=).with(%w{a b c d})
+ @searcher.find("mynode")
+ end
+
+ it "should add all entry attributes as node parameters" do
+ @entry.stubs(:to_hash).returns("one" => ["two"], "three" => ["four"])
+ @node.expects(:parameters=).with("one" => "two", "three" => "four")
+ @searcher.find("mynode")
+ end
+
+ it "should retain false parameter values" do
+ @entry.stubs(:to_hash).returns("one" => [false])
+ @node.expects(:parameters=).with("one" => false)
+ @searcher.find("mynode")
+ end
+
+ it "should turn single-value parameter value arrays into single non-arrays" do
+ @entry.stubs(:to_hash).returns("one" => ["a"])
+ @node.expects(:parameters=).with("one" => "a")
+ @searcher.find("mynode")
+ end
+
+ it "should keep multi-valued parametes as arrays" do
+ @entry.stubs(:to_hash).returns("one" => ["a", "b"])
+ @node.expects(:parameters=).with("one" => ["a", "b"])
+ @searcher.find("mynode")
+ end
+end
+
+describe Puppet::Indirector::Ldap::Node, " when a parent node exists" do
+ include LdapNodeSearching
+
+ before do
+ @parent = mock 'parent'
+ @parent_parent = mock 'parent_parent'
+
+ @searcher.meta_def(:search_filter) do |name|
+ return name
+ end
+ @connection.stubs(:search).with { |*args| args[2] == @name }.yields(@entry)
+ @connection.stubs(:search).with { |*args| args[2] == 'parent' }.yields(@parent)
+ @connection.stubs(:search).with { |*args| args[2] == 'parent_parent' }.yields(@parent_parent)
+
+ @searcher.stubs(:parent_attribute).returns(:parent)
+ end
+
+ it "should add any parent classes to the node's classes" do
+ @entry.stubs(:to_hash).returns({})
+ @entry.stubs(:vals).with(:parent).returns(%w{parent})
+ @entry.stubs(:vals).with("one").returns(%w{a b})
+
+ @parent.stubs(:to_hash).returns({})
+ @parent.stubs(:vals).with("one").returns(%w{c d})
+ @parent.stubs(:vals).with(:parent).returns(nil)
+
+ @searcher.stubs(:class_attributes).returns(%w{one})
+ @node.expects(:classes=).with(%w{a b c d})
+ @searcher.find("mynode")
+ end
+
+ it "should add any parent parameters to the node's parameters" do
+ @entry.stubs(:to_hash).returns("one" => "two")
+ @entry.stubs(:vals).with(:parent).returns(%w{parent})
+
+ @parent.stubs(:to_hash).returns("three" => "four")
+ @parent.stubs(:vals).with(:parent).returns(nil)
+
+ @node.expects(:parameters=).with("one" => "two", "three" => "four")
+ @searcher.find("mynode")
+ end
+
+ it "should prefer node parameters over parent parameters" do
+ @entry.stubs(:to_hash).returns("one" => "two")
+ @entry.stubs(:vals).with(:parent).returns(%w{parent})
+
+ @parent.stubs(:to_hash).returns("one" => "three")
+ @parent.stubs(:vals).with(:parent).returns(nil)
+
+ @node.expects(:parameters=).with("one" => "two")
+ @searcher.find("mynode")
+ end
+
+ it "should recursively look up parent information" do
+ @entry.stubs(:to_hash).returns("one" => "two")
+ @entry.stubs(:vals).with(:parent).returns(%w{parent})
+
+ @parent.stubs(:to_hash).returns("three" => "four")
+ @parent.stubs(:vals).with(:parent).returns(['parent_parent'])
+
+ @parent_parent.stubs(:to_hash).returns("five" => "six")
+ @parent_parent.stubs(:vals).with(:parent).returns(nil)
+ @parent_parent.stubs(:vals).with(:parent).returns(nil)
+
+ @node.expects(:parameters=).with("one" => "two", "three" => "four", "five" => "six")
+ @searcher.find("mynode")
+ end
+
+ it "should not allow loops in parent declarations" do
+ @entry.stubs(:to_hash).returns("one" => "two")
+ @entry.stubs(:vals).with(:parent).returns(%w{parent})
+
+ @parent.stubs(:to_hash).returns("three" => "four")
+ @parent.stubs(:vals).with(:parent).returns([@name])
+ proc { @searcher.find("mynode") }.should raise_error(ArgumentError)
+ end
+end
+
+describe Puppet::Indirector::Ldap::Node, " when developing the search query" do
before do
@searcher = Puppet::Indirector::Ldap::Node.new
end