Sha256: d01edf78fb5ecc9a1df0e48d8f357464faf4116059f38eab6af7fe7981ac51b3

Contents?: true

Size: 724 Bytes

Versions: 3

Compression:

Stored size: 724 Bytes

Contents

require 'serverspec'
require 'serverspec/type/base'

module Serverspec::Type
  class WindowsFirewall < Base

    def initialize
      @runner = Specinfra::Runner
    end

    def has_open_port?(port)
      command_result = @runner.run_command("((New-Object -comObject HNetCfg.FwPolicy2).rules | where-object { $_.LocalPorts -eq #{port} -and $_.Action -eq 1}).Enabled")
      command_result.stdout.gsub(/\n/, '') == "True"
    end

    def enabled?
      command_result = @runner.run_command("(get-service MpsSvc).Status")
      command_result.stdout.gsub(/\n/, '') == "Running"
    end

    def to_s
      "Windows Firewall"
    end

  end

  def windows_firewall
    WindowsFirewall.new
  end
end

include Serverspec::Type

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
octopus-serverspec-extensions-0.19.1 lib/octopus_serverspec_extensions/type/windows_firewall.rb
octopus-serverspec-extensions-0.19.0 lib/octopus_serverspec_extensions/type/windows_firewall.rb
octopus-serverspec-extensions-0.14.0 lib/octopus_serverspec_extensions/type/windows_firewall.rb