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,39 +1,151 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+ require 'ipaddress'
2
3
 
3
- describe VasTarget do
4
- it 'should get all available targets' do
5
- targs = VasTarget.get_all
6
- targs.count.should > 0
4
+ module OpenvasCli
5
+ describe VasTarget do
6
+ before(:each) do
7
+ @valid_chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a',
8
+ 'b', 'c', 'd', 'e', 'f', 'A', 'B', 'C', 'D', 'E', 'F', '-']
9
+ end
7
10
 
8
- targs.each { |t|
9
- t.should be_valid
10
- }
11
- end
12
-
13
- it 'should require a non-empty vas_id' do
14
- t = VasTarget.new
15
- t.vas_id = ""
11
+ after(:each) do
12
+ all = VasTarget.get_all
13
+
14
+ all.each { |t|
15
+ t.destroy! if t.name =~ /Test_.*/i
16
+ }
17
+ end
18
+
19
+ def valid_params
20
+ {
21
+ :name=>"Test_#{Time.now.strftime('%Y-%m-%d_%H:%M:%S')}",
22
+ :hosts => VasTarget.get_local_subnets
23
+ }
24
+ end
16
25
 
17
- t.should_not be_valid
18
- end
19
-
20
- it 'should require a valid UUID format' do
21
- t = VasTarget.new
22
- t.vas_id = "This is not a valid UUID"
26
+ it 'should get all available targets' do
27
+ targs = VasTarget.get_all
28
+ targs.count.should > 0
29
+
30
+ targs.each { |t|
31
+ t.should be_valid
32
+ }
33
+ end
23
34
 
24
- t.should_not be_valid
25
- t.should have(1).errors
35
+ it 'should require a non-empty vas_id' do
36
+ t = VasTarget.new(valid_params)
37
+ t.id = ""
38
+
39
+ t.should_not be_valid
40
+ end
26
41
 
27
- valid_chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a',
28
- 'b', 'c', 'd', 'e', 'f', 'A', 'B', 'C', 'D', 'E', 'F', '-']
42
+ it 'should require a valid UUID format' do
43
+ t = VasTarget.new(valid_params)
44
+ t.id = "This is not a valid UUID"
45
+ t.should_not be_valid
46
+ t.should have(1).errors
47
+
48
+ 1.upto(10) {
49
+ uuid = ''
50
+ 1.upto(rand(40) + 1) {
51
+ uuid += @valid_chars[rand(@valid_chars.length)]
52
+ }
53
+ t.id = uuid
54
+ t.should be_valid
55
+ }
56
+ end
29
57
 
