openvas-cli 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/Gemfile +2 -0
  2. data/Gemfile.lock +50 -0
  3. data/VERSION +1 -1
  4. data/lib/openvas-cli/configuration.rb +25 -0
  5. data/lib/openvas-cli/conn_addin.rb +27 -0
  6. data/lib/openvas-cli/immutable_children_validator.rb +15 -0
  7. data/lib/openvas-cli/vas_administrator.rb +7 -0
  8. data/lib/openvas-cli/vas_base.rb +20 -30
  9. data/lib/openvas-cli/vas_config.rb +127 -0
  10. data/lib/openvas-cli/vas_connection.rb +140 -0
  11. data/lib/openvas-cli/vas_exceptions.rb +9 -7
  12. data/lib/openvas-cli/vas_lsc_credential.rb +110 -0
  13. data/lib/openvas-cli/vas_nvt.rb +64 -64
  14. data/lib/openvas-cli/vas_nvt_family.rb +39 -30
  15. data/lib/openvas-cli/vas_override.rb +6 -4
  16. data/lib/openvas-cli/vas_period.rb +89 -0
  17. data/lib/openvas-cli/vas_preference.rb +139 -49
  18. data/lib/openvas-cli/vas_report.rb +110 -103
  19. data/lib/openvas-cli/vas_result.rb +90 -89
  20. data/lib/openvas-cli/vas_schedule.rb +163 -55
  21. data/lib/openvas-cli/vas_target.rb +200 -23
  22. data/lib/openvas-cli/vas_task.rb +229 -30
  23. data/lib/openvas-cli/vas_task_progress.rb +29 -0
  24. data/lib/openvas-cli/xml_addin.rb +34 -0
  25. data/lib/openvas_cli.rb +19 -0
  26. data/openvas-cli.gemspec +28 -6
  27. data/spec/openvas-cli/vas_administrator_spec.rb +6 -0
  28. data/spec/openvas-cli/vas_config_spec.rb +81 -0
  29. data/spec/openvas-cli/vas_lsc_credential_spec.rb +72 -0
  30. data/spec/openvas-cli/vas_nvt_family_spec.rb +7 -5
  31. data/spec/openvas-cli/vas_nvt_spec.rb +30 -26
  32. data/spec/openvas-cli/vas_period_spec.rb +7 -0
  33. data/spec/openvas-cli/vas_preference_spec.rb +23 -21
  34. data/spec/openvas-cli/vas_report_spec.rb +65 -63
  35. data/spec/openvas-cli/vas_result_spec.rb +94 -93
  36. data/spec/openvas-cli/vas_schedule_spec.rb +154 -57
  37. data/spec/openvas-cli/vas_target_spec.rb +140 -28
  38. data/spec/openvas-cli/vas_task_spec.rb +92 -11
  39. data/spec/spec_helper.rb +15 -5
  40. metadata +72 -24
  41. data/lib/openvas-cli/openvas-cli.rb +0 -273
  42. data/spec/openvas-cli/openvas-cli_spec.rb +0 -45
@@ -1,75 +1,77 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
  require 'nokogiri'
3
3
 
4
- describe "VasReport" do
5
- it "should pull all available reports" do
6
- repts = VasReport.get_all
4
+ module OpenvasCli
5
+ describe VasReport do
6
+ it "should pull all available reports" do
7
+ repts = VasReport.get_all
8
+
9
+ repts.should_not be nil
10
+
11
+ repts.each { |r| r.should be_valid }
12
+ end
7
13
 
8
- repts.should_not be nil
14
+ it 'should pull a raw XML dump for a single report' do
15
+ rept = VasReport.get_all[0]
16
+
17
+ xml = rept.to_xml
18
+
19
+ xdoc = Nokogiri::XML(xml) #it should be a valid xml document
20
+
21
+ xdoc.at_xpath("//report/@id").value.should == rept.report_id
22
+ end
9
23
 
