Sha256: c468aac57f56b9404f311cec2da71920af3c9e58ffaca028ca844abf76ce6f8e

Contents?: true

Size: 1.33 KB

Versions: 46

Compression:

Stored size: 1.33 KB

Contents

module FWToolkit
  module Test
    module NetworkHelpers

      #Given /^the network simulates a 3G connection
      #ipfw add pipe 1 all from any to any out 
      #ipfw add pipe 2 all from any to any in 
      #ipfw pipe 1 config bw 64Kbit/s 
      #ipfw pipe 2 config bw 128Kbit/s
    
      def ipfw_reset_rule_number
        @@ipfw_rule_number = 1
      end
    
      def ipfw_exit_unless_clean
        ipfw_list = `sudo ipfw list`
        if ipfw_list =~ /^(?!65535 allow ip from any to any$).*/
          puts 'The firewall table contains rules other than the default. Run `sudo ipfw flush` before rerunning cucumber if you don\'t need these rules.'
          exit -1
        end
      end
    
      def ipfw_deny(host='localhost')
        `sudo ipfw add #{@@ipfw_rule_number} deny tcp from any to #{host}`
        @@ipfw_rule_number += 1
      end
    
      def ipfw_flush
        `sudo ipfw flush`
      end
    end
  end
end
World(FWToolkit::Test::NetworkHelpers)

# Check IPFW because we flush firewall rules at the end of each scenario
# If we have anything but the default rule, warn the user and exit
Before do
  ipfw_exit_unless_clean
  ipfw_reset_rule_number
end

After do
  ipfw_flush
end

#
# Steps
#
Given /^the network has no connection$/ do
  ipfw_deny
end

Then /^the network is returned to its original state$/ do
  ipfw_flush
end




Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
fwtoolkit-0.9.3 lib/fwtoolkit/test/network_steps.rb
fwtoolkit-0.9.2 lib/fwtoolkit/test/network_steps.rb
fwtoolkit-0.9.1 lib/fwtoolkit/test/network_steps.rb
fwtoolkit-0.9.0 lib/fwtoolkit/test/network_steps.rb
fwtoolkit-0.8.7 lib/fwtoolkit/test/network_steps.rb
fwtoolkit-0.8.6 lib/fwtoolkit/test/network_steps.rb
fwtoolkit-0.8.5 lib/fwtoolkit/test/network_steps.rb
fwtoolkit-0.8.4 lib/fwtoolkit/test/network_steps.rb
fwtoolkit-0.8.3 lib/fwtoolkit/test/network_steps.rb
fwtoolkit-0.8.2 lib/fwtoolkit/test/network_steps.rb
fwtoolkit-0.8.1 lib/fwtoolkit/test/network_steps.rb
fwtoolkit-0.8.0 lib/fwtoolkit/test/network_steps.rb
fwtoolkit-0.7.3 lib/fwtoolkit/test/network_steps.rb
fwtoolkit-0.7.2 lib/fwtoolkit/test/network_steps.rb
fwtoolkit-0.7.1 lib/fwtoolkit/test/network_steps.rb
fwtoolkit-0.7.0 lib/fwtoolkit/test/network_steps.rb
fwtoolkit-0.6.6 lib/fwtoolkit/test/network_steps.rb
fwtoolkit-0.6.5 lib/fwtoolkit/test/network_steps.rb
fwtoolkit-0.6.4 lib/fwtoolkit/test/network_steps.rb
fwtoolkit-0.6.3 lib/fwtoolkit/test/network_steps.rb