owasp_zap 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 12b7b8a9a5e467df211b540b1e37397c2010a3cc
4
- data.tar.gz: 59631214ffc42c20e952f1bc4e0fdf0aa0dda8ca
3
+ metadata.gz: 4b415e6b141e52526caacc96bdcdefb8186a7832
4
+ data.tar.gz: 1dc4d0e67c9f466d731e300c472656cf4f180133
5
5
  SHA512:
6
- metadata.gz: bdd1bcfd595e647f0c78edd838052be844fe10b29f4b4f01d00f4e042f4ff814f87378282bce761b9841fe983b1a2147279d9bf089257722bd0ffb5fae762660
7
- data.tar.gz: a1c5bee92a9674f37c2867127fb64aaa37d4d5266ced72e3dea4400bc9444d548f1540915dca9ffeb9da42b0e43abdf650a0ab527aaec005247b336685deeebc
6
+ metadata.gz: 9fc2f9b1fafb2b78a0d378b06b3e4a4473d0de8c2f4f576b8f9fff97cee535e711c4a8f4e1042e1ad84489cc5868e379268448faf7bb670cec3420298739f1f9
7
+ data.tar.gz: b61ec24d8efc9d1315968263fafe874e115059a9e2c81669eb901f3c30c78540d3ca02a0fa515d48d1bdcfa33e8ddf2f68d2703f2fb517182e583e20e6984769
@@ -11,7 +11,7 @@ module OwaspZap
11
11
  def view(format = "JSON")
12
12
  raise OwaspZap::WrongFormatException,"Output format not accepted" unless ["JSON","HTML","XML"].include?(format)
13
13
  #http://localhost:8080/JSON/core/view/alerts/?zapapiformat=JSON&baseurl=http%3A%2F%2F192.168.1.113&start=&count=
14
- url = Addressable::URI.parse "#{@base}/core/view/alerts/"
14
+ url = Addressable::URI.parse "#{@base}/#{format}/core/view/alerts/"
15
15
  url.query_values = {:zapapiformat=>format,:baseurl=>@target}
16
16
  RestClient::get url.normalize.to_str
17
17
  end
@@ -1,20 +1,29 @@
1
1
  module OwaspZap
2
2
  class Attack
3
3
  def initialize(params = {})
4
- #TODO
5
- #handle it
4
+ # TODO
5
+ # handle it
6
6
  @base = params[:base]
7
7
  @target = params[:target]
8
8
  end
9
9
 
10
10
  def start
11
- url = Addressable::URI.parse "#{@base}/ascan/action/scan/"
11
+ url = Addressable::URI.parse "#{@base}/JSON/ascan/action/scan/"
12
12
  url.query_values = {:zapapiformat=>"JSON",:url=>@target}
13
13
  RestClient::get url.normalize.to_str
14
14
  end
15
15
 
16
16
  def status
17
- JSON.parse RestClient::get("#{@base}/ascan/view/status/?zapapiformat=JSON")
17
+ ret = JSON.parse(RestClient::get("#{@base}/JSON/ascan/view/status/?zapapiformat=JSON"))
18
+ if ret.has_key? "status"
19
+ ret["status"].to_i
20
+ else
21
+ 100 # it means no running
22
+ end
23
+ end
24
+
25
+ def running?
26
+ self.status != 100
18
27
  end
19
28
 
20
29
  end
@@ -10,18 +10,26 @@ module OwaspZap
10
10
 
11
11
  def start
12
12
  #http://localhost:8080/JSON/spider/action/scan/?zapapiformat=JSON&url=
13
- url = Addressable::URI.parse "#{@base}/spider/action/scan/"
13
+ url = Addressable::URI.parse "#{@base}/JSON/spider/action/scan/"
14
14
  url.query_values = {:zapapiformat=>"JSON",:url=>@target}
15
15
  RestClient::get url.normalize.to_str
16
16
  end
17
17
 
18
18
  def stop
19
- RestClient::get "#{@base}/spider/action/stop/?zapapiformat=JSON"
19
+ RestClient::get "#{@base}/JSON/spider/action/stop/?zapapiformat=JSON"
20
20
  end
21
21
 
22
22
  def status
23
- RestClient::get "#{@base}/spider/view/status/?zapapiformat=JSON"
24
- end
23
+ ret = JSON.parse(RestClient::get("#{@base}/JSON/spider/view/status/?zapapiformat=JSON"))
24
+ if ret.has_key? "status"
25
+ ret["status"].to_i
26
+ else
27
+ 100 # it means no running
28
+ end
29
+ end
25
30
 
31
+ def running?
32
+ self.status != 100
33
+ end
26
34
  end
27
35
  end
@@ -1,3 +1,3 @@
1
1
  module OwaspZap
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
data/lib/owasp_zap.rb CHANGED
@@ -20,7 +20,7 @@ module OwaspZap
20
20
  def initialize(params = {})
21
21
  #TODO
22
22
  # handle params
23
- @base = params[:base] || "http://127.0.0.1:8080/JSON"
23
+ @base = params[:base] || "http://127.0.0.1:8080"
24
24
  @target = params[:target]
25
25
  @zap_bin = params [:zap] || "#{ENV['HOME']}/ZAP/zap.sh"
26
26
  end
@@ -83,7 +83,7 @@ module OwaspZap
83
83
 
84
84
  #shutdown zap
85
85
  def shutdown
