Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch '14463-port_fixnums_to_strings'

Fixes #101 pull request.
  • Loading branch information...
commit b0a512277c85e9bf8bcd81ea61aa8009f4721320 2 parents b4ae95d + b4d2e07
@dcarley dcarley authored
View
6 lib/puppet/type/firewall.rb
@@ -131,7 +131,7 @@
EOS
munge do |value|
- @resource.string_to_port(value)
+ @resource.string_to_port(value, :proto)
end
def is_to_s(value)
@@ -161,7 +161,7 @@ def should_to_s(value)
EOS
munge do |value|
- @resource.string_to_port(value)
+ @resource.string_to_port(value, :proto)
end
def is_to_s(value)
@@ -191,7 +191,7 @@ def should_to_s(value)
EOS
munge do |value|
- @resource.string_to_port(value)
+ @resource.string_to_port(value, :proto)
end
def is_to_s(value)
View
15 lib/puppet/util/firewall.rb
@@ -65,21 +65,26 @@ def log_level_name_to_number(value)
end
end
- # This method takes a string and attempts to convert it to a port number
- # if valid.
+ # This method takes a string and a protocol and attempts to convert
+ # it to a port number if valid.
#
# If the string already contains a port number or perhaps a range of ports
# in the format 22:1000 for example, it simply returns the string and does
# nothing.
- def string_to_port(value)
+ def string_to_port(value, proto)
+ proto = proto.to_s
+ unless proto =~ /^(tcp|udp)$/
+ proto = 'tcp'
+ end
+
if value.kind_of?(String)
if value.match(/^\d+(-\d+)?$/)
return value
else
- return Socket.getservbyname(value).to_s
+ return Socket.getservbyname(value, proto).to_s
end
else
- Socket.getservbyname(value)
+ Socket.getservbyname(value.to_s, proto).to_s
end
end
View
5 spec/unit/puppet/type/firewall_spec.rb
@@ -140,6 +140,11 @@
@resource[port].should == ['22','23']
end
+ it "should accept a #{port} as a number" do
+ @resource[port] = 22
+ @resource[port].should == ['22']
+ end
+
it "should accept a #{port} as a hyphen separated range" do
@resource[port] = ['22-1000']
@resource[port].should == ['22-1000']
View
6 spec/unit/puppet/util/firewall_spec.rb
@@ -68,8 +68,10 @@
describe '#string_to_port' do
subject { resource }
- specify { subject.string_to_port('80').should == '80' }
- specify { subject.string_to_port('http').should == '80' }
+ specify { subject.string_to_port('80','tcp').should == '80' }
+ specify { subject.string_to_port(80,'tcp').should == '80' }
+ specify { subject.string_to_port('http','tcp').should == '80' }
+ specify { subject.string_to_port('domain','udp').should == '53' }
end
describe '#to_hex32' do
Please sign in to comment.
Something went wrong with that request. Please try again.