30
- 1.upto(10) {
31
- uuid = ''
32
- 1.upto(rand(40) + 1) {
33
- uuid += valid_chars[rand(valid_chars.length)]
58
+ it 'should generate a valid list of subnets' do
59
+ VasTarget.get_local_subnets.each { |sn|
60
+ net = IPAddress(sn)
61
+ net.should be_network
34
62
  }
35
- t.vas_id = uuid
63
+ end
64
+
65
+ it 'should create a new target if the id is empty' do
66
+ t = VasTarget.new(valid_params)
67
+ t.id = nil
68
+ t.save!
69
+
70
+ t.id.should_not be nil
71
+
72
+ n_t = VasTarget.get_all(:id => t.id)[0]
73
+ n_t.should_not be nil
74
+ n_t.id.should == t.id
75
+ n_t.name.should == t.name
76
+ n_t.should have(t.hosts.count).hosts
77
+ # n_t.hosts.each { |h|
78
+ # t.hosts.should include h
79
+ # }
80
+ end
81
+
82
+ it 'should record a change when the name has changed' do
83
+ t = VasTarget.new(valid_params)
84
+
85
+ t.should_not be_changed
86
+
87
+ t.name = "NEW NAME"
88
+ t.should be_changed
89
+ end
90
+
91
+ it 'should record a change when the comment has changed' do
92
+ t = VasTarget.new(valid_params)
93
+ t.should_not be_changed
94
+
95
+ t.comment = "NEW COMMENT"
96
+ t.should be_changed
97
+ end
98
+
99
+ it 'should record a change when the hosts have been re-assigned' do
100
+ t = VasTarget.new(valid_params)
101
+ t.should_not be_changed
102
+
103
+ t.hosts = ['10.10.10.0/24', '192.168.1.0/24']
104
+ t.should be_changed
105
+ end
106
+
107
+ it 'should record a change when a host has been added' do
108
+ t = VasTarget.new(valid_params)
109
+ t.should_not be_changed
110
+
111
+ t.hosts << "10.10.10.0/24"
112
+ t.should be_changed
113
+ end
114
+
115
+ it 'should record a change when a host has been removed' do
116
+ t = VasTarget.new(valid_params.merge({:hosts => ['10.10.10.0/24', '192.168.1.0/24']}))
36
117
  t.should be_valid
37
- }
118
+ t.should have(2).hosts
119
+
120
+ t.hosts.delete_if { |h| h == '192.168.1.0/24'}
121
+ t.should have(1).hosts
122
+
123
+ t.should be_changed
124
+ end
125
+
126
+ it 'should create a new target and delete the old one when something has changed.' do
127
+ t = VasTarget.new(valid_params)
128
+ t.save!
129
+ org_id = t.id
130
+
131
+ t.hosts = ['10.10.10.0/24', '192.168.1.0/24']
132
+ t.save!
133
+
134
+ t.id.should_not == org_id
135
+
136
+ srch = VasTarget.get_all(:id => org_id)
137
+ srch.should_not be nil
138
+ srch.size.should == 0
139
+ end
140
+
141
+ it 'should show a change when a new credential is added' do
142
+ t = VasTarget.new(valid_params)
143
+ t.credentials[:ssh] = VasLscCredential.new(:name => "Test_login",
144
+ :login => "myLogin",
145
+ :comment => "Should never be saved",
146
+ :password => "reallyBadPassword")
147
+
148
+ t.should be_changed
149
+ end
38
150
  end
39
151
  end
@@ -1,19 +1,100 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
- describe 'VasTask' do
4
- it 'should pull all tasks' do
5
- tasks = VasTask.get_all
3
+ module OpenvasCli
4
+ describe VasTask do
5
+ after(:each) do
6
+ all = VasTask.get_all
7
+ all.each { |t| t.destroy! if t.name =~ /Test_.*/i }
8
+
9
+ all = VasTarget.get_all
10
+ all.each { |t| t.destroy! if t.name =~ /Target_Test_.*/i }
11
+ end
6
12
 
7
- tasks.should_not be nil
13
+ def valid_params
14
+ {
15
+ :name => "Test_#{Time.now.strftime('%Y-%m-%d_%H:%M:%S')}",
16
+ :config_id => get_config_id,
17
+ :target_id => get_target_id,
18
+ :schedule => VasSchedule.new(schedule_params)
19
+ }
20
+ end
8
21
 
9
- tasks.each { |t| t.should be_valid }
10
- end
11
-
12
- it 'should pull a single task given the task_id' do
13
- task = VasTask.get_all[0]
22
+ def schedule_params
23
+ {
24
+ :name => "Test_#{Time.now.strftime('%Y-%m-%d_%H:%M:%S')}",
25
+ :comment => "Test Schedule [Automatically Generated]",
26
+ :first_time => Time.now + 86400,
27
+ :period => VasPeriod.new(:number => 1, :period => :day)
28
+ }
29
+ end
30
+
31
+ def get_config_id
32
+ VasConfig.get_all.choice.id
33
+ end
34
+
35
+ def get_target_id
36
+ targs = VasTarget.get_all
37
+ if targs.count == 0
38
+ t = VasTarget.create!(valid_target_params)
39
+ else
40
+ t = targs.choice
41
+ end
42
+
43
+ t.id
44
+ end
45
+
46
+ def valid_target_params
47
+ {
48
+ :name => "Test_Target_#{Time.now.strftime('%Y-%m-%d_%H:%M:%S')}",
49
+ :hosts => VasTarget.get_local_subnets
50
+ }
51
+ end
52
+
53
+ it 'should create a valid task' do
54
+ t = VasTask.new(valid_params)
55
+ t.should be_valid
56
+ end
57
+
58
+ it 'should pull all tasks' do
59
+ tasks = VasTask.get_all
60
+
61
+ tasks.should_not be nil
62
+
63
+ tasks.each { |t| t.should be_valid }
64
+ end
65
+
66
+ it 'should create a task' do
67
+ t = VasTask.new(valid_params)
68
+ t.save!
69
+
70
+ t.id.should_not be nil
71
+ t.id.should_not be_empty
72
+
73
+ new_t = VasTask.get_all(:id => t.id)[0]
74
+ new_t.should_not be nil
75
+
76
+ new_t.name.should == t.name
77
+ new_t.config_id.should == t.config_id
78
+ new_t.target_id.should == t.target_id
79
+
80
+ new_t.destroy!
81
+ end
14
82
 
15
- new_task = VasTask.get_all(:task_id => task.task_id)[0]
83
+ it 'should pull a single task given the task_id' do
84
+ all = VasTask.get_all
85
+
86
+ if all.length > 0
87
+ task = all[0]
88
+
89
+ new_task = VasTask.get_all(:task_id => task.task_id)[0]
90
+
91
+ task.task_id.should == new_task.task_id
92
+ end
93
+ end
16
94
 
17
- task.task_id.should == new_task.task_id
95
+ it 'should start a new task and run it to the end'
96
+ it 'should stop a task completely'
97
+ it 'should pause a task and restart it'
98
+ it 'should report the progress of a task'
18
99
  end
19
100
  end
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,11 @@
1
1
  $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'openvas-cli')))
