This is to prepare the next batch of commits.
Signed-off-by: Brice Figureau <[email protected]>
---
lib/puppet/auth/handler.rb | 12 ++++++++++++
lib/puppet/network/http/handler.rb | 12 ------------
spec/unit/auth/handler_spec.rb | 31 ++++++++++++++++++++++++++++++-
spec/unit/network/http/handler_spec.rb | 20 --------------------
4 files changed, 42 insertions(+), 33 deletions(-)
diff --git a/lib/puppet/auth/handler.rb b/lib/puppet/auth/handler.rb
index db6cd05..0822e44 100644
--- a/lib/puppet/auth/handler.rb
+++ b/lib/puppet/auth/handler.rb
@@ -1,7 +1,19 @@
+require 'resolv'
module Puppet::Auth::Handler
def self.included(mod)
type = mod.name.sub(/Puppet::Network::HTTP::(.*)REST/, '\1').downcase
mod.send(:include, Puppet::Auth::handler(type))
end
+
+ # resolve node name from peer's ip address
+ # this is used when the request is unauthenticated
+ def resolve_node(ip)
+ begin
+ return Resolv.getname(ip)
+ rescue => detail
+ Puppet.err "Could not resolve #{ip}: #{detail}"
+ end
+ ip
+ end
end
\ No newline at end of file
diff --git a/lib/puppet/network/http/handler.rb
b/lib/puppet/network/http/handler.rb
index 82238aa..b25fe26 100644
--- a/lib/puppet/network/http/handler.rb
+++ b/lib/puppet/network/http/handler.rb
@@ -4,7 +4,6 @@ end
require 'puppet/network/http/api/v1'
require 'puppet/network/rest_authorization'
require 'puppet/network/rights'
-require 'resolv'
module Puppet::Network::HTTP::Handler
include Puppet::Network::HTTP::API::V1
@@ -150,17 +149,6 @@ module Puppet::Network::HTTP::Handler
return_yaml_response(response, result)
end
- # resolve node name from peer's ip address
- # this is used when the request is unauthenticated
- def resolve_node(result)
- begin
- return Resolv.getname(result[:ip])
- rescue => detail
- Puppet.err "Could not resolve #{result[:ip]}: #{detail}"
- end
- result[:ip]
- end
-
private
def return_yaml_response(response, body)
diff --git a/spec/unit/auth/handler_spec.rb b/spec/unit/auth/handler_spec.rb
index 1c07dc1..918fa42 100644
--- a/spec/unit/auth/handler_spec.rb
+++ b/spec/unit/auth/handler_spec.rb
@@ -22,4 +22,33 @@ describe Puppet::Auth::Handler do
handler.should be_include(Puppet::Auth::MongrelSsl)
end
end
-end
\ No newline at end of file
+
+ describe "when resolving node" do
+ before do
+ @handler = Class.new do
+ def self.name
+ "Puppet::Network::HTTP::MongrelREST"
+ end
+ include Puppet::Auth::Handler
+ end.new
+ end
+
+ it "should use a look-up from the ip address" do
+ Resolv.expects(:getname).with("1.2.3.4").returns("host.domain.com")
+
+ @handler.resolve_node("1.2.3.4")
+ end
+
+ it "should return the look-up result" do
+ Resolv.stubs(:getname).with("1.2.3.4").returns("host.domain.com")
+
+ @handler.resolve_node("1.2.3.4").should == "host.domain.com"
+ end
+
+ it "should return the ip address if resolving fails" do
+ Resolv.stubs(:getname).with("1.2.3.4").raises(RuntimeError, "no such
host")
+
+ @handler.resolve_node("1.2.3.4").should == "1.2.3.4"
+ end
+ end
+end
diff --git a/spec/unit/network/http/handler_spec.rb
b/spec/unit/network/http/handler_spec.rb
index 16f1b53..106fd9f 100755
--- a/spec/unit/network/http/handler_spec.rb
+++ b/spec/unit/network/http/handler_spec.rb
@@ -407,24 +407,4 @@ describe Puppet::Network::HTTP::Handler do
end
end
end
-
- describe "when resolving node" do
- it "should use a look-up from the ip address" do
- Resolv.expects(:getname).with("1.2.3.4").returns("host.domain.com")
-
- @handler.resolve_node(:ip => "1.2.3.4")
- end
-
- it "should return the look-up result" do
- Resolv.stubs(:getname).with("1.2.3.4").returns("host.domain.com")
-
- @handler.resolve_node(:ip => "1.2.3.4").should == "host.domain.com"
- end
-
- it "should return the ip address if resolving fails" do
- Resolv.stubs(:getname).with("1.2.3.4").raises(RuntimeError, "no such
host")
-
- @handler.resolve_node(:ip => "1.2.3.4").should == "1.2.3.4"
- end
- end
end
--
1.7.2.1
--
You received this message because you are subscribed to the Google Groups
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-dev?hl=en.