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.
- data/Gemfile +2 -0
- data/Gemfile.lock +50 -0
- data/VERSION +1 -1
- data/lib/openvas-cli/configuration.rb +25 -0
- data/lib/openvas-cli/conn_addin.rb +27 -0
- data/lib/openvas-cli/immutable_children_validator.rb +15 -0
- data/lib/openvas-cli/vas_administrator.rb +7 -0
- data/lib/openvas-cli/vas_base.rb +20 -30
- data/lib/openvas-cli/vas_config.rb +127 -0
- data/lib/openvas-cli/vas_connection.rb +140 -0
- data/lib/openvas-cli/vas_exceptions.rb +9 -7
- data/lib/openvas-cli/vas_lsc_credential.rb +110 -0
- data/lib/openvas-cli/vas_nvt.rb +64 -64
- data/lib/openvas-cli/vas_nvt_family.rb +39 -30
- data/lib/openvas-cli/vas_override.rb +6 -4
- data/lib/openvas-cli/vas_period.rb +89 -0
- data/lib/openvas-cli/vas_preference.rb +139 -49
- data/lib/openvas-cli/vas_report.rb +110 -103
- data/lib/openvas-cli/vas_result.rb +90 -89
- data/lib/openvas-cli/vas_schedule.rb +163 -55
- data/lib/openvas-cli/vas_target.rb +200 -23
- data/lib/openvas-cli/vas_task.rb +229 -30
- data/lib/openvas-cli/vas_task_progress.rb +29 -0
- data/lib/openvas-cli/xml_addin.rb +34 -0
- data/lib/openvas_cli.rb +19 -0
- data/openvas-cli.gemspec +28 -6
- data/spec/openvas-cli/vas_administrator_spec.rb +6 -0
- data/spec/openvas-cli/vas_config_spec.rb +81 -0
- data/spec/openvas-cli/vas_lsc_credential_spec.rb +72 -0
- data/spec/openvas-cli/vas_nvt_family_spec.rb +7 -5
- data/spec/openvas-cli/vas_nvt_spec.rb +30 -26
- data/spec/openvas-cli/vas_period_spec.rb +7 -0
- data/spec/openvas-cli/vas_preference_spec.rb +23 -21
- data/spec/openvas-cli/vas_report_spec.rb +65 -63
- data/spec/openvas-cli/vas_result_spec.rb +94 -93
- data/spec/openvas-cli/vas_schedule_spec.rb +154 -57
- data/spec/openvas-cli/vas_target_spec.rb +140 -28
- data/spec/openvas-cli/vas_task_spec.rb +92 -11
- data/spec/spec_helper.rb +15 -5
- metadata +72 -24
- data/lib/openvas-cli/openvas-cli.rb +0 -273
- 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
|
-
|
5
|
-
|
6
|
-
|
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
|
-
|
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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
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
|
-
|
4
|
-
|
5
|
-
|
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
|
-
|
8
|
+
all_results.should_not be nil
|
24
9
|
|
25
|
-
|
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
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
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
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
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
|
-
|
73
|
-
|
74
|
-
|
75
|
-
last_val =
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
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
|
-
|
83
|
-
|
84
|
-
|
85
|
-
last_val =
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
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
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
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
|
-
|
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
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
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
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
all
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
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
|