spec/arachni/spider_spec.rb in arachni-0.4.2 vs spec/arachni/spider_spec.rb in arachni-0.4.3
- old
+ new
@@ -1,22 +1,22 @@
-require_relative '../spec_helper'
+require 'spec_helper'
describe Arachni::Spider do
before( :all ) do
@opts = Arachni::Options.instance
- @opts.url = server_url_for :spider
+ @opts.url = web_server_url_for :spider
@url = @opts.url.to_s
end
before( :each ) do
reset_options
@opts.url = @url
Arachni::HTTP.instance.reset
end
it 'supports HTTPS' do
- @opts.url = (server_url_for :spider_https).gsub( 'http', 'https' )
+ @opts.url = (web_server_url_for :spider_https).gsub( 'http', 'https' )
spider = Arachni::Spider.new
spider.run.size.should == 3
spider.redirects.size.should == 2
end
@@ -220,10 +220,21 @@
Arachni::Spider.new.run.size.should == 11
end
end
end
context 'when the link-count-limit option has been set' do
+ context 'and the limit has been reached' do
+ it 'immediately returns' do
+ @opts.link_count_limit = 1
+ spider = Arachni::Spider.new
+ spider.run.should == spider.sitemap
+ spider.sitemap.should == [@url]
+
+ spider.run.should be_false
+ end
+ end
+
it 'follows only a <link-count-limit> amount of paths' do
@opts.link_count_limit = 1
spider = Arachni::Spider.new
spider.run.should == spider.sitemap
spider.sitemap.should == [@url]
@@ -379,11 +390,11 @@
s.paths.include?( path ).should be_false
s.sitemap.include?( path ).should be_true
s = Arachni::Spider.new
paths = [@url + 'a_pushed_path', @url + 'another_pushed_path']
- s.push( paths )
+ s.push( paths ).should be_true
(s.paths & paths).sort.should == paths.sort
s.run
(s.paths & paths).should be_empty
(s.sitemap & paths).sort.should == paths.sort
end
@@ -394,16 +405,29 @@
wp = 'another weird path %"&*[$)'
nwp = Arachni::Module::Utilities.to_absolute( wp )
np = Arachni::Module::Utilities.to_absolute( p )
- s.push( p )
+ s.push( p ).should be_true
s.run
s.fancy_sitemap[np].should == 200
s.fancy_sitemap[nwp].should == 200
end
+ context 'when the link-count-limit option has been set' do
+ context 'and the limit has been reached' do
+ it 'immediately returns' do
+ @opts.link_count_limit = 1
+ spider = Arachni::Spider.new
+ spider.run.should == spider.sitemap
+ spider.sitemap.should == [@url]
+
+ spider.push( Arachni::Module::Utilities.to_absolute( 'test' ) ).should be_false
+ end
+ end
+ end
+
#context 'when called after the crawl has finished' do
# it 'should wake the crawler up after pushing the new paths' do
# s = Arachni::Spider.new
# s.run
# s.done?.should be_true
@@ -443,10 +467,10 @@
s.running?.should be_false
end
end
context 'when running' do
it 'returns false' do
- @opts.url = server_url_for( :auditor ) + '/sleep'
+ @opts.url = web_server_url_for( :auditor ) + '/sleep'
s = Arachni::Spider.new
Thread.new{ s.run }
sleep 1
s.running?.should be_true
end