spec/zap_spec.rb in owasp_zap-0.0.8 vs spec/zap_spec.rb in owasp_zap-0.0.9
- old
+ new
@@ -6,71 +6,72 @@
before do
@zap = Zap.new(:target=>'http://127.0.0.1')
end
it "shouldnt be nil" do
- @zap.wont_be :nil?
+ @zap.wont_be_nil
end
it "should have a target" do
- @zap.respond_to? :target
+ @zap.must_respond_to :target
end
it "target shouldnt be nil" do
- @zap.target.wont_be :nil?
+ @zap.target.wont_be_nil
end
it "should have a base" do
- assert_respond_to @zap,:base
+ @zap.must_respond_to :base
+ #assert_respond_to @zap,:base
end
it "should have method start" do
- assert_respond_to @zap,:start
+ @zap.must_respond_to :start
end
it "should have a method shutdown" do
- assert_respond_to @zap,:shutdown
+ @zap.must_respond_to :shutdown
end
it "should respond_to to spider" do
- assert_respond_to @zap,:spider
+ @zap.must_respond_to :spider
end
it "should call spider and get a spider object" do
assert_equal @zap.spider.class,Zap::Spider
end
it "should respond_to auth" do
- assert_respond_to @zap,:auth
+ @zap.must_respond_to :auth
end
it "should call auth and get an auth object" do
assert_equal @zap.auth.class, Zap::Auth
end
it "should respond_to ascan" do
- assert_respond_to @zap,:ascan
+ @zap.must_respond_to :ascan
end
it "should call ascan and get an attack object" do
assert_equal @zap.ascan.class, Zap::Attack
end
it "should respond_to alerts" do
- assert_respond_to @zap,:alerts
+ @zap.must_respond_to :alerts
end
it "should call alerts and get a alert object" do
assert_equal @zap.alerts.class,Zap::Alert
end
it "base shouldnt be nil" do
@zap.base.wont_be :nil?
end
- it "base default should be http://127.0.0.1:8080/JSON" do
- assert_equal @zap.base, "http://127.0.0.1:8080/JSON"
+ it "base default should be http://127.0.0.1:8080" do
+ assert_equal @zap.base, "http://127.0.0.1:8080"
end
end
describe "changing default params" do
it "should be able to set base" do
@@ -84,11 +85,11 @@
@h = Zap::Zap.new :target=>"http://127.0.0.1"
stub_request(:get, "http://127.0.0.1:8080/JSON/core/action/shutdown/").to_return(:status => 200, :body => "{\"Result\":\"OK\"}" , :headers => {})
end
it "should receive a json as answer" do
- @h.shutdown.wont_be :nil?
+ @h.shutdown.wont_be_nil
end
it "should request the shutdown url" do
@h.shutdown
assert_requested :get,"http://127.0.0.1:8080/JSON/core/action/shutdown/"
end
@@ -97,18 +98,18 @@
describe "StringExtension" do
it "should not respond_to camel_case and snake_case" do
@str = ""
[:camel_case,:snake_case].each do |m|
- refute_respond_to(@str,m)
+ @str.wont_respond_to m
end
end
it "should respond_to camel_case and snake_case" do
@str = ""
@str.extend Zap::StringExtension
[:camel_case,:snake_case].each do |m|
- assert_respond_to @str,m
+ @str.must_respond_to m
end
end
it "should answer to camel_case" do
@str = "foo_bar"
@str.extend Zap::StringExtension
@@ -127,14 +128,35 @@
stub_request(:get, "http://127.0.0.1:8080/JSON/spider/view/status/?zapapiformat=JSON").to_return(:status => 200, :body => {:status=>"100"}.to_json, :headers => {})
stub_request(:get, "http://127.0.0.1:8080/JSON/ascan/view/status/?zapapiformat=JSON").to_return(:status => 200, :body => {:status=>"100"}.to_json, :headers => {})
end
it "should create a ascan" do
- @h.status_for(:ascan).wont_be :nil?
+ @h.status_for(:ascan).wont_be_nil
end
it "should create a spider" do
- @h.status_for(:spider).wont_be :nil?
+ @h.status_for(:spider).wont_be_nil
end
it "should return an unknown" do
- @h.status_for(:foo).wont_be :nil?
+ @h.status_for(:foo).wont_be_nil
end
+
+ it "should return an integer" do
+ @h.spider.status.must_be_kind_of Numeric
+ end
+ it "should return an integer" do
+ @h.spider.status.must_be_kind_of Numeric
+ end
end
+
+describe "running? method" do
+ before do
+ @h = Zap::Zap.new :target=>"http://127.0.0.1"
+ stub_request(:get, "http://127.0.0.1:8080/JSON/spider/view/status/?zapapiformat=JSON").to_return(:status => 200, :body => {:status=>"90"}.to_json, :headers => {})
+ stub_request(:get, "http://127.0.0.1:8080/JSON/ascan/view/status/?zapapiformat=JSON").to_return(:status => 200, :body => {:status=>"100"}.to_json, :headers => {})
+ end
+ it "should return true" do
+ @h.spider.running?.must_equal true
+ end
+ it "should return false" do
+ @h.ascan.running?.must_equal false
+ end
+end