86
- RestClient::get "#{@base}/core/action/shutdown/"
86
+ RestClient::get "#{@base}/JSON/core/action/shutdown/"
87
87
  end
88
88
 
89
89
  #xml report
data/spec/zap_spec.rb CHANGED
@@ -8,31 +8,32 @@ describe Zap do
8
8
  end
9
9
 
10
10
  it "shouldnt be nil" do
11
- @zap.wont_be :nil?
11
+ @zap.wont_be_nil
12
12
  end
13
13
 
14
14
  it "should have a target" do
15
- @zap.respond_to? :target
15
+ @zap.must_respond_to :target
16
16
  end
17
17
 
18
18
  it "target shouldnt be nil" do
19
- @zap.target.wont_be :nil?
19
+ @zap.target.wont_be_nil
20
20
  end
21
21
 
22
22
  it "should have a base" do
23
- assert_respond_to @zap,:base
23
+ @zap.must_respond_to :base
24
+ #assert_respond_to @zap,:base
24
25
  end
25
26
 
26
27
  it "should have method start" do
27
- assert_respond_to @zap,:start
28
+ @zap.must_respond_to :start
28
29
  end
29
30
 
30
31
  it "should have a method shutdown" do
31
- assert_respond_to @zap,:shutdown
32
+ @zap.must_respond_to :shutdown
32
33
  end
33
34
 
34
35
  it "should respond_to to spider" do
35
- assert_respond_to @zap,:spider
36
+ @zap.must_respond_to :spider
36
37
  end
37
38
 
38
39
  it "should call spider and get a spider object" do
@@ -40,7 +41,7 @@ describe Zap do
40
41
  end
41
42
 
42
43
  it "should respond_to auth" do
43
- assert_respond_to @zap,:auth
44
+ @zap.must_respond_to :auth
44
45
  end
45
46
 
46
47
  it "should call auth and get an auth object" do
@@ -48,7 +49,7 @@ describe Zap do
48
49
  end
49
50
 
50
51
  it "should respond_to ascan" do
51
- assert_respond_to @zap,:ascan
52
+ @zap.must_respond_to :ascan
52
53
  end
53
54
 
54
55
  it "should call ascan and get an attack object" do
@@ -56,7 +57,7 @@ describe Zap do
56
57
  end
57
58
 
58
59
  it "should respond_to alerts" do
59
- assert_respond_to @zap,:alerts
60
+ @zap.must_respond_to :alerts
60
61
  end
61
62
 
62
63
  it "should call alerts and get a alert object" do
@@ -67,8 +68,8 @@ describe Zap do
67
68
  @zap.base.wont_be :nil?
68
69
  end
69
70
 
70
- it "base default should be http://127.0.0.1:8080/JSON" do
71
- assert_equal @zap.base, "http://127.0.0.1:8080/JSON"
71
+ it "base default should be http://127.0.0.1:8080" do
72
+ assert_equal @zap.base, "http://127.0.0.1:8080"
72
73
  end
73
74
  end
74
75
 
@@ -86,7 +87,7 @@ describe "method shutdown" do
86
87
  end
87
88
 
88
89
  it "should receive a json as answer" do
89
- @h.shutdown.wont_be :nil?
90
+ @h.shutdown.wont_be_nil
90
91
  end
91
92
  it "should request the shutdown url" do
92
93
  @h.shutdown
@@ -99,14 +100,14 @@ describe "StringExtension" do
99
100
  it "should not respond_to camel_case and snake_case" do
100
101
  @str = ""
101
102
  [:camel_case,:snake_case].each do |m|
102
- refute_respond_to(@str,m)
103
+ @str.wont_respond_to m
103
104
  end
104
105
  end
105
106
  it "should respond_to camel_case and snake_case" do
106
107
  @str = ""
107
108
  @str.extend Zap::StringExtension
108
109
  [:camel_case,:snake_case].each do |m|
109
- assert_respond_to @str,m
110
+ @str.must_respond_to m
110
111
  end
111
112
  end
112
113
  it "should answer to camel_case" do
@@ -129,12 +130,33 @@ describe "status_for" do
129
130
  end
130
131
 
131
132
  it "should create a ascan" do
132
- @h.status_for(:ascan).wont_be :nil?
133
+ @h.status_for(:ascan).wont_be_nil
133
134
  end
134
135
  it "should create a spider" do
135
- @h.status_for(:spider).wont_be :nil?
136
+ @h.status_for(:spider).wont_be_nil
136
137
  end
137
138
  it "should return an unknown" do
138
- @h.status_for(:foo).wont_be :nil?
139
+ @h.status_for(:foo).wont_be_nil
140
+ end
141
+
142
+ it "should return an integer" do
143
+ @h.spider.status.must_be_kind_of Numeric
144
+ end
145
+ it "should return an integer" do
146
+ @h.spider.status.must_be_kind_of Numeric
139
147
  end
140
148
  end
149
+
150
+ describe "running? method" do
151
+ before do
152
+ @h = Zap::Zap.new :target=>"http://127.0.0.1"
153
+ 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 => {})
154
+ 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 => {})
155
+ end
156
+ it "should return true" do
157
+ @h.spider.running?.must_equal true
158
+ end
159
+ it "should return false" do
160
+ @h.ascan.running?.must_equal false
161
+ end
162
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: owasp_zap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Pereira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-13 00:00:00.000000000 Z
11
+ date: 2014-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler