openvas 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb71da56ded8ee0e5088b370c2e91e678b08f9b5
4
- data.tar.gz: e2e8f389b26fd9ec3bb338a4cde7145afc604d0e
3
+ metadata.gz: 6094b62731b5348bd12957817944e7cefa4f1374
4
+ data.tar.gz: e3f959afb305df9725ea3dada3dd123e4831dcf3
5
5
  SHA512:
6
- metadata.gz: e735cf653b828edbfdbb41627bf93b9a31d78b5c15949d7d048cbeb936063aee4ad77b7ff4e777dbe7e3f9462d0ded58a82eb7038c5b76a5b55b01d87df83e13
7
- data.tar.gz: 72cf0814aaca8fed228ce66a9a27460b312d4c8e8e0aec7dc364f1c8de393cc5481440fac3bc4e57ff5147a8bcac8e2aa3d2f860d217e9f48094b769b490c91e
6
+ metadata.gz: 94c12bb0387ca5ed328b63ec98a006264ccdee4c999b7d53314d4f07071f11d02d2f4795ab755183454ef7635f877011f3d6a472e0667c0a4eeb5ae413addfcf
7
+ data.tar.gz: 1268415590f0b935765e500605458b3bd878f18c851e6db4ca37d47119309585a0377dea851c9f7191f8bc9dc42c8971d8dd15aa07c95982c49e6f3ecde1fa62
data/.rubocop.yml CHANGED
@@ -6,8 +6,12 @@ AllCops:
6
6
  Metrics/LineLength:
7
7
  Max: 120
8
8
 
9
+ Metrics/BlockLength:
10
+ Exclude:
11
+ - 'spec/**/*'
12
+
9
13
  Metrics/MethodLength:
10
14
  Max: 30
11
15
 
12
16
  Metrics/AbcSize:
13
- Max: 30
17
+ Max: 30
data/.rubocop_todo.yml CHANGED
@@ -21,8 +21,6 @@ Style/Documentation:
21
21
  - 'lib/openvas/client.rb'
22
22
  - 'lib/openvas/config.rb'
23
23
  - 'lib/openvas/reports.rb'
24
- - 'lib/openvas/results.rb'
25
- - 'lib/openvas/scans.rb'
26
24
 
27
25
  # Offense count: 2
28
26
  # Cop supports --auto-correct.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- openvas (0.2.0)
4
+ openvas (0.3.0)
5
5
  nokogiri (~> 1.8)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -46,7 +46,7 @@ Openvas::Auth.login
46
46
  - Retrive all scans and list the results
47
47
 
