spec/relevance/tarantula/form_submission_spec.rb in codez-tarantula-0.5.3 vs spec/relevance/tarantula/form_submission_spec.rb in codez-tarantula-0.5.4

- old
+ new

@@ -1,9 +1,9 @@ require "spec_helper" describe Relevance::Tarantula::FormSubmission do - + describe "with a good form" do # TODO: add more from field types to this example form as needed before do @tag = Hpricot(%q{ <form action="/session" method="post"> @@ -12,11 +12,11 @@ <input name="commit" type="submit" value="Postit" /> <input name="secret" type="hidden" value="secret" /> <select id="foo_opened_on_1i" name="foo[opened_on(1i)]"> <option value="2003">2003</option> <option value="2004">2004</option> - </select> + </select> </form> }) end describe "crawl" do @@ -27,71 +27,71 @@ response = form.crawl response.code.should == "404" response.content_type.should == "text/plain" response.body.should == "ActiveRecord::RecordNotFound" end - + it "submits the form and logs response" do doc = Hpricot('<form action="/action" method="post"/>') form = make_form(doc.at('form')) fs = Relevance::Tarantula::FormSubmission.new(form) form.crawler.expects(:submit).returns(stub(:code => "200")) fs.expects(:log).with("Response 200 for #{fs}") fs.crawl end - + end describe "with default attack" do before do @form = make_form(@tag.at('form')) @fs = Relevance::Tarantula::FormSubmission.new(@form) end - + it "can mutate text areas" do @fs.attack.stubs(:random_int).returns("42") @fs.mutate_text_areas(@form).should == {"comment" => "42"} end - + it "can mutate selects" do Hpricot::Elements.any_instance.stubs(:sample).returns(stub(:[] => "2006-stub")) @fs.mutate_selects(@form).should == {"foo[opened_on(1i)]" => "2006-stub"} end - + it "can mutate inputs" do @fs.attack.stubs(:random_int).returns("43") - @fs.mutate_inputs(@form).should == {"commit"=>"43", "secret"=>"43", "email"=>"43"} + @fs.mutate_inputs(@form).should == {"commit"=>"43", "secret"=>"secret", "email"=>"43"} end it "has a signature based on action and fields" do @fs.signature.should == ['/session', [ - "comment", - "commit", - "email", - "foo[opened_on(1i)]", + "comment", + "commit", + "email", + "foo[opened_on(1i)]", "secret"], @fs.attack.name] end - + it "has a friendly to_s" do @fs.to_s.should =~ %r{^/session post} end end - + describe "with a custom attack" do before do @form = make_form(@tag.at('form')) - @attack = Relevance::Tarantula::Attack.new(:name => 'foo_name', - :input => 'foo_code', + @attack = Relevance::Tarantula::Attack.new(:name => 'foo_name', + :input => 'foo_code', :output => 'foo_code') @fs = Relevance::Tarantula::FormSubmission.new(@form, @attack) end - + it "can mutate text areas" do @fs.mutate_text_areas(@form).should == {"comment" => "foo_code"} end - + it "can mutate selects" do Hpricot::Elements.any_instance.stubs(:sample).returns(stub(:[] => "2006-stub")) @fs.mutate_selects(@form).should == {"foo[opened_on(1i)]" => "2006-stub"} end @@ -99,14 +99,14 @@ @fs.mutate_inputs(@form).should == {"commit"=>"foo_code", "secret"=>"foo_code", "email"=>"foo_code"} end it "has a signature based on action, fields, and attack name" do @fs.signature.should == ['/session', [ - "comment", - "commit", - "email", - "foo[opened_on(1i)]", + "comment", + "commit", + "email", + "foo[opened_on(1i)]", "secret"], "foo_name" ] end @@ -132,20 +132,20 @@ Relevance::Tarantula::FormSubmission.instance_variable_set("@attacks", saved_attacks) end end end end - + describe "with a crummy form" do before do @tag = Hpricot(%q{ <form action="/session" method="post"> <input value="no_name" /> </form> }) end - + describe "with default attack" do before do @form = make_form(@tag.at('form')) @fs = Relevance::Tarantula::FormSubmission.new(@form) end @@ -165,7 +165,7 @@ @fs.mutate_inputs(@form).should == {} end end end - + end