EOS
munge do |value|
- @resource.string_to_port(value)
+ @resource.string_to_port(value, :proto)
end
def is_to_s(value)
EOS
munge do |value|
- @resource.string_to_port(value)
+ @resource.string_to_port(value, :proto)
end
def is_to_s(value)
EOS
munge do |value|
- @resource.string_to_port(value)
+ @resource.string_to_port(value, :proto)
end
def is_to_s(value)
# 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
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)
end
end
@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']
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