lib/specinfra/command/module/ss.rb in specinfra-2.76.7 vs lib/specinfra/command/module/ss.rb in specinfra-2.76.8
- old
+ new
@@ -1,25 +1,29 @@
module Specinfra
module Command
module Module
module Ss
def check_is_listening(port, options={})
- pattern = ":#{port} "
- pattern = " #{inaddr_any_to_asterisk(options[:local_address])}#{pattern}" if options[:local_address]
- "ss #{command_options(options[:protocol])} | grep -- #{escape(pattern)}"
+ if options[:local_address]
+ pattern = inaddr_any_to_asterisk(options[:local_address]).map { |l| " #{l}:#{port} " }
+ pattern = pattern.join('|')
+ else
+ pattern = ":#{port} "
+ end
+ "ss #{command_options(options[:protocol])} | grep -E -- #{escape(pattern)}"
end
private
# WORKAROUND:
- # ss displays "*" instead of "0.0.0.0".
+ # Older ss versions display "*" instead of "0.0.0.0".
# But serverspec validates IP address by `valid_ip_address?` method:
# https://github.com/serverspec/serverspec/blob/master/lib/serverspec/type/port.rb
def inaddr_any_to_asterisk(local_address)
if local_address == '0.0.0.0'
- '\*'
+ [ '\*' , '0\.0\.0\.0' ]
else
- local_address
+ [ local_address ]
end
end
def command_options(protocol)
case protocol.to_s