Oct 25, 2008

RFuzz: samples

RFuzz: samples: "How’s it used?

RFuzz is really easy to use for just basic HTTP requests and running simple tests. It’s even easier if you follow the REST paradigm.

The following are the examles that come with the gem.
hpricot_pudding.rb

Simple client that lets you search google from the command line. Run it with:

ruby hpricot_pudding.rb 'ruby zed'

and it will return all the results printed out. (requires hpricot)

require 'rubygems' require 'hpricot' require 'rfuzz/session' include RFuzz agent = 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.4) Firefox/1.5.0.4' google = HttpClient.new('www.google.com', 80) r = google.get('/search', :head => {'User-Agent' => agent}, :query => {'q' => ARGV[0], 'hl' => 'en', 'btnG' => 'Google Search'}) if r.http_status != '200' puts 'Wrong Status: #{r.http_status}?' else doc = Hpricot(r.http_body) (doc/:a).each do |link| if link.attributes['class'] == 'l' puts link.attributes['href'] puts ' -- ' + link.children.join end end end

kill_routes.rb

Demonstrates hitting a Ruby on Rails application with randomly generated long and insanely long URIs to see if you can choke the Rails routes system. When running under Mongrel you’ll find that Mongrel’s explicit limit of 512 characters on URIs protects Rails quite well."