2
+ $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
2
3
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
4
 
4
5
  require 'rspec'
5
- require 'openvas-cli'
6
6
  require 'log4r'
7
+ require 'fileutils'
8
+ require 'openvas_cli'
7
9
 
8
10
  Dir["#{File.dirname(__FILE__)}/../lib/openvas-cli/vas_*.rb"].each {|f| require f}
9
11
  # Requires supporting files with custom matchers and macros, etc,
@@ -18,13 +20,21 @@ end
18
20
  # Set the client and logger up to meet your needs. Be careful if you set the
19
21
  # log level to Log4r::DEBUG. This will cause A LOT of information to be dumped
20
22
  # to file.
23
+ log_dir = File.expand_path(File.join(File.dirname(__FILE__), "..", "log"))
24
+ FileUtils.mkdir(log_dir) unless File.exists?(log_dir)
21
25
  logger = Log4r::Logger.new 'test_log'
22
26
  log_file = File.expand_path(File.join(File.dirname(__FILE__), '..', 'log', 'test.log'))
23
27
  log_out = Log4r::RollingFileOutputter.new('test_log' ,
24
28
  {:filename => log_file.to_s,
25
29
  :maxsize => 10485760})
26
- log_out.level = Log4r::WARN
30
+ log_out.level = Log4r::INFO
27
31
  logger.outputters = log_out
28
- OpenvasCli.logger = logger
29
- OpenvasCli.user = "admin"
30
- OpenvasCli.password = "Password"
32
+ #VasManager.logger = logger
33
+ #VasManager.user = "admin"
34
+ #VasManager.password = "Password"
35
+
36
+ OpenvasCli.configure { |config|
37
+ config.password = "Password"
38
+ }
39
+
40
+ OpenvasCli.logger = logger
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openvas-cli
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Reed Swenson
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-11 00:00:00 -06:00
18
+ date: 2011-03-25 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -31,8 +31,8 @@ dependencies:
31
31
  - 0
32
32
  - 5
33
33
  version: 3.0.5
34
- version_requirements: *id001
35
34
  name: activesupport
35
+ version_requirements: *id001
36
36
  prerelease: false
37
37
  - !ruby/object:Gem::Dependency
38
38
  type: :runtime
@@ -47,12 +47,28 @@ dependencies:
47
47
  - 0
48
48
  - 5
49
49
  version: 3.0.5
50
- version_requirements: *id002
51
50
  name: activerecord
51
+ version_requirements: *id002
52
52
  prerelease: false