10
- repts.each { |r| r.should be_valid }
11
- end
12
-
13
- it 'should pull a raw XML dump for a single report' do
14
- rept = VasReport.get_all[0]
15
-
16
- xml = rept.to_xml
17
-
18
- xdoc = Nokogiri::XML(xml) #it should be a valid xml document
19
-
20
- xdoc.at_xpath("//report/@id").value.should == rept.report_id
21
- end
22
-
23
- it 'should pull a specific report by id' do
24
- all = VasReport.get_all
25
-
26
- o_rept = all[rand(all.count)]
27
- o_rept.should_not be nil
28
- n_rept = VasReport.get_all(:report_id => o_rept.report_id)[0]
29
- n_rept.should_not be nil
30
-
31
- o_rept.report_id.should == n_rept.report_id
32
- end
33
-
34
- it 'should report the associated results' do
35
- all = VasReport.get_all
24
+ it 'should pull a specific report by id' do
25
+ all = VasReport.get_all
26
+
27
+ o_rept = all[rand(all.count)]
28
+ o_rept.should_not be nil
29
+ n_rept = VasReport.get_all(:report_id => o_rept.report_id)[0]
30
+ n_rept.should_not be nil
31
+
32
+ o_rept.report_id.should == n_rept.report_id
33
+ end
36
34
 