48
48
  ```ruby
49
- Openvas::Scans.all.each do |scan|
49
+ Openvas::Scan.all.each do |scan|
50
50
  puts 'Scan Name : ' + scan.name
51
51
  puts '-'*40
52
52
  scan.last_results.each do |result|
@@ -31,7 +31,7 @@ module Openvas
31
31
  end
32
32
 
33
33
  def results
34
- Openvas::Results.find_by_report_id(@id)
34
+ Openvas::Result.find_by_report_id(@id)
35
35
  end
36
36
  end
37
37
  end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'time'
4
+
5
+ module Openvas
6
+ # Class used to interact with OpenVAS' scans results
7
+ class Result
8
+ attr_accessor :id, :name, :comment, :description, :host, :user, :port, :severity, :created_at, :updated_at
9
+
10
+ def initialize(result)
11
+ @id = result.at_xpath('@id').value
12
+ @name = result.at_xpath('name').text
13
+ @comment = result.at_xpath('comment').text
14
+ @user = result.at_xpath('owner/name').text
15
+ @host = result.at_xpath('host').text
16
+ @port = result.at_xpath('port').text
17
+ @severity = result.at_xpath('severity').text
18
+ @description = result.at_xpath('description').text
19
+
20
+ @created_at = Time.parse(result.at_xpath('creation_time').text)
21
+ @updated_at = Time.parse(result.at_xpath('modification_time').text)
22
+ end
23
+
24
+ def results
25
+ Openvas::Result.find_by_report_id(@id)
26
+ end
27
+
28
+ class << self
29
+ MAX_RESULTS = 1000
30
+
31
+ def all
32
+ # TODO: implement pagination
33
+ query = Nokogiri::XML::Builder.new { get_results(filter: "first=1 rows=#{MAX_RESULTS}") }
34
+
35
+ query(query).xpath('//get_results_response/result').map do |result|
36
+ new(result)
37
+ end
38
+ end
39
+
40
+ def find_by_id(id)
41
+ query = Nokogiri::XML::Builder.new { get_results(result_id: id) }
42
+ new(query(query).at_xpath('//get_results_response/result'))
43
+ end
44
+
45
+ def find_by_report_id(id)
46
+ # TODO: implement pagination
47
+ query = Nokogiri::XML::Builder.new { get_results(filter: "report_id=#{id} first=1 rows=#{MAX_RESULTS}") }
48
+
49
+ query(query).xpath('//get_results_response/result').map do |result|
50
+ new(result)
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -3,21 +3,8 @@
3
3
  require 'time'
4
4
 
5
5
  module Openvas
6
- class Scans < Client
7
- def self.all
8
- query = Nokogiri::XML::Builder.new { get_tasks }
9
- query(query).xpath('//get_tasks_response/task').map do |scan|
10
- Openvas::Scan.new(scan)
11
- end
12
- end
13
-
14
- def self.find_by_id(id)
15
- query = Nokogiri::XML::Builder.new { get_tasks(task_id: id) }
16
- Openvas::Scan.new(query(query).at_xpath('//get_tasks_response/task'))
17
- end
18
- end
19
-
20
- class Scan
6
+ # Class used to interact with OpenVAS' scans
7
+ class Scan < Client
21
8
  attr_accessor :id, :name, :comment, :status, :target, :user, :created_at, :updated_at
22
9
 
23
10
  def initialize(scan)
@@ -40,13 +27,26 @@ module Openvas
40
27
  end
41
28
 
42
29
  def last_results
43
- Openvas::Results.find_by_report_id(@last_report_id)
30
+ Openvas::Result.find_by_report_id(@last_report_id)
44
31
  end
45
32
 
46
33
  def finished?
47
- return true if @status.eql? 'Done'
34
+ @status == 'Done'
35
+ end
36
+
37
+ class << self
38
+ def all
39
+ data = Nokogiri::XML::Builder.new { get_tasks }
48
40
 
49
- false
41
+ query(data).xpath('//get_tasks_response/task').map do |scan|
42
+ new(scan)
43
+ end
44
+ end
45
+
46
+ def find_by_id(id)
47
+ data = Nokogiri::XML::Builder.new { get_tasks(task_id: id) }
48
+ new(query(data).at_xpath('//get_tasks_response/task'))
49
+ end
50
50
  end
51
51
  end
52
52
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Openvas
4
- VERSION = '0.2.1'
4
+ VERSION = '0.3.0'
5
5
  end
data/lib/openvas.rb CHANGED
@@ -6,9 +6,9 @@ require 'openvas/config'
6
6
  require 'openvas/client'
7
7
  require 'openvas/auth'
8
8
 
9
- require 'openvas/scans'
9
+ require 'openvas/scan'
10
10
  require 'openvas/reports'
11
- require 'openvas/results'
11
+ require 'openvas/result'
12
12
 
13
13
  module Openvas
14
14
  extend self
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Openvas::Scan do
6
+ let(:scan) { Openvas::Scan.find_by_id('96625625-8e22-4b1c-9c65-4ddf80f78d20') }
7
+
8
+ describe '.all' do
9
+ before { allow(Openvas::Scan).to receive(:query).and_return(fixture_xml('openvas/scans/all.xml')) }
10
+
11
+ it 'list scans' do
12
+ expect(Openvas::Scan.all.count).to eq 2
13
+ end
14
+ end
15
+
16
+ describe '.find_by_id' do
17
+ before { allow(Openvas::Scan).to receive(:query).and_return(fixture_xml('openvas/scans/find_by_id.xml')) }
18
+
19
+ it 'returns an Openvas::Scan object' do
20
+ expect(scan).to be_a(Openvas::Scan)
21
+ end
22
+
23
+ it 'retrieves the scan\'s id' do
24
+ expect(scan.id).to eq '96625625-8e22-4b1c-9c65-4ddf80f78d20'
25
+ end
26
+
27
+ it 'retrieves the scan\'s name' do
28
+ expect(scan.name).to eq 'shellshock_01'
29
+ end
30
+
31
+ it 'retrieves the scan\'s comment' do
32
+ expect(scan.comment).to be_empty
33
+ end
34
+
35
+ it 'retrieves the scan\'s user' do
36
+ expect(scan.user).to eq 'admin'
37
+ end
38
+
39
+ it 'retrieves the scan\'s status' do
40
+ expect(scan.status).to eq 'Done'
41
+ end
42
+
43
+ it 'retrieves the scan\'s creation date' do
44
+ expect(scan.created_at.to_s).to eq '2017-12-11 16:40:16 UTC'
45
+ end
46
+
47
+ it 'retrieves the scan\'s modification date' do
48
+ expect(scan.updated_at.to_s).to eq '2017-12-12 08:13:44 UTC'
49
+ end
50
+ end
51
+
52
+ describe '#finished?' do
53
+ before { allow(Openvas::Scan).to receive(:query).and_return(fixture_xml('openvas/scans/find_by_id.xml')) }
54
+
55
+ context 'when the status is Done' do
56
+ before { scan.status = 'Done' }
57
+
58
+ it 'returns true' do
59
+ expect(scan.finished?).to be_truthy
60
+ end
61
+ end
62
+
63
+ context 'when the status is not Done' do
64
+ before { scan.status = 'Running' }
65
+
66
+ it 'returns false' do
67
+ expect(scan.finished?).to be_falsey
68
+ end
69
+ end
70
+ end
71
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openvas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Wininger
@@ -101,8 +101,8 @@ files:
101
101
  - lib/openvas/client.rb
102
102
  - lib/openvas/config.rb
103
103
  - lib/openvas/reports.rb
104
- - lib/openvas/results.rb
105
- - lib/openvas/scans.rb
104
+ - lib/openvas/result.rb
105
+ - lib/openvas/scan.rb
106
106
  - lib/openvas/version.rb
107
107
  - openvas.gemspec
108
108
  - spec/fixtures/openvas/client/version.xml
@@ -110,7 +110,7 @@ files:
110
110
  - spec/fixtures/openvas/scans/find_by_id.xml
111
111
  - spec/openvas/auth_spec.rb
112
112
  - spec/openvas/client_spec.rb
113
- - spec/openvas/scans_spec.rb
113
+ - spec/openvas/scan_spec.rb
114
114
  - spec/openvas_spec.rb
115
115
  - spec/spec_helper.rb
116
116
  homepage: https://github.com/Cyberwatch/ruby-openvas
@@ -143,6 +143,6 @@ test_files:
143
143
  - spec/fixtures/openvas/scans/find_by_id.xml
144
144
  - spec/openvas/auth_spec.rb
145
145
  - spec/openvas/client_spec.rb
146
- - spec/openvas/scans_spec.rb
146
+ - spec/openvas/scan_spec.rb
147
147
  - spec/openvas_spec.rb
148
148
  - spec/spec_helper.rb
@@ -1,53 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'time'
4
-
5
- module Openvas
6
- class Results < Client
7
- MAX_RESULTS = 1000
8
-
9
- def self.all
10
- # TODO: implement pagination
11
- query = Nokogiri::XML::Builder.new { get_results(filter: "first=1 rows=#{MAX_RESULTS}") }
12
- query(query).xpath('//get_results_response/result').map do |result|
13
- Openvas::Result.new(result)
14
- end
15
- end
16
-
17
- def self.find_by_id(id)
18
- query = Nokogiri::XML::Builder.new { get_results(result_id: id) }
19
- Openvas::Result.new(query(query).at_xpath('//get_results_response/result'))
20
- end
21
-
22
- def self.find_by_report_id(id)
23
- # TODO: implement pagination
24
- query = Nokogiri::XML::Builder.new { get_results(filter: "report_id=#{id} first=1 rows=#{MAX_RESULTS}") }
25
-
26
- query(query).xpath('//get_results_response/result').map do |result|
27
- Openvas::Result.new(result)
28
- end
29
- end
30
- end
31
-
32
- class Result
33
- attr_accessor :id, :name, :comment, :description, :host, :user, :port, :severity, :created_at, :updated_at
34
-
35
- def initialize(result)
36
- @id = result.at_xpath('@id').value
37
- @name = result.at_xpath('name').text
38
- @comment = result.at_xpath('comment').text
39
- @user = result.at_xpath('owner/name').text
40
- @host = result.at_xpath('host').text
41
- @port = result.at_xpath('port').text
42
- @severity = result.at_xpath('severity').text
43
- @description = result.at_xpath('description').text
44
-
45
- @created_at = Time.parse(result.at_xpath('creation_time').text)
46
- @updated_at = Time.parse(result.at_xpath('modification_time').text)
47
- end
48
-
49
- def results
50
- Openvas::Results.find_by_report_id(@id)
51
- end
52
- end
53
- end
@@ -1,61 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Openvas::Scans do
6
- describe '#all' do
7
- before(:each) do
8
- allow(Openvas::Scans).to receive(:query).and_return(fixture_xml('openvas/scans/all.xml'))
9
- end
10
-
11
- it 'list scans' do
12
- expect(Openvas::Scans.all.count).to eq 2
13
- end
14
- end
15
-
16
- describe '#find_by_id' do
17
- before(:each) do
18
- allow(Openvas::Scans).to receive(:query).and_return(fixture_xml('openvas/scans/find_by_id.xml'))
19
- end
20
-
21
- it 'get the version' do
22
- expect(Openvas::Scans.find_by_id('96625625-8e22-4b1c-9c65-4ddf80f78d20')).to be_a(Openvas::Scan)
23
- end
24
-
25
- context 'scan' do
26
- let(:scan) { Openvas::Scans.find_by_id('96625625-8e22-4b1c-9c65-4ddf80f78d20') }
27
-
28
- it '#id' do
29
- expect(scan.id).to eq '96625625-8e22-4b1c-9c65-4ddf80f78d20'
30
- end
31
-
32
- it '#name' do
33
- expect(scan.name).to eq 'shellshock_01'
34
- end
35
-
36
- it '#comment' do
37
- expect(scan.comment).to eq ''
38
- end
39
-
40
- it '#user' do
41
- expect(scan.user).to eq 'admin'
42
- end
43
-
44
- it '#status' do
45
- expect(scan.status).to eq 'Done'
46
- end
47
-
48
- it '#finished' do
49
- expect(scan.finished?).to be_truthy
50
- end
51
-
52
- it '#created_at' do
53
- expect(scan.created_at.to_s).to eq '2017-12-11 16:40:16 UTC'
54
- end
55
-
56
- it '#updated_at' do
57
- expect(scan.updated_at.to_s).to eq '2017-12-12 08:13:44 UTC'
58
- end
59
- end
60
- end
61
- end