53
53
  - !ruby/object:Gem::Dependency
54
54
  type: :runtime
55
55
  requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 13
61
+ segments:
62
+ - 3
63
+ - 0
64
+ - 5
65
+ version: 3.0.5
66
+ name: rails
67
+ version_requirements: *id003
68
+ prerelease: false
69
+ - !ruby/object:Gem::Dependency
70
+ type: :runtime
71
+ requirement: &id004 !ruby/object:Gem::Requirement
56
72
  none: false
57
73
  requirements:
58
74
  - - ">="
@@ -63,12 +79,28 @@ dependencies:
63
79
  - 4
64
80
  - 4
65
81
  version: 1.4.4
66
- version_requirements: *id003
67
82
  name: nokogiri
83
+ version_requirements: *id004
84
+ prerelease: false
85
+ - !ruby/object:Gem::Dependency
86
+ type: :runtime
87
+ requirement: &id005 !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ hash: 3
93
+ segments:
94
+ - 0
95
+ - 7
96
+ - 0
97
+ version: 0.7.0
98
+ name: ipaddress
99
+ version_requirements: *id005
68
100
  prerelease: false
69
101
  - !ruby/object:Gem::Dependency
70
102
  type: :development
71
- requirement: &id004 !ruby/object:Gem::Requirement
103
+ requirement: &id006 !ruby/object:Gem::Requirement
72
104
  none: false
73
105
  requirements:
74
106
  - - ~>
@@ -79,12 +111,12 @@ dependencies:
79
111
  - 3
80
112
  - 0
81
113
  version: 2.3.0
82
- version_requirements: *id004
83
114
  name: rspec
115
+ version_requirements: *id006
84
116
  prerelease: false
85
117
  - !ruby/object:Gem::Dependency
86
118
  type: :development
87
- requirement: &id005 !ruby/object:Gem::Requirement
119
+ requirement: &id007 !ruby/object:Gem::Requirement
88
120
  none: false
89
121
  requirements:
90
122
  - - ~>
@@ -95,12 +127,12 @@ dependencies:
95
127
  - 0
96
128
  - 0
97
129
  version: 1.0.0
98
- version_requirements: *id005
99
130
  name: bundler
131
+ version_requirements: *id007
100
132
  prerelease: false
101
133
  - !ruby/object:Gem::Dependency
102
134
  type: :development
103
- requirement: &id006 !ruby/object:Gem::Requirement
135
+ requirement: &id008 !ruby/object:Gem::Requirement
104
136
  none: false
105
137
  requirements:
106
138
  - - ~>
@@ -111,12 +143,12 @@ dependencies:
111
143
  - 5
112
144
  - 2
113
145
  version: 1.5.2
114
- version_requirements: *id006
115
146
  name: jeweler
147
+ version_requirements: *id008
116
148
  prerelease: false
117
149
  - !ruby/object:Gem::Dependency
118
150
  type: :development
119
- requirement: &id007 !ruby/object:Gem::Requirement
151
+ requirement: &id009 !ruby/object:Gem::Requirement
120
152
  none: false
121
153
  requirements:
122
154
  - - ">="
@@ -125,12 +157,12 @@ dependencies:
125
157
  segments:
126
158
  - 0
127
159
  version: "0"
128
- version_requirements: *id007
129
160
  name: rcov
161
+ version_requirements: *id009
130
162
  prerelease: false
131
163
  - !ruby/object:Gem::Dependency
132
164
  type: :development
133
- requirement: &id008 !ruby/object:Gem::Requirement
165
+ requirement: &id010 !ruby/object:Gem::Requirement
134
166
  none: false
135
167
  requirements:
136
168
  - - ">="
@@ -139,12 +171,12 @@ dependencies:
139
171
  segments:
140
172
  - 0
141
173
  version: "0"
142
- version_requirements: *id008
143
174
  name: ZenTest
175
+ version_requirements: *id010
144
176
  prerelease: false
145
177
  - !ruby/object:Gem::Dependency
146
178
  type: :development
147
- requirement: &id009 !ruby/object:Gem::Requirement
179
+ requirement: &id011 !ruby/object:Gem::Requirement
148
180
  none: false