37
- all.each { |r|
38
- r.result_count[:filtered].should == r.results.count
39
- }
40
- end
41
-
42
- it 'should filter the results' do
43
- all = VasReport.get_all(:filter => [:high])
44
-
45
- all.each { |report|
46
- report.results.each{ |result|
47
- result.threat.should =~ /high/i
35
+ it 'should report the associated results' do
36
+ all = VasReport.get_all
37
+
38
+ all.each { |r|
39
+ r.result_count[:filtered].should == r.results.count
48
40
  }
49
- }
41
+ end
50
42
 
51
- all = VasReport.get_all(:filter => [:log])
52
-
53
- all.each { |report|
54
- report.results.each{ |result|
55
- result.threat.should =~ /log/i
43
+ it 'should filter the results' do
44
+ all = VasReport.get_all(:filter => [:high])
45
+
46
+ all.each { |report|
47
+ report.results.each{ |result|
48
+ result.threat.should =~ /high/i
49
+ }
56
50
  }
57
- }
58
-
59
- all = VasReport.get_all(:filter => [:medium, :debug, :low])
60
-
61
- all.each { |report|
62
- report.results.each{ |result|
63
- result.threat.should =~ /(medium)|(debug)|(low)/i
51
+
52
+ all = VasReport.get_all(:filter => [:log])
53
+
54
+ all.each { |report|
55
+ report.results.each{ |result|
56
+ result.threat.should =~ /log/i
57
+ }
64
58
  }
65
- }
66
- end
67
-
68
- it 'should return an empty set when passed a bad report_id' do
69
- lambda {
70
- r = VasReport.get_all(:report_id => '0000000000')
71
- r.should_not be nil
72
- r.should be_empty
73
- }.should_not raise_error
59
+
60
+ all = VasReport.get_all(:filter => [:medium, :debug, :low])
61
+
62
+ all.each { |report|
63
+ report.results.each{ |result|
64
+ result.threat.should =~ /(medium)|(debug)|(low)/i
65
+ }
66
+ }
67
+ end
68
+
69
+ it 'should return an empty set when passed a bad report_id' do
70
+ lambda {
71
+ r = VasReport.get_all(:report_id => '0000000000')
72
+ r.should_not be nil
73
+ r.should be_empty
74
+ }.should_not raise_error
75
+ end
74
76
  end
75
77
  end
@@ -1,109 +1,110 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
- describe 'VasResult' do
4
- it 'should pull all results' do
5
- all_results = VasResult.get_all
6
-
7
- all_results.should_not be nil
8
-
9
- all_results.count.should > 0
10
-
11
- all_results.each { |r| r.should be_valid }
12
- end
13
-
14
- it 'should be able to paginate results', :slow=>true do
15
- result_count = VasResult.get_all.count
16
-
17
- start = 0
18
- num = 20
19
-
20
- while start < result_count do
21
- results = VasResult.get_all(:start => start, :count => num)
3
+ module OpenvasCli
4
+ describe VasResult do
5
+ it 'should pull all results' do
6
+ all_results = VasResult.get_all
22
7
 
23
- results.count.should <= 20
8
+ all_results.should_not be nil
24
9
 
25
- start += results.count
10
+ all_results.each { |r| r.should be_valid }
26
11
  end
27
- end
28
-
29
- it 'should sort by threat by default' do
30
- results = VasResult.get_all
31
12
 
32
- last_val = 9
33
- results.each { |r|
34
- r.threat_level.should <= last_val
35
- last_val = r.threat_level
36
- }
37
- end
38
-
39
- it 'should sort the results by ID' do
40
- results = VasResult.get_all(:sort_by => :result_id)
13
+ it 'should be able to paginate results', :slow=>true do
14
+ result_count = VasResult.get_all.count
15
+
16
+ start = 0
17
+ num = 20
18
+
19
+ while start < result_count do
20
+ results = VasResult.get_all(:start => start, :count => num)
21
+
22
+ results.count.should <= 20
23
+
24
+ start += results.count
25
+ end
26
+ end
41
27
 
42
- last_id = ""
43
- results.each { |r|
44
- r.result_id.should >= last_id
45
- last_id = r.result_id
46
- }
47
- end
48
-
49
- it 'should sort the results by host' do
50
- results = VasResult.get_all(:sort_by => :host)
28
+ it 'should sort by threat by default' do
29
+ results = VasResult.get_all
30
+
31
+ last_val = 9
32
+ results.each { |r|
33
+ r.threat_level.should <= last_val
34
+ last_val = r.threat_level
35
+ }
36
+ end
51
37
 
52
- last_host = ""
53
- results.each { |r|
54
- r.host.should >= last_host
55
- last_host = r.host
56
- }
57
- end
58
-
59
- it 'should sort the results by rule_id' do
60
- results = VasResult.get_all(:sort_by => :rule_id)
38
+ it 'should sort the results by ID' do
39
+ results = VasResult.get_all(:sort_by => :result_id)
40
+
41
+ last_id = ""
42
+ results.each { |r|
43
+ r.result_id.should >= last_id
44
+ last_id = r.result_id
45
+ }
46
+ end
61
47
 
62
- last_val = ""
63
- results.each { |r|
64
- r.rule_id.should >= last_val
65
- last_val = r.rule_id
66
- }
67
- end
68
-
69
- it 'should sort the results by subnet' do
70
- results = VasResult.get_all(:sort_by => :subnet)
48
+ it 'should sort the results by host' do
49
+ results = VasResult.get_all(:sort_by => :host)
50
+
51
+ last_host = ""
52
+ results.each { |r|
53
+ r.host.should >= last_host
54
+ last_host = r.host
55
+ }
56
+ end
71
57
 
72
- last_val = ""
73
- results.each { |r|
74
- r.subnet.should >= last_val
75
- last_val = r.subnet
76
- }
77
- end
78
-
79
- it 'should sort the results by threat' do
80
- results = VasResult.get_all(:sort_by => :threat)
58
+ it 'should sort the results by rule_id' do
59
+ results = VasResult.get_all(:sort_by => :rule_id)
60
+
61
+ last_val = ""
62
+ results.each { |r|
63
+ r.rule_id.should >= last_val
64
+ last_val = r.rule_id
65
+ }
66
+ end
81
67
 
82
- last_val = 9
83
- results.each { |r|
84
- r.threat_level.should <= last_val
85
- last_val = r.threat_level
86
- }
87
- end
88
-
89
- it 'shoudl pull results for a specified task' do
90
- tasks = VasTask.get_all
68
+ it 'should sort the results by subnet' do
69
+ results = VasResult.get_all(:sort_by => :subnet)
70
+
71
+ last_val = ""
72
+ results.each { |r|
73
+ r.subnet.should >= last_val
74
+ last_val = r.subnet
75
+ }
76
+ end
91
77
 
92
- tasks.count.should > 0
93
- task_id = tasks[0].task_id
94
- results = VasResult.get_all(:task_id => task_id)
95
- results.each { |r| r.task_id.should == task_id }
78
+ it 'should sort the results by threat' do
79
+ results = VasResult.get_all(:sort_by => :threat)
80
+
81
+ last_val = 9
82
+ results.each { |r|
83
+ r.threat_level.should <= last_val
84
+ last_val = r.threat_level
85
+ }
86
+ end
96
87
 
97
- all_tasks = VasResult.get_all
88
+ it 'shoudl pull results for a specified task' do
89
+ tasks = VasTask.get_all
90
+
91
+ unless tasks.empty?
92
+ task_id = tasks[0].task_id
93
+ results = VasResult.get_all(:task_id => task_id)
94
+ results.each { |r| r.task_id.should == task_id }
95
+
96
+ all_tasks = VasResult.get_all
97
+
98
+ all_tasks.count.should >= results.count
99
+ end
100
+ end
98
101
 
99
- all_tasks.count.should >= results.count
100
- end
101
-
102
- it 'should filter based off of threat level' do
103
- results = VasResult.get_all(:filter=>[:high, :medium])
104
- threats = ["High", "Medium"]
105
- results.each { |r|
106
- threats.should include r.threat
107
- }
102
+ it 'should filter based off of threat level' do
103
+ results = VasResult.get_all(:filter=>[:high, :medium])
104
+ threats = ["High", "Medium"]
105
+ results.each { |r|
106
+ threats.should include r.threat
107
+ }
108
+ end
108
109
  end
109
110
  end
@@ -1,61 +1,158 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
- describe 'VasSchedule' do
4
- it 'should pull all available schedules' do
5
- schedules = VasSchedule.get_all
6
- schedules.should_not be nil
7
- schedules.count.should > 0
8
- schedules.each{ |s| s.should be_valid }
9
- end
10
-
11
- it 'should pull a schedule by ID' do
12
- all = VasSchedule.get_all
13
- all.should_not be nil
14
- all.count.should > 0
15
-
16
- schedule_id = all[rand(all.count)].schedule_id
17
- schedules = VasSchedule.get_all(:schedule_id => schedule_id)
18
- schedules.count.should == 1
19
- schedules[0].schedule_id.should == schedule_id
20
- end
21
-
22
- it 'default sort should be by name' do
23
- all = VasSchedule.get_all
24
-
25
- old_val = ""
26
- all.each { |s|
27
- s.name.should >= old_val
28
- old_val = s.name
29
- }
30
- end
31
-
32
- it 'should sort by schedule_id' do
33
- all = VasSchedule.get_all(:sort_by=>:schedule_id)
34
-
35
- old_val = ""
36
- all.each { |s|
37
- s.schedule_id.should >= old_val
38
- old_val = s.schedule_id
39
- }
40
- end
41
-
42
- it 'should sort_by first_time' do
43
- all = VasSchedule.get_all(:sort_by=>:first_time)
44
-
45
- old_val = Time.at(0)
46
- all.each { |s|
47
- s.first_time.should >= old_val
48
- old_val = s.first_time
49
- }
50
- end
51
-
52
- it 'should sort_by next_time' do
53
- all = VasSchedule.get_all(:sort_by=>:next_time)
54
-
55
- old_val = Time.at(0)
56
- all.each { |s|
57
- s.next_time.should >= old_val
58
- old_val = s.next_time
59
- }
3
+ module OpenvasCli
4
+ describe VasSchedule do
5
+ def valid_params
6
+ {
7
+ :name => "Test_#{Time.now.strftime('%Y-%m-%d_%H:%M:%S')}",
8
+ :comment => "Test Schedule [Automatically Generated]",
9
+ :first_time => Time.now + 86400,
10
+ :period => VasPeriod.new(:number => 1, :period => :day)
11
+ }
12
+ end
13
+
14
+ def get_t_string(t)
15
+ t.strftime("%Y-%m-%d_%H:%M")
16
+ end
17
+
18
+ after(:each) do
19
+ all = VasSchedule.get_all
20
+ all.each { |s| s.destroy! if s.name =~ /Test_.*/i }
21
+ end
22
+
23
+ it 'should pull all available schedules' do
24
+ schedules = VasSchedule.get_all
25
+ schedules.should_not be nil
26
+ schedules.each{ |s| s.should be_valid }
27
+ end
28
+
29
+ it 'should pull a schedule by ID' do
30
+ all = VasSchedule.get_all
31
+ all.should_not be nil
32
+
33
+ unless all.empty?
34
+ schedule_id = all.choice.id
35
+ schedules = VasSchedule.get_all(:id => schedule_id)
36
+ schedules.count.should == 1
37
+ schedules[0].id.should == schedule_id
38
+ end
39
+ end
40
+
41
+ it 'default sort should be by name' do
42
+ all = VasSchedule.get_all
43
+
44
+ old_val = ""
45
+ all.each { |s|
46
+ s.name.should >= old_val
47
+ old_val = s.name
48
+ }
49
+ end
50
+
51
+ it 'should sort by schedule_id' do
52
+ all = VasSchedule.get_all(:sort_by=>:schedule_id)
53
+
54
+ old_val = ""
55
+ all.each { |s|
56
+ s.id.should >= old_val
57
+ old_val = s.id
58
+ }
59
+ end
60
+
61
+ it 'should sort_by first_time' do
62
+ all = VasSchedule.get_all(:sort_by=>:first_time)
63
+
64
+ old_val = Time.at(0)
65
+ all.each { |s|
66
+ s.first_time.should >= old_val
67
+ old_val = s.first_time
68
+ }
69
+ end
70
+
71
+ it 'should sort_by next_time' do
72
+ all = VasSchedule.get_all(:sort_by=>:next_time)
73
+
74
+ old_val = Time.at(0)
75
+ all.each { |s|
76
+ s.next_time.should >= old_val
77
+ old_val = s.next_time
78
+ }
79
+ end
80
+
81
+ it 'should create a new schedule' do
82
+ s = VasSchedule.new(valid_params)
83
+ s.should be_valid
84
+ s.save!
85
+
86
+ s.should_not be_changed
87
+ s.id.should_not be nil
88
+
89
+ new_s = VasSchedule.get_all(:id => s.id)[0]
90
+ new_s.should_not be nil
91
+ new_s.id.should == s.id
92
+ new_s.name.should == s.name
93
+ new_s.comment.should == s.comment
94
+ get_t_string(new_s.first_time).should == get_t_string(s.first_time)
95
+ new_s.period.should == s.period
96
+ end
97
+
98
+ it 'should modify an existing schedule' do
99
+ s = VasSchedule.new(valid_params)
100
+ s.save!
101
+
102
+ old_id = s.id
103
+
104
+ s.comment = "NEW COMMENT"
105
+ s.save!
106
+
107
+ s.id.should_not == old_id
108
+
109
+ VasSchedule.get_all(:id => old_id).should be_empty
110
+
111
+ new_s = VasSchedule.get_all(:id => s.id)[0]
112
+ new_s.should_not be nil
113
+ new_s.id.should == s.id
114
+ new_s.name.should == s.name
115
+ new_s.comment.should == s.comment
116
+ get_t_string(new_s.first_time).should == get_t_string(s.first_time)
117
+ new_s.period.should == s.period
118
+ end
119
+
120
+ it 'should report changed when name is changed' do
121
+ s = VasSchedule.new(valid_params)
122
+ s.should_not be_changed
123
+
124
+ s.name = "NEW NAME"
125
+ s.should be_changed
126
+ end
127
+
128
+ it 'should report changed when comment is changed' do
129
+ s = VasSchedule.new(valid_params)
130
+ s.should_not be_changed
131
+
132
+ s.comment = "NEW COMMENT"
133
+ s.should be_changed
134
+ end
135
+
136
+ it 'should report changed when first_time is changed' do
137
+ s = VasSchedule.new(valid_params)
138
+ s.should_not be_changed
139
+
140
+ s.first_time = s.first_time
141
+ s.should_not be_changed
142
+
143
+ s.first_time = Time.now + 30
144
+ s.should be_changed
145
+ end
146
+
147
+ it 'should report changed when period is changed' do
148
+ s = VasSchedule.new(valid_params)
149
+ s.should_not be_changed
150
+
151
+ s.period = s.period
152
+ s.should_not be_changed
153
+
154
+ s.period = s.period + VasPeriod.new(:number => 2, :period => :day)
155
+ s.should be_changed
156
+ end
60
157
  end
61
158
  end