Sha256: 9d90f754b41c88faea0124ab1a76c163054f8f7c7df8ebd44cc0d75f805a5a42

Contents?: true

Size: 1.02 KB

Versions: 85

Compression:

Stored size: 1.02 KB

Contents

require 'resolv'

module Serverspec::Type
  class Port < Base
    def protocols
      %w(udp tcp tcp6 udp6)
    end

    def options
      @options ||= {}
    end

    def protocol_matcher(protocol)
      protocol = protocol.to_s.downcase
      if protocols.include?(protocol)
        options[:protocol] = protocol
      else
        raise ArgumentError.new("`be_listening` matcher doesn't support #{protocol}")
      end
    end

    def local_address_matcher(local_address)
      if valid_ip_address?(local_address)
        options[:local_address] = local_address
      else
        raise ArgumentError.new("`be_listening` matcher requires valid IPv4 or IPv6 address")
      end
    end

    def listening?(protocol, local_address)
      protocol_matcher(protocol) if protocol
      local_address_matcher(local_address) if local_address
      @runner.check_port_is_listening(@name, options)
    end

    def valid_ip_address?(ip_address)
      !!(ip_address =~ Resolv::IPv4::Regex) || !!(ip_address =~ Resolv::IPv6::Regex)
    end
  end
end

Version data entries

85 entries across 85 versions & 4 rubygems

Version Path
serverspec-2.42.3 lib/serverspec/type/port.rb
serverspec-2.42.2 lib/serverspec/type/port.rb
serverspec-2.42.1 lib/serverspec/type/port.rb
serverspec-cem-acpt-2.42.0 lib/serverspec/type/port.rb
serverspec-2.42.0 lib/serverspec/type/port.rb
serverspec-2.41.8 lib/serverspec/type/port.rb
serverspec-2.41.7 lib/serverspec/type/port.rb
serverspec-2.41.6 lib/serverspec/type/port.rb
serverspec-2.41.5 lib/serverspec/type/port.rb
serverspec-2.41.4 lib/serverspec/type/port.rb
serverspec-ruby19-2.24.3 lib/serverspec/type/port.rb
serverspec-2.41.3 lib/serverspec/type/port.rb
serverspec-2.41.2 lib/serverspec/type/port.rb
serverspec-2.41.1 lib/serverspec/type/port.rb
serverspec-2.41.0 lib/serverspec/type/port.rb
serverspec-2.40.0 lib/serverspec/type/port.rb
serverspec-2.39.2 lib/serverspec/type/port.rb
serverspec-2.39.1 lib/serverspec/type/port.rb
serverspec-2.39.0 lib/serverspec/type/port.rb
serverspec-2.38.1 lib/serverspec/type/port.rb