149
181
  requirements:
150
182
  - - ">="
@@ -153,8 +185,8 @@ dependencies:
153
185
  segments:
154
186
  - 0
155
187
  version: "0"
156
- version_requirements: *id009
157
188
  name: log4r
189
+ version_requirements: *id011
158
190
  prerelease: false
159
191
  description: A full ruby implementation of the OpenVAS OMP (version 2.0) protocol.
160
192
  email: fleureed@gmail.com
@@ -177,24 +209,37 @@ files:
177
209
  - features/openvas-cli.feature
178
210
  - features/step_definitions/openvas-cli_steps.rb
179
211
  - features/support/env.rb
212
+ - lib/openvas-cli/configuration.rb
213
+ - lib/openvas-cli/conn_addin.rb
214
+ - lib/openvas-cli/immutable_children_validator.rb
180
215
  - lib/openvas-cli/oid_validator.rb
181
- - lib/openvas-cli/openvas-cli.rb
182
216
  - lib/openvas-cli/uuid_validator.rb
217
+ - lib/openvas-cli/vas_administrator.rb
183
218
  - lib/openvas-cli/vas_base.rb
219
+ - lib/openvas-cli/vas_config.rb
220
+ - lib/openvas-cli/vas_connection.rb
184
221
  - lib/openvas-cli/vas_exceptions.rb
222
+ - lib/openvas-cli/vas_lsc_credential.rb
185
223
  - lib/openvas-cli/vas_nvt.rb
186
224
  - lib/openvas-cli/vas_nvt_family.rb
187
225
  - lib/openvas-cli/vas_override.rb
226
+ - lib/openvas-cli/vas_period.rb
188
227
  - lib/openvas-cli/vas_preference.rb
189
228
  - lib/openvas-cli/vas_report.rb
190
229
  - lib/openvas-cli/vas_result.rb
191
230
  - lib/openvas-cli/vas_schedule.rb
192
231
  - lib/openvas-cli/vas_target.rb
193
232
  - lib/openvas-cli/vas_task.rb
233
+ - lib/openvas-cli/vas_task_progress.rb
234
+ - lib/openvas-cli/xml_addin.rb
235
+ - lib/openvas_cli.rb
194
236
  - openvas-cli.gemspec
195
- - spec/openvas-cli/openvas-cli_spec.rb
237
+ - spec/openvas-cli/vas_administrator_spec.rb
238
+ - spec/openvas-cli/vas_config_spec.rb
239
+ - spec/openvas-cli/vas_lsc_credential_spec.rb
196
240
  - spec/openvas-cli/vas_nvt_family_spec.rb
197
241
  - spec/openvas-cli/vas_nvt_spec.rb
242
+ - spec/openvas-cli/vas_period_spec.rb
198
243
  - spec/openvas-cli/vas_preference_spec.rb
199
244
  - spec/openvas-cli/vas_report_spec.rb
200
245
  - spec/openvas-cli/vas_result_spec.rb
@@ -232,14 +277,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
232
277
  requirements: []
233
278
 
234
279
  rubyforge_project:
235
- rubygems_version: 1.6.0
280
+ rubygems_version: 1.6.2
236
281
  signing_key:
237
282
  specification_version: 3
238
283
  summary: A full ruby implementation of the OpenVAS OMP (version 2.0) protocol.
239
284
  test_files:
240
- - spec/openvas-cli/openvas-cli_spec.rb
285
+ - spec/openvas-cli/vas_administrator_spec.rb
286
+ - spec/openvas-cli/vas_config_spec.rb
287
+ - spec/openvas-cli/vas_lsc_credential_spec.rb
241
288
  - spec/openvas-cli/vas_nvt_family_spec.rb
242
289
  - spec/openvas-cli/vas_nvt_spec.rb
290
+ - spec/openvas-cli/vas_period_spec.rb
243
291
  - spec/openvas-cli/vas_preference_spec.rb
244
292
  - spec/openvas-cli/vas_report_spec.rb
245
293
  - spec/openvas-cli/vas_result_spec.rb