metasploit_data_models 1.0.0.pre.rails.pre.4.0b → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +2 -2
  3. data/.travis.yml +6 -3
  4. data/CHANGELOG.md +6 -0
  5. data/CONTRIBUTING.md +10 -52
  6. data/Gemfile +4 -6
  7. data/RELEASING.md +88 -0
  8. data/Rakefile +23 -0
  9. data/UPGRADING.md +1 -0
  10. data/app/models/mdm/api_key.rb +41 -1
  11. data/app/models/mdm/client.rb +41 -1
  12. data/app/models/mdm/cred.rb +116 -28
  13. data/app/models/mdm/event.rb +47 -0
  14. data/app/models/mdm/exploit_attempt.rb +65 -16
  15. data/app/models/mdm/exploited_host.rb +27 -0
  16. data/app/models/mdm/host_detail.rb +44 -0
  17. data/app/models/mdm/host_tag.rb +6 -8
  18. data/app/models/mdm/listener.rb +52 -0
  19. data/app/models/mdm/macro.rb +42 -0
  20. data/app/models/mdm/mod_ref.rb +21 -1
  21. data/app/models/mdm/module/action.rb +15 -0
  22. data/app/models/mdm/module/arch.rb +10 -0
  23. data/app/models/mdm/module/author.rb +17 -1
  24. data/app/models/mdm/module/mixin.rb +13 -0
  25. data/app/models/mdm/module/platform.rb +11 -0
  26. data/app/models/mdm/module/target.rb +18 -0
  27. data/app/models/mdm/nexpose_console.rb +82 -4
  28. data/app/models/mdm/profile.rb +36 -0
  29. data/app/models/mdm/route.rb +16 -4
  30. data/app/models/mdm/session_event.rb +32 -0
  31. data/app/models/mdm/tag.rb +48 -9
  32. data/app/models/mdm/task.rb +85 -46
  33. data/app/models/mdm/task_cred.rb +29 -0
  34. data/app/models/mdm/task_host.rb +25 -0
  35. data/app/models/mdm/task_service.rb +25 -0
  36. data/app/models/mdm/task_session.rb +25 -0
  37. data/app/models/mdm/user.rb +192 -6
  38. data/app/models/mdm/vuln_attempt.rb +37 -12
  39. data/app/models/mdm/vuln_detail.rb +138 -5
  40. data/app/models/mdm/vuln_ref.rb +3 -0
  41. data/app/models/mdm/web_form.rb +34 -0
  42. data/app/models/mdm/web_page.rb +69 -0
  43. data/app/models/mdm/web_site.rb +50 -0
  44. data/app/models/mdm/wmap_request.rb +85 -0
  45. data/app/models/mdm/wmap_target.rb +40 -0
  46. data/app/models/mdm/workspace.rb +160 -17
  47. data/app/models/metasploit_data_models/automatic_exploitation/match.rb +13 -23
  48. data/app/models/metasploit_data_models/automatic_exploitation/match_result.rb +25 -4
  49. data/app/models/metasploit_data_models/automatic_exploitation/match_set.rb +15 -4
  50. data/app/models/metasploit_data_models/automatic_exploitation/run.rb +7 -3
  51. data/app/models/metasploit_data_models/ip_address/v4/segmented.rb +1 -1
  52. data/app/models/metasploit_data_models/module_run.rb +1 -1
  53. data/app/models/metasploit_data_models/search/visitor/where.rb +1 -1
  54. data/app/validators/ip_format_validator.rb +4 -0
  55. data/app/validators/parameters_validator.rb +12 -0
  56. data/app/validators/password_is_strong_validator.rb +10 -1
  57. data/lib/mdm/host/operating_system_normalization.rb +7 -10
  58. data/lib/metasploit_data_models.rb +4 -0
  59. data/lib/metasploit_data_models/automatic_exploitation.rb +25 -0
  60. data/lib/metasploit_data_models/engine.rb +2 -0
  61. data/lib/metasploit_data_models/serialized_prefs.rb +6 -0
  62. data/lib/metasploit_data_models/version.rb +30 -7
  63. data/metasploit_data_models.gemspec +9 -2
  64. data/spec/app/models/mdm/api_key_spec.rb +1 -3
  65. data/spec/app/models/mdm/client_spec.rb +9 -11
  66. data/spec/app/models/mdm/cred_spec.rb +42 -54
  67. data/spec/app/models/mdm/event_spec.rb +22 -24
  68. data/spec/app/models/mdm/exploit_attempt_spec.rb +19 -21
  69. data/spec/app/models/mdm/exploited_host_spec.rb +11 -13
  70. data/spec/app/models/mdm/host_detail_spec.rb +15 -17
  71. data/spec/app/models/mdm/host_spec.rb +262 -260
  72. data/spec/app/models/mdm/host_tag_spec.rb +6 -8
  73. data/spec/app/models/mdm/listener_spec.rb +30 -32
  74. data/spec/app/models/mdm/loot_spec.rb +21 -23
  75. data/spec/app/models/mdm/macro_spec.rb +1 -3
  76. data/spec/app/models/mdm/mod_ref_spec.rb +1 -3
  77. data/spec/app/models/mdm/module/action_spec.rb +8 -10
  78. data/spec/app/models/mdm/module/arch_spec.rb +8 -10
  79. data/spec/app/models/mdm/module/author_spec.rb +19 -14
  80. data/spec/app/models/mdm/module/detail_spec.rb +184 -75
  81. data/spec/app/models/mdm/module/mixin_spec.rb +8 -10
  82. data/spec/app/models/mdm/module/platform_spec.rb +8 -10
  83. data/spec/app/models/mdm/module/ref_spec.rb +8 -10
  84. data/spec/app/models/mdm/module/target_spec.rb +10 -12
  85. data/spec/app/models/mdm/nexpose_console_spec.rb +35 -37
  86. data/spec/app/models/mdm/note_spec.rb +23 -25
  87. data/spec/app/models/mdm/profile_spec.rb +1 -3
  88. data/spec/app/models/mdm/ref_spec.rb +9 -12
  89. data/spec/app/models/mdm/route_spec.rb +6 -8
  90. data/spec/app/models/mdm/service_spec.rb +38 -40
  91. data/spec/app/models/mdm/session_event_spec.rb +10 -12
  92. data/spec/app/models/mdm/session_spec.rb +13 -15
  93. data/spec/app/models/mdm/tag_spec.rb +29 -30
  94. data/spec/app/models/mdm/task_cred_spec.rb +9 -11
  95. data/spec/app/models/mdm/task_host_spec.rb +9 -11
  96. data/spec/app/models/mdm/task_service_spec.rb +9 -11
  97. data/spec/app/models/mdm/task_session_spec.rb +7 -9
  98. data/spec/app/models/mdm/task_spec.rb +27 -29
  99. data/spec/app/models/mdm/user_spec.rb +17 -19
  100. data/spec/app/models/mdm/vuln_attempt_spec.rb +14 -16
  101. data/spec/app/models/mdm/vuln_detail_spec.rb +26 -28
  102. data/spec/app/models/mdm/vuln_ref_spec.rb +8 -10
  103. data/spec/app/models/mdm/vuln_spec.rb +24 -26
  104. data/spec/app/models/mdm/web_form_spec.rb +11 -13
  105. data/spec/app/models/mdm/web_page_spec.rb +19 -21
  106. data/spec/app/models/mdm/web_site_spec.rb +21 -23
  107. data/spec/app/models/mdm/web_vuln_spec.rb +63 -65
  108. data/spec/app/models/mdm/wmap_request_spec.rb +1 -3
  109. data/spec/app/models/mdm/wmap_target_spec.rb +1 -3
  110. data/spec/app/models/mdm/workspace_spec.rb +97 -100
  111. data/spec/app/models/metasploit_data_models/automatic_exploitation/match_result_spec.rb +3 -5
  112. data/spec/app/models/metasploit_data_models/automatic_exploitation/match_set_spec.rb +13 -15
  113. data/spec/app/models/metasploit_data_models/automatic_exploitation/match_spec.rb +1 -3
  114. data/spec/app/models/metasploit_data_models/automatic_exploitation/run_spec.rb +1 -3
  115. data/spec/app/models/metasploit_data_models/ip_address/v4/cidr_spec.rb +10 -12
  116. data/spec/app/models/metasploit_data_models/ip_address/v4/nmap_spec.rb +4 -6
  117. data/spec/app/models/metasploit_data_models/ip_address/v4/range_spec.rb +21 -23
  118. data/spec/app/models/metasploit_data_models/ip_address/v4/segment/nmap/list_spec.rb +9 -11
  119. data/spec/app/models/metasploit_data_models/ip_address/v4/segment/nmap/range_spec.rb +21 -23
  120. data/spec/app/models/metasploit_data_models/ip_address/v4/segment/segmented_spec.rb +4 -6
  121. data/spec/app/models/metasploit_data_models/ip_address/v4/segment/single_spec.rb +22 -15
  122. data/spec/app/models/metasploit_data_models/ip_address/v4/single_spec.rb +4 -6
  123. data/spec/app/models/metasploit_data_models/module_run_spec.rb +1 -3
  124. data/spec/app/models/metasploit_data_models/search/operation/ip_address_spec.rb +18 -20
  125. data/spec/app/models/metasploit_data_models/search/operation/port/number_spec.rb +6 -8
  126. data/spec/app/models/metasploit_data_models/search/operation/port/range_spec.rb +8 -10
  127. data/spec/app/models/metasploit_data_models/search/operation/range_spec.rb +8 -10
  128. data/spec/app/models/metasploit_data_models/search/operator/ip_address_spec.rb +2 -4
  129. data/spec/app/models/metasploit_data_models/search/operator/multitext_spec.rb +8 -10
  130. data/spec/app/models/metasploit_data_models/search/operator/port/list_spec.rb +6 -8
  131. data/spec/app/models/metasploit_data_models/search/visitor/attribute_spec.rb +9 -11
  132. data/spec/app/models/metasploit_data_models/search/visitor/includes_spec.rb +5 -7
  133. data/spec/app/models/metasploit_data_models/search/visitor/joins_spec.rb +17 -19
  134. data/spec/app/models/metasploit_data_models/search/visitor/method_spec.rb +5 -7
  135. data/spec/app/models/metasploit_data_models/search/visitor/relation_spec.rb +61 -23
  136. data/spec/app/models/metasploit_data_models/search/visitor/where_spec.rb +8 -10
  137. data/spec/app/validators/parameters_validator_spec.rb +29 -29
  138. data/spec/app/validators/password_is_strong_validator_spec.rb +54 -46
  139. data/spec/lib/base64_serializer_spec.rb +19 -21
  140. data/spec/lib/ipaddr_spec.rb +1 -3
  141. data/spec/lib/metasploit_data_models/ip_address/cidr_spec.rb +18 -12
  142. data/spec/lib/metasploit_data_models/ip_address/range_spec.rb +4 -6
  143. data/spec/lib/metasploit_data_models/match/child_spec.rb +2 -4
  144. data/spec/lib/metasploit_data_models/match/parent_spec.rb +4 -6
  145. data/spec/lib/metasploit_data_models/version_spec.rb +3 -139
  146. data/spec/lib/metasploit_data_models_spec.rb +4 -0
  147. data/spec/spec_helper.rb +86 -12
  148. data/spec/support/shared/examples/mdm/module/detail/does_not_support_stance_with_mtype.rb +2 -2
  149. data/spec/support/shared/examples/mdm/module/detail/supports_stance_with_mtype.rb +4 -4
  150. data/spec/support/shared/examples/metasploit_data_models/search/operation/ipaddress/match.rb +2 -2
  151. data/spec/support/shared/examples/metasploit_data_models/search/visitor/includes/visit/with_children.rb +5 -5
  152. data/spec/support/shared/examples/metasploit_data_models/search/visitor/includes/visit/with_metasploit_model_search_operation_base.rb +5 -5
  153. data/spec/support/shared/examples/metasploit_data_models/search/visitor/where/visit/with_equality.rb +3 -3
  154. data/spec/support/shared/examples/metasploit_data_models/search/visitor/where/visit/with_metasploit_model_search_group_base.rb +7 -6
  155. metadata +74 -14
  156. data/app/models/metasploit_data_models/automatic_exploitation.rb +0 -16
  157. data/lib/tasks/yard.rake +0 -33
@@ -1,6 +1,4 @@
1
- require 'spec_helper'
2
-
3
- describe Mdm::Host do
1
+ RSpec.describe Mdm::Host, type: :model do
4
2
  subject(:host) do
5
3
  FactoryGirl.build(:mdm_host)
6
4
  end
@@ -41,15 +39,18 @@ describe Mdm::Host do
41
39
  it_should_behave_like 'Metasploit::Concern.run'
42
40
 
43
41
  context 'factory' do
44
- it 'should be valid' do
45
- host = FactoryGirl.build(:mdm_host)
46
- host.should be_valid
42
+ context 'mdm_host' do
43
+ subject(:mdm_host) {
44
+ FactoryGirl.build(:mdm_host)
45
+ }
46
+
47
+ it { is_expected.to be_valid }
47
48
  end
48
49
  end
49
50
 
50
51
  context 'Constants' do
51
52
  subject(:max_nmap_certainty) { described_class::MAX_NMAP_CERTAINTY }
52
- it { should eq(0.84) }
53
+ it { is_expected.to eq(0.84) }
53
54
  end
54
55
 
55
56
  context '#destroy' do
@@ -103,19 +104,19 @@ describe Mdm::Host do
103
104
  end
104
105
 
105
106
  context 'associations' do
106
- it { should have_many(:creds).class_name('Mdm::Cred').through(:services) }
107
- it { should have_many(:clients).class_name('Mdm::Client').dependent(:destroy) }
108
- it { should have_many(:exploit_attempts).class_name('Mdm::ExploitAttempt').dependent(:destroy) }
109
- it { should have_many(:exploited_hosts).class_name('Mdm::ExploitedHost').dependent(:destroy) }
110
- it { should have_many(:host_details).class_name('Mdm::HostDetail').dependent(:destroy) }
111
- it { should have_many(:hosts_tags).class_name('Mdm::HostTag') }
112
- it { should have_many(:loots).class_name('Mdm::Loot').dependent(:destroy).order('loots.created_at DESC') }
113
- it { should have_many(:module_runs).class_name('MetasploitDataModels::ModuleRun') }
114
- it { should have_many(:task_hosts).class_name('Mdm::TaskHost').dependent(:destroy) }
115
- it { should have_many(:tasks).class_name('Mdm::Task').through(:task_hosts) }
107
+ it { is_expected.to have_many(:creds).class_name('Mdm::Cred').through(:services) }
108
+ it { is_expected.to have_many(:clients).class_name('Mdm::Client').dependent(:destroy) }
109
+ it { is_expected.to have_many(:exploit_attempts).class_name('Mdm::ExploitAttempt').dependent(:destroy) }
110
+ it { is_expected.to have_many(:exploited_hosts).class_name('Mdm::ExploitedHost').dependent(:destroy) }
111
+ it { is_expected.to have_many(:host_details).class_name('Mdm::HostDetail').dependent(:destroy) }
112
+ it { is_expected.to have_many(:hosts_tags).class_name('Mdm::HostTag') }
113
+ it { is_expected.to have_many(:loots).class_name('Mdm::Loot').dependent(:destroy).order('loots.created_at DESC') }
114
+ it { is_expected.to have_many(:module_runs).class_name('MetasploitDataModels::ModuleRun') }
115
+ it { is_expected.to have_many(:task_hosts).class_name('Mdm::TaskHost').dependent(:destroy) }
116
+ it { is_expected.to have_many(:tasks).class_name('Mdm::Task').through(:task_hosts) }
116
117
 
117
118
  context 'module_details' do
118
- it { should have_many(:module_details).class_name('Mdm::Module::Detail').through(:module_refs) }
119
+ it { is_expected.to have_many(:module_details).class_name('Mdm::Module::Detail').through(:module_refs) }
119
120
 
120
121
  context 'with Mdm::Vulns' do
121
122
  let!(:vulns) do
@@ -188,8 +189,8 @@ describe Mdm::Host do
188
189
  module_details << module_ref.detail
189
190
  end
190
191
 
191
- host.module_details.count.should < module_details.length
192
- module_details.uniq.count.should == host.module_details.count
192
+ expect(architectures).to include('mips')
193
+ expect(module_details.uniq.count).to eq(host.module_details.count)
193
194
  end
194
195
  end
195
196
  end
@@ -198,17 +199,17 @@ describe Mdm::Host do
198
199
  end
199
200
  end
200
201
 
201
- it { should have_many(:module_refs).class_name('Mdm::Module::Ref').through(:refs) }
202
- it { should have_many(:notes).class_name('Mdm::Note').dependent(:delete_all).order('notes.created_at') }
203
- it { should have_many(:refs).class_name('Mdm::Ref').through(:vuln_refs) }
204
- it { should have_many(:services).class_name('Mdm::Service').dependent(:destroy).order('services.port, services.proto') }
205
- it { should have_many(:service_notes).through(:services) }
206
- it { should have_many(:sessions).class_name('Mdm::Session').dependent(:destroy).order('sessions.opened_at') }
207
- it { should have_many(:tags).class_name('Mdm::Tag').through(:hosts_tags) }
208
- it { should have_many(:vulns).class_name('Mdm::Vuln').dependent(:delete_all) }
209
- it { should have_many(:vuln_refs).class_name('Mdm::VulnRef') }
210
- it { should have_many(:web_sites).class_name('Mdm::WebSite').through(:services) }
211
- it { should belong_to(:workspace).class_name('Mdm::Workspace') }
202
+ it { is_expected.to have_many(:module_refs).class_name('Mdm::Module::Ref').through(:refs) }
203
+ it { is_expected.to have_many(:notes).class_name('Mdm::Note').dependent(:delete_all).order('notes.created_at') }
204
+ it { is_expected.to have_many(:refs).class_name('Mdm::Ref').through(:vuln_refs) }
205
+ it { is_expected.to have_many(:services).class_name('Mdm::Service').dependent(:destroy).order('services.port, services.proto') }
206
+ it { is_expected.to have_many(:service_notes).through(:services) }
207
+ it { is_expected.to have_many(:sessions).class_name('Mdm::Session').dependent(:destroy).order('sessions.opened_at') }
208
+ it { is_expected.to have_many(:tags).class_name('Mdm::Tag').through(:hosts_tags) }
209
+ it { is_expected.to have_many(:vulns).class_name('Mdm::Vuln').dependent(:delete_all) }
210
+ it { is_expected.to have_many(:vuln_refs).class_name('Mdm::VulnRef') }
211
+ it { is_expected.to have_many(:web_sites).class_name('Mdm::WebSite').through(:services) }
212
+ it { is_expected.to belong_to(:workspace).class_name('Mdm::Workspace') }
212
213
  end
213
214
 
214
215
  context 'CONSTANTS' do
@@ -218,70 +219,70 @@ describe Mdm::Host do
218
219
  end
219
220
 
220
221
  it 'should be an Array<String>' do
221
- architectures.should be_an Array
222
+ expect(architectures).to include('mips')
222
223
 
223
224
  architectures.each do |architecture|
224
- architecture.should be_a String
225
+ expect(architectures).to include('mips')
225
226
  end
226
227
  end
227
228
 
228
229
  it 'should include both endians of ARM' do
229
- architectures.should include('armbe')
230
- architectures.should include('armle')
230
+ expect(architectures).to include('mips')
231
+ expect(architectures).to include('mips')
231
232
  end
232
233
 
233
234
  it 'should include 32-bit and 64-bit versions of Cell Broadband Engine Architecture' do
234
- architectures.should include('cbea')
235
- architectures.should include('cbea64')
235
+ expect(architectures).to include('mips')
236
+ expect(architectures).to include('mips')
236
237
  end
237
238
 
238
239
  it 'should include cmd for command shell' do
239
- architectures.should include('cmd')
240
+ expect(architectures).to include('mips')
240
241
  end
241
242
 
242
243
  it 'should include java for Java Virtual Machine' do
243
- architectures.should include('java')
244
+ expect(architectures).to include('mips')
244
245
  end
245
246
 
246
247
  it 'should include plain and endian-ware MIPS' do
247
- architectures.should include('mips')
248
- architectures.should include('mipsbe')
249
- architectures.should include('mipsle')
248
+ expect(architectures).to include('mips')
249
+ expect(architectures).to include('mipsbe')
250
+ expect(architectures).to include('mipsle')
250
251
  end
251
252
 
252
253
  it 'should include php for PHP code' do
253
- architectures.should include('php')
254
+ expect(architectures).to include('php')
254
255
  end
255
256
 
256
257
  it 'should include 32-bit and 64-bit PowerPC' do
257
- architectures.should include('ppc')
258
- architectures.should include('ppc64')
258
+ expect(architectures).to include('ppc')
259
+ expect(architectures).to include('ppc64')
259
260
  end
260
261
 
261
262
  it 'should include ruby for Ruby code' do
262
- architectures.should include('ruby')
263
+ expect(architectures).to include('ruby')
263
264
  end
264
265
 
265
266
  it 'should include sparc for Sparc' do
266
- architectures.should include('sparc')
267
+ expect(architectures).to include('sparc')
267
268
  end
268
269
 
269
270
  it 'should include tty for Terminals' do
270
- architectures.should include('tty')
271
+ expect(architectures).to include('tty')
271
272
  end
272
273
 
273
274
  it 'should include 32-bit and 64-bit x86' do
274
- architectures.should include('x64')
275
- architectures.should include('x86')
276
- architectures.should include('x86_64')
275
+ expect(architectures).to include('x64')
276
+ expect(architectures).to include('x86')
277
+ expect(architectures).to include('x86_64')
277
278
  end
278
279
 
279
280
  it 'should include blank string to indicate no detection has happened' do
280
- architectures.should include('')
281
+ expect(architectures).to include('')
281
282
  end
282
283
 
283
284
  it 'should include "Unknown" for failed detection attempts' do
284
- architectures.should include('Unknown')
285
+ expect(architectures).to include('Unknown')
285
286
  end
286
287
 
287
288
  end
@@ -292,71 +293,71 @@ describe Mdm::Host do
292
293
  end
293
294
 
294
295
  it 'should be an Array<String>' do
295
- search_fields.should be_an Array
296
+ expect(search_fields).to be_an Array
296
297
 
297
298
  search_fields.each { |search_field|
298
- search_field.should be_a String
299
+ expect(search_field).to be_a String
299
300
  }
300
301
  end
301
302
 
302
303
  it 'should cast address to text' do
303
- search_fields.should include('address::text')
304
+ expect(search_fields).to include('address::text')
304
305
  end
305
306
 
306
- it { should include('comments') }
307
- it { should include('mac') }
308
- it { should include('name') }
309
- it { should include('os_flavor') }
310
- it { should include('os_name') }
311
- it { should include('os_sp') }
312
- it { should include('purpose') }
307
+ it { is_expected.to include('comments') }
308
+ it { is_expected.to include('mac') }
309
+ it { is_expected.to include('name') }
310
+ it { is_expected.to include('os_flavor') }
311
+ it { is_expected.to include('os_name') }
312
+ it { is_expected.to include('os_sp') }
313
+ it { is_expected.to include('purpose') }
313
314
  end
314
315
 
315
316
  it 'should define STATES in any order' do
316
- described_class::STATES.should =~ states
317
+ expect(described_class::STATES).to match_array(states)
317
318
  end
318
319
  end
319
320
 
320
321
  context 'database' do
321
322
  context 'columns' do
322
- it { should have_db_column(:address).of_type(:inet).with_options(:null => false) }
323
- it { should have_db_column(:arch).of_type(:string) }
324
- it { should have_db_column(:comm).of_type(:string) }
325
- it { should have_db_column(:comments).of_type(:text) }
326
- it { should have_db_column(:info).of_type(:string).with_options(:limit => 2 ** 16) }
327
- it { should have_db_column(:mac).of_type(:string) }
328
- it { should have_db_column(:name).of_type(:string) }
329
- it { should have_db_column(:os_flavor).of_type(:string) }
330
- it { should have_db_column(:os_lang).of_type(:string) }
331
- it { should have_db_column(:os_name).of_type(:string) }
332
- it { should have_db_column(:os_sp).of_type(:string) }
333
- it { should have_db_column(:purpose).of_type(:text) }
334
- it { should have_db_column(:scope).of_type(:text) }
335
- it { should have_db_column(:state).of_type(:string) }
336
- it { should have_db_column(:virtual_host).of_type(:text) }
337
- it { should have_db_column(:workspace_id).of_type(:integer).with_options(:null => false) }
323
+ it { is_expected.to have_db_column(:address).of_type(:inet).with_options(:null => false) }
324
+ it { is_expected.to have_db_column(:arch).of_type(:string) }
325
+ it { is_expected.to have_db_column(:comm).of_type(:string) }
326
+ it { is_expected.to have_db_column(:comments).of_type(:text) }
327
+ it { is_expected.to have_db_column(:info).of_type(:string).with_options(:limit => 2 ** 16) }
328
+ it { is_expected.to have_db_column(:mac).of_type(:string) }
329
+ it { is_expected.to have_db_column(:name).of_type(:string) }
330
+ it { is_expected.to have_db_column(:os_flavor).of_type(:string) }
331
+ it { is_expected.to have_db_column(:os_lang).of_type(:string) }
332
+ it { is_expected.to have_db_column(:os_name).of_type(:string) }
333
+ it { is_expected.to have_db_column(:os_sp).of_type(:string) }
334
+ it { is_expected.to have_db_column(:purpose).of_type(:text) }
335
+ it { is_expected.to have_db_column(:scope).of_type(:text) }
336
+ it { is_expected.to have_db_column(:state).of_type(:string) }
337
+ it { is_expected.to have_db_column(:virtual_host).of_type(:text) }
338
+ it { is_expected.to have_db_column(:workspace_id).of_type(:integer).with_options(:null => false) }
338
339
 
339
340
  context 'counter caches' do
340
- it { should have_db_column(:exploit_attempt_count).of_type(:integer).with_options(:default => 0) }
341
- it { should have_db_column(:host_detail_count).of_type(:integer).with_options(:default => 0) }
342
- it { should have_db_column(:note_count).of_type(:integer).with_options(:default => 0) }
343
- it { should have_db_column(:service_count).of_type(:integer).with_options(:default => 0) }
344
- it { should have_db_column(:vuln_count).of_type(:integer).with_options(:default => 0) }
341
+ it { is_expected.to have_db_column(:exploit_attempt_count).of_type(:integer).with_options(:default => 0) }
342
+ it { is_expected.to have_db_column(:host_detail_count).of_type(:integer).with_options(:default => 0) }
343
+ it { is_expected.to have_db_column(:note_count).of_type(:integer).with_options(:default => 0) }
344
+ it { is_expected.to have_db_column(:service_count).of_type(:integer).with_options(:default => 0) }
345
+ it { is_expected.to have_db_column(:vuln_count).of_type(:integer).with_options(:default => 0) }
345
346
  end
346
347
 
347
348
  context 'timestamps' do
348
- it { should have_db_column(:created_at).of_type(:datetime) }
349
- it { should have_db_column(:updated_at).of_type(:datetime) }
349
+ it { is_expected.to have_db_column(:created_at).of_type(:datetime) }
350
+ it { is_expected.to have_db_column(:updated_at).of_type(:datetime) }
350
351
  end
351
352
  end
352
353
 
353
354
  context 'indices' do
354
- it { should have_db_index([:workspace_id, :address]).unique(true) }
355
- it { should have_db_index(:name) }
356
- it { should have_db_index(:os_flavor) }
357
- it { should have_db_index(:os_name) }
358
- it { should have_db_index(:purpose) }
359
- it { should have_db_index(:state) }
355
+ it { is_expected.to have_db_index([:workspace_id, :address]).unique(true) }
356
+ it { is_expected.to have_db_index(:name) }
357
+ it { is_expected.to have_db_index(:os_flavor) }
358
+ it { is_expected.to have_db_index(:os_name) }
359
+ it { is_expected.to have_db_index(:purpose) }
360
+ it { is_expected.to have_db_index(:state) }
360
361
  end
361
362
  end
362
363
 
@@ -366,7 +367,7 @@ describe Mdm::Host do
366
367
  FactoryGirl.build(:full_mdm_host)
367
368
  end
368
369
 
369
- it { should be_valid }
370
+ it { is_expected.to be_valid }
370
371
  end
371
372
 
372
373
  context 'mdm_host' do
@@ -374,14 +375,14 @@ describe Mdm::Host do
374
375
  FactoryGirl.build(:mdm_host)
375
376
  end
376
377
 
377
- it { should be_valid }
378
+ it { is_expected.to be_valid }
378
379
  end
379
380
  end
380
381
 
381
382
  context 'validations' do
382
383
  context 'address' do
383
- it { should ensure_exclusion_of(:address).in_array(['127.0.0.1']) }
384
- it { should validate_presence_of(:address) }
384
+ it { is_expected.to validate_exclusion_of(:address).in_array(['127.0.0.1']) }
385
+ it { is_expected.to validate_presence_of(:address) }
385
386
 
386
387
  # can't use validate_uniqueness_of(:address).scoped_to(:workspace_id) because it will attempt to set workspace_id
387
388
  # to `nil`, which will make the `:null => false` constraint on hosts.workspace_id to fail.
@@ -393,8 +394,8 @@ describe Mdm::Host do
393
394
 
394
395
  duplicate_host = FactoryGirl.build(:mdm_host, :address => address, :workspace => workspace)
395
396
 
396
- duplicate_host.should_not be_valid
397
- duplicate_host.errors[:address].should include('has already been taken')
397
+ expect(duplicate_host).not_to be_valid
398
+ expect(duplicate_host.errors[:address]).to include('has already been taken')
398
399
  end
399
400
  end
400
401
 
@@ -405,19 +406,20 @@ describe Mdm::Host do
405
406
  context 'with an unknown architecture' do
406
407
  let(:arch) { "asdfasdf" }
407
408
  it 'should normalize to Unknown' do
408
- host.should be_valid
409
- host.arch.should be described_class::UNKNOWN_ARCHITECTURE
409
+ expect(host).to be_valid
410
+ expect(host.arch).to be described_class::UNKNOWN_ARCHITECTURE
410
411
  end
411
412
  end
412
413
  described_class::ARCHITECTURES.each do |arch|
413
414
  context "with known architecture '#{arch}'" do
414
415
  let(:arch) { arch }
415
- it { should be_valid }
416
+ it { is_expected.to be_valid }
416
417
  end
417
418
  end
418
419
  end
419
- it { should validate_inclusion_of(:state).in_array(states).allow_nil }
420
- it { should validate_presence_of(:workspace) }
420
+
421
+ it { is_expected.to validate_inclusion_of(:state).in_array(states).allow_nil }
422
+ it { is_expected.to validate_presence_of(:workspace) }
421
423
  end
422
424
 
423
425
  context 'search scope' do
@@ -431,13 +433,13 @@ describe Mdm::Host do
431
433
 
432
434
  context 'searching for an empty string' do
433
435
  it 'should return any hosts in the database' do
434
- search_for('').should include(subject)
436
+ expect(search_for('')).to include(subject)
435
437
  end
436
438
  end
437
439
 
438
440
  context 'searching for an existing Host\'s name' do
439
441
  it 'should return the host' do
440
- search_for(subject.name).should include(subject)
442
+ expect(search_for(subject.name)).to include(subject)
441
443
  end
442
444
  end
443
445
  end
@@ -446,139 +448,139 @@ describe Mdm::Host do
446
448
  context '#get_arch_from_string' do
447
449
  context "should return 'x64'" do
448
450
  it "when the string contains 'x64'" do
449
- host.send(:get_arch_from_string, 'blahx64blah').should == 'x64'
451
+ expect(host.send(:get_arch_from_string, 'blahx64blah')).to eq('x64')
450
452
  end
451
453
 
452
454
  it "when the string contains 'X64'" do
453
- host.send(:get_arch_from_string, 'blahX64blah').should == 'x64'
455
+ expect(host.send(:get_arch_from_string, 'blahX64blah')).to eq('x64')
454
456
  end
455
457
 
456
458
  it "when the string contains 'x86_64'" do
457
- host.send(:get_arch_from_string, 'blahx86_64blah').should == 'x64'
459
+ expect(host.send(:get_arch_from_string, 'blahx86_64blah')).to eq('x64')
458
460
  end
459
461
 
460
462
  it "when the string contains 'X86_64'" do
461
- host.send(:get_arch_from_string, 'blahX86_64blah').should == 'x64'
463
+ expect(host.send(:get_arch_from_string, 'blahX86_64blah')).to eq('x64')
462
464
  end
463
465
 
464
466
  it "when the string contains 'amd64'" do
465
- host.send(:get_arch_from_string, 'blahamd64blah').should == 'x64'
467
+ expect(host.send(:get_arch_from_string, 'blahamd64blah')).to eq('x64')
466
468
  end
467
469
 
468
470
  it "when the string contains 'AMD64'" do
469
- host.send(:get_arch_from_string, 'blahAMD64blah').should == 'x64'
471
+ expect(host.send(:get_arch_from_string, 'blahAMD64blah')).to eq('x64')
470
472
  end
471
473
 
472
474
  it "when the string contains 'aMd64'" do
473
- host.send(:get_arch_from_string, 'blahamd64blah').should == 'x64'
475
+ expect(host.send(:get_arch_from_string, 'blahamd64blah')).to eq('x64')
474
476
  end
475
477
  end
476
478
 
477
479
  context "should return 'x86'" do
478
480
  it "when the string contains 'x86'" do
479
- host.send(:get_arch_from_string, 'blahx86blah').should == 'x86'
481
+ expect(host.send(:get_arch_from_string, 'blahx86blah')).to eq('x86')
480
482
  end
481
483
 
482
484
  it "when the string contains 'X86'" do
483
- host.send(:get_arch_from_string, 'blahX86blah').should == 'x86'
485
+ expect(host.send(:get_arch_from_string, 'blahX86blah')).to eq('x86')
484
486
  end
485
487
 
486
488
  it "when the string contains 'i386'" do
487
- host.send(:get_arch_from_string, 'blahi386blah').should == 'x86'
489
+ expect(host.send(:get_arch_from_string, 'blahi386blah')).to eq('x86')
488
490
  end
489
491
 
490
492
  it "when the string contains 'I386'" do
491
- host.send(:get_arch_from_string, 'blahI386blah').should == 'x86'
493
+ expect(host.send(:get_arch_from_string, 'blahI386blah')).to eq('x86')
492
494
  end
493
495
 
494
496
  it "when the string contains 'i486'" do
495
- host.send(:get_arch_from_string, 'blahi486blah').should == 'x86'
497
+ expect(host.send(:get_arch_from_string, 'blahi486blah')).to eq('x86')
496
498
  end
497
499
 
498
500
  it "when the string contains 'i586'" do
499
- host.send(:get_arch_from_string, 'blahi586blah').should == 'x86'
501
+ expect(host.send(:get_arch_from_string, 'blahi586blah')).to eq('x86')
500
502
  end
501
503
 
502
504
  it "when the string contains 'i686'" do
503
- host.send(:get_arch_from_string, 'blahi386blah').should == 'x86'
505
+ expect(host.send(:get_arch_from_string, 'blahi386blah')).to eq('x86')
504
506
  end
505
507
  end
506
508
 
507
509
  context "should return 'ppc'" do
508
510
  it "when the string contains 'PowerPC'" do
509
- host.send(:get_arch_from_string, 'blahPowerPCblah').should == 'ppc'
511
+ expect(host.send(:get_arch_from_string, 'blahPowerPCblah')).to eq('ppc')
510
512
  end
511
513
 
512
514
  it "when the string contains 'PPC'" do
513
- host.send(:get_arch_from_string, 'blahPPCblah').should == 'ppc'
515
+ expect(host.send(:get_arch_from_string, 'blahPPCblah')).to eq('ppc')
514
516
  end
515
517
 
516
518
  it "when the string contains 'POWER'" do
517
- host.send(:get_arch_from_string, 'blahPOWERblah').should == 'ppc'
519
+ expect(host.send(:get_arch_from_string, 'blahPOWERblah')).to eq('ppc')
518
520
  end
519
521
 
520
522
  it "when the string contains 'ppc'" do
521
- host.send(:get_arch_from_string, 'blahppcblah').should == 'ppc'
523
+ expect(host.send(:get_arch_from_string, 'blahppcblah')).to eq('ppc')
522
524
  end
523
525
  end
524
526
 
525
527
  context 'should return nil' do
526
528
  it 'when PowerPC is cased incorrectly' do
527
- host.send(:get_arch_from_string, 'powerPC').should == nil
528
- host.send(:get_arch_from_string, 'Powerpc').should == nil
529
+ expect(host.send(:get_arch_from_string, 'powerPC')).to eq(nil)
530
+ expect(host.send(:get_arch_from_string, 'Powerpc')).to eq(nil)
529
531
  end
530
532
 
531
533
  it 'when no recognized arch string is present' do
532
- host.send(:get_arch_from_string, 'blahblah').should == nil
534
+ expect(host.send(:get_arch_from_string, 'blahblah')).to eq(nil)
533
535
  end
534
536
  end
535
537
 
536
538
  it "should return 'sparc' if the string contains SPARC, regardless of case" do
537
- host.send(:get_arch_from_string, 'blahSPARCblah').should == 'sparc'
538
- host.send(:get_arch_from_string, 'blahSPaRCblah').should == 'sparc'
539
- host.send(:get_arch_from_string, 'blahsparcblah').should == 'sparc'
539
+ expect(host.send(:get_arch_from_string, 'blahSPARCblah')).to eq('sparc')
540
+ expect(host.send(:get_arch_from_string, 'blahSPaRCblah')).to eq('sparc')
541
+ expect(host.send(:get_arch_from_string, 'blahsparcblah')).to eq('sparc')
540
542
  end
541
543
 
542
544
  it "should return 'arm' if the string contains 'ARM', regardless of case" do
543
- host.send(:get_arch_from_string, 'blahARMblah').should == 'arm'
544
- host.send(:get_arch_from_string, 'blahArMblah').should == 'arm'
545
- host.send(:get_arch_from_string, 'blaharmblah').should == 'arm'
545
+ expect(host.send(:get_arch_from_string, 'blahARMblah')).to eq('arm')
546
+ expect(host.send(:get_arch_from_string, 'blahArMblah')).to eq('arm')
547
+ expect(host.send(:get_arch_from_string, 'blaharmblah')).to eq('arm')
546
548
  end
547
549
 
548
550
  it "should return 'mips' if the string contains 'MIPS', regardless of case" do
549
- host.send(:get_arch_from_string, 'blahMIPSblah').should == 'mips'
550
- host.send(:get_arch_from_string, 'blahMiPslah').should == 'mips'
551
- host.send(:get_arch_from_string, 'blahmipsblah').should == 'mips'
551
+ expect(host.send(:get_arch_from_string, 'blahMIPSblah')).to eq('mips')
552
+ expect(host.send(:get_arch_from_string, 'blahMiPslah')).to eq('mips')
553
+ expect(host.send(:get_arch_from_string, 'blahmipsblah')).to eq('mips')
552
554
  end
553
555
  end
554
556
 
555
557
  context '#parse_windows_os_str' do
556
558
  it 'should always return the os_name as Windows' do
557
559
  result = host.send(:parse_windows_os_str, '')
558
- result['os.product'].should == 'Windows'
560
+ expect(result['os.product']).to eq('Windows')
559
561
  end
560
562
 
561
563
  context 'arch' do
562
564
  it 'should return a value for arch if there is one' do
563
565
  result = host.send(:parse_windows_os_str, 'Windows x64')
564
- result['os.arch'].should == 'x64'
566
+ expect(result['os.arch']).to eq('x64')
565
567
  end
566
568
 
567
569
  it "should not have an arch key if we don't know the arch" do
568
570
  result = host.send(:parse_windows_os_str, 'Windows')
569
- result.has_key?('os.arch').should == false
571
+ expect(result.has_key?('os.arch')).to eq(false)
570
572
  end
571
573
  end
572
574
 
573
575
  context 'Service Pack' do
574
576
  it 'should be returned if we see Service Pack X' do
575
577
  result = host.send(:parse_windows_os_str, 'Windows XP Service Pack 1')
576
- result['os.version'].should == 'SP1'
578
+ expect(result['os.version']).to eq('SP1')
577
579
  end
578
580
 
579
581
  it 'should be returned if we see SPX' do
580
582
  result = host.send(:parse_windows_os_str, 'Windows XP SP3')
581
- result['os.version'].should == 'SP3'
583
+ expect(result['os.version']).to eq('SP3')
582
584
  end
583
585
  end
584
586
 
@@ -586,141 +588,137 @@ describe Mdm::Host do
586
588
 
587
589
  it "should appear as Windows 95 for 'Windows 95" do
588
590
  result = host.send(:parse_windows_os_str, 'Windows 95')
589
- result['os.product'].should == 'Windows 95'
591
+ expect(result['os.product']).to eq('Windows 95')
590
592
  end
591
593
 
592
594
  it "should appear as Windows NT 3.51 for 'Windows NT 3.51" do
593
595
  result = host.send(:parse_windows_os_str, 'Windows NT 3.51')
594
- result['os.product'].should == 'Windows NT 3.51'
596
+ expect(result['os.product']).to eq('Windows NT 3.51')
595
597
  end
596
598
 
597
599
  it "should appear as Windows NT 4.0 for 'Windows NT 4.0" do
598
600
  result = host.send(:parse_windows_os_str, 'Windows NT 4.0')
599
- result['os.product'].should == 'Windows NT 4.0'
601
+ expect(result['os.product']).to eq('Windows NT 4.0')
600
602
  end
601
603
 
602
604
  it "should appear as Windows 98 for 'Windows 98" do
603
605
  result = host.send(:parse_windows_os_str, 'Windows 98')
604
- result['os.product'].should == 'Windows 98'
606
+ expect(result['os.product']).to eq('Windows 98')
605
607
  end
606
608
 
607
609
  it "should appear as Windows ME for 'Windows ME" do
608
610
  result = host.send(:parse_windows_os_str, 'Windows ME')
609
- result['os.product'].should == 'Windows ME'
611
+ expect(result['os.product']).to eq('Windows ME')
610
612
  end
611
613
 
612
614
  it "should appear as Windows 2003 for '.NET Server'" do
613
615
  result = host.send(:parse_windows_os_str, 'Windows .NET Server')
614
- result['os.product'].should == 'Windows Server 2003'
616
+ expect(result['os.product']).to eq('Windows Server 2003')
615
617
  end
616
618
 
617
619
  it 'should be recognized for Windows XP' do
618
620
  result = host.send(:parse_windows_os_str, 'Windows XP')
619
- result['os.product'].should == 'Windows XP'
621
+ expect(result['os.product']).to eq('Windows XP')
620
622
  end
621
623
 
622
624
  it 'should be recognized for Windows Server 2000' do
623
625
  result = host.send(:parse_windows_os_str, 'Windows 2000')
624
- result['os.product'].should == 'Windows Server 2000'
626
+ expect(result['os.product']).to eq('Windows Server 2000')
625
627
  end
626
628
 
627
629
  it 'should be recognized for Windows Server 2003' do
628
630
  result = host.send(:parse_windows_os_str, 'Windows 2003')
629
- result['os.product'].should == 'Windows Server 2003'
631
+ expect(result['os.product']).to eq('Windows Server 2003')
630
632
  end
631
633
 
632
634
  it 'should be recognized for Windows 2008' do
633
635
  result = host.send(:parse_windows_os_str, 'Windows 2008')
634
- result['os.product'].should == 'Windows Server 2008'
636
+ expect(result['os.product']).to eq('Windows Server 2008')
635
637
  end
636
638
 
637
639
  it 'should be recognized for Windows 2012' do
638
640
  result = host.send(:parse_windows_os_str, 'Windows 2012')
639
- result['os.product'].should == 'Windows Server 2012'
641
+ expect(result['os.product']).to eq('Windows Server 2012')
640
642
  end
641
643
 
642
644
  it 'should be recognized for Windows Vista' do
643
645
  result = host.send(:parse_windows_os_str, 'Windows Vista')
644
- result['os.product'].should == 'Windows Vista'
646
+ expect(result['os.product']).to eq('Windows Vista')
645
647
  end
646
648
 
647
649
  it 'should be recognized for Windows Server 2000' do
648
650
  result = host.send(:parse_windows_os_str, 'Windows 2000 Advanced Server')
649
- result['os.product'].should == 'Windows Server 2000'
651
+ expect(result['os.product']).to eq('Windows Server 2000')
650
652
  end
651
653
 
652
654
  it 'should be recognized for Windows 7' do
653
655
  result = host.send(:parse_windows_os_str, 'Windows 7')
654
- result['os.product'].should == 'Windows 7'
656
+ expect(result['os.product']).to eq('Windows 7')
655
657
  end
656
658
 
657
659
  it 'should be recognized for Windows 7 Ultimate Edition' do
658
660
  result = host.send(:parse_windows_os_str, 'Windows 7 Ultimate Edition')
659
- result['os.product'].should == 'Windows 7'
660
- result['os.edition'].should == 'Ultimate'
661
+ expect(result['os.product']).to eq('Windows 7')
662
+ expect(result['os.edition']).to eq('Ultimate')
661
663
  end
662
664
 
663
665
  it 'should be recognized for Windows 8' do
664
666
  result = host.send(:parse_windows_os_str, 'Windows 8')
665
- result['os.product'].should == 'Windows 8'
667
+ expect(result['os.product']).to eq('Windows 8')
666
668
  end
667
669
 
668
670
  it 'should be recognized for Windows 8.1' do
669
671
  result = host.send(:parse_windows_os_str, 'Windows 8.1')
670
- result['os.product'].should == 'Windows 8.1'
672
+ expect(result['os.product']).to eq('Windows 8.1')
671
673
  end
672
674
 
673
675
  it 'should be recognized for Windows 8.2' do
674
676
  result = host.send(:parse_windows_os_str, 'Windows 8.2')
675
- result['os.product'].should == 'Windows 8.2'
677
+ expect(result['os.product']).to eq('Windows 8.2')
676
678
  end
677
679
 
678
680
  it 'should be recognized as Windows XP, Build 2600, SP3' do
679
681
  result = host.send(:parse_windows_os_str, 'Windows XP (Build 2600, Service Pack 3).')
680
- result['os.product'].should == 'Windows XP'
681
- result['os.build'].should == '2600'
682
- result['os.version'].should == 'SP3'
682
+ expect(result['os.product']).to eq('Windows XP')
683
+ expect(result['os.build']).to eq('2600')
684
+ expect(result['os.version']).to eq('SP3')
683
685
  end
684
686
 
685
687
  it 'should be recognized as Windows Server 2003, Build 3790' do
686
688
  result = host.send(:parse_windows_os_str, 'Windows .NET Server (Build 3790).')
687
- result['os.product'].should == 'Windows Server 2003'
688
- result['os.build'].should == '3790'
689
+ expect(result['os.product']).to eq('Windows Server 2003')
690
+ expect(result['os.build']).to eq('3790')
689
691
  end
690
692
 
691
693
  it 'should be recognized as Windows Server 2008, Build 6001, SP1' do
692
694
  result = host.send(:parse_windows_os_str, 'Windows 2008 (Build 6001, Service Pack 1).')
693
- result['os.product'].should == 'Windows Server 2008'
694
- result['os.build'].should == '6001'
695
- result['os.version'].should == 'SP1'
695
+ expect(result['os.product']).to eq('Windows Server 2008')
696
+ expect(result['os.build']).to eq('6001')
697
+ expect(result['os.version']).to eq('SP1')
696
698
  end
697
699
 
698
700
  it 'should default to Windows <name> if all else fails' do
699
701
  result = host.send(:parse_windows_os_str, 'Windows Foobar Service Pack 3')
700
- result['os.product'].should == 'Windows Foobar'
701
- result['os.version'].should == 'SP3'
702
+ expect(result['os.product']).to eq('Windows Foobar')
703
+ expect(result['os.version']).to eq('SP3')
702
704
  end
703
705
  end
704
706
  end
705
707
 
706
708
  context '#validate_fingerprint_data' do
707
- before(:each) do
708
- host.stub(:dlog)
709
- end
710
-
711
709
  it 'should return false for an empty hash' do
712
710
  fingerprint= FactoryGirl.build(:mdm_note, :data => {})
713
- host.validate_fingerprint_data(fingerprint).should == false
711
+ expect(host.validate_fingerprint_data(fingerprint)).to eq(false)
714
712
  end
715
713
 
716
714
  it 'should return false for postgresql fingerprints' do
717
715
  fingerprint= FactoryGirl.build(:mdm_note, :ntype => 'postgresql.fingerprint', :data => {})
718
- host.validate_fingerprint_data(fingerprint).should == false
716
+ expect(host.validate_fingerprint_data(fingerprint)).to eq(false)
719
717
  end
720
718
 
721
719
  it 'should return false if the fingerprint does not contain a hash' do
722
720
  fingerprint= FactoryGirl.build(:mdm_note, :data => 'this is not a fingerprint')
723
- host.validate_fingerprint_data(fingerprint).should == false
721
+ expect(host.validate_fingerprint_data(fingerprint)).to eq(false)
724
722
  end
725
723
  end
726
724
 
@@ -728,91 +726,95 @@ describe Mdm::Host do
728
726
  context '#apply_match_to_host' do
729
727
 
730
728
  before(:each) do
731
- stub_const('Rex::Text', Module.new)
732
- allow(Rex::Text).to receive(:ascii_safe_hex) do |unsanitized|
733
- # Pass back the sanitized value for the stub
734
- unsanitized.unpack("C*").pack("C*").gsub(/([\x00-\x08\x0b\x0c\x0e-\x1f\x80-\xFF])/n){ |x| "\\x%.2x" % x.unpack("C*")[0]}
735
- end
729
+ stub_const(
730
+ 'Rex::Text',
731
+ Module.new do
732
+ def self.ascii_safe_hex(unsanitized)
733
+ # Pass back the sanitized value for the stub
734
+ unsanitized.unpack("C*").pack("C*").gsub(/([\x00-\x08\x0b\x0c\x0e-\x1f\x80-\xFF])/n){ |x| "\\x%.2x" % x.unpack("C*")[0]}
735
+ end
736
+ end
737
+ )
736
738
  end
737
739
 
738
740
  it 'should set host.mac when host.mac is present' do
739
741
  match = { 'host.mac' => '00:11:22:33:44:55' }
740
742
  host.send(:apply_match_to_host, match)
741
- host.mac.should == '00:11:22:33:44:55'
743
+ expect(host.mac).to eq('00:11:22:33:44:55')
742
744
  end
743
745
 
744
746
  it 'should set host.name when host.name is present' do
745
747
  match = { 'host.name' => 'webbyweb' }
746
748
  host.send(:apply_match_to_host, match)
747
- host.name.should == 'webbyweb'
749
+ expect(host.name).to eq('webbyweb')
748
750
  end
749
751
 
750
752
  it 'should set host.arch when os.arch is present' do
751
753
  match = { 'os.arch' => 'x86' }
752
754
  host.send(:apply_match_to_host, match)
753
- host.arch.should == 'x86'
755
+ expect(host.arch).to eq('x86')
754
756
  end
755
757
 
756
758
  it 'should set host.name to an escaped hex value when host.name contains high bytes' do
757
759
  match = { 'host.name' => "HighBytes\xff\xf0".force_encoding('binary') }
758
760
  host.send(:apply_match_to_host, match)
759
- host.name.should == "HighBytes\\xff\\xf0"
761
+ expect(host.name).to eq("HighBytes\\xff\\xf0")
760
762
  end
761
763
 
762
764
  it 'should set host.purpose to client when os.product is Windows XP' do
763
765
  match = { 'os.product' => 'Windows XP' }
764
766
  host.send(:apply_match_to_host, match)
765
- host.os_name.should == 'Windows XP'
766
- host.purpose.should == 'client'
767
+ expect(host.os_name).to eq('Windows XP')
768
+ expect(host.purpose).to eq('client')
767
769
  end
768
770
 
769
771
  it 'should set host.purpose to server when os.product is Windows 2012' do
770
772
  match = { 'os.product' => 'Windows 2012' }
771
773
  host.send(:apply_match_to_host, match)
772
- host.os_name.should == 'Windows 2012'
773
- host.purpose.should == 'server'
774
+ expect(host.os_name).to eq('Windows 2012')
775
+ expect(host.purpose).to eq('server')
774
776
  end
775
777
 
776
778
  it 'should set host.purpose to printer when os.device is Print server' do
777
779
  match = { 'os.device' => 'Print server' }
778
780
  host.send(:apply_match_to_host, match)
779
- host.purpose.should == 'printer'
781
+ expect(host.purpose).to eq('printer')
780
782
  end
781
783
 
782
784
  it 'should set host.os_lang to English when os.language is English' do
783
785
  match = { 'os.language' => 'English' }
784
786
  host.send(:apply_match_to_host, match)
785
- host.os_lang.should == 'English'
787
+ expect(host.os_lang).to eq('English')
786
788
  end
787
789
 
788
790
  it 'should set host.os_name to Windows 8.1 when os.product is Windows 8.1' do
789
791
  match = { 'os.product' => 'Windows 8.1' }
790
792
  host.send(:apply_match_to_host, match)
791
- host.os_name.should == 'Windows 8.1'
793
+ expect(host.os_name).to eq('Windows 8.1')
792
794
  end
793
795
 
794
796
  it 'should set host.os_name to Windows when os.product is not set and os.family is Windows' do
795
797
  match = { 'os.family' => 'Windows' }
796
798
  host.send(:apply_match_to_host, match)
797
- host.os_name.should == 'Windows'
799
+ expect(host.os_name).to eq('Windows')
798
800
  end
799
801
 
800
802
  it 'should set host.os_flavor to Professional when os.edition is Professional' do
801
803
  match = { 'os.edition' => 'Professional' }
802
804
  host.send(:apply_match_to_host, match)
803
- host.os_flavor.should == 'Professional'
805
+ expect(host.os_flavor).to eq('Professional')
804
806
  end
805
807
 
806
808
  it 'should set host.os_sp to SP2 when os.version is SP2' do
807
809
  match = { 'os.version' => 'SP2' }
808
810
  host.send(:apply_match_to_host, match)
809
- host.os_sp.should == 'SP2'
811
+ expect(host.os_sp).to eq('SP2')
810
812
  end
811
813
 
812
814
  it 'should set host.os_sp to 3.2.11 when os.version is nil and linux.kernel.version is 3.2.11' do
813
815
  match = { 'linux.kernel.version' => '3.2.11' }
814
816
  host.send(:apply_match_to_host, match)
815
- host.os_sp.should == '3.2.11'
817
+ expect(host.os_sp).to eq('3.2.11')
816
818
  end
817
819
  end
818
820
 
@@ -821,33 +823,33 @@ describe Mdm::Host do
821
823
  it 'should convert Service Pack X to SPX' do
822
824
  match = { 'os.version' => 'Service Pack 2' }
823
825
  result = host.send(:normalize_match, match)
824
- result['os.version'].should == 'SP2'
826
+ expect(result['os.version']).to eq('SP2')
825
827
  end
826
828
 
827
829
  it 'should not convert No Service Pack to SP' do
828
830
  match = { 'os.version' => 'No Service Pack' }
829
831
  result = host.send(:normalize_match, match)
830
- result['os.version'].should == 'No Service Pack'
832
+ expect(result['os.version']).to eq('No Service Pack')
831
833
  end
832
834
 
833
835
  it 'should convert Apple Mac OS X to Mac OS X' do
834
836
  match = { 'os.product' => 'Apple Mac OS X' }
835
837
  result = host.send(:normalize_match, match)
836
- result['os.product'].should == 'Mac OS X'
837
- result['os.vendor'].should == 'Apple'
838
+ expect(result['os.product']).to eq('Mac OS X')
839
+ expect(result['os.vendor']).to eq('Apple')
838
840
  end
839
841
 
840
842
  it 'should convert Microsoft Windows to Windows' do
841
843
  match = { 'os.product' => 'Microsoft Windows 7' }
842
844
  result = host.send(:normalize_match, match)
843
- result['os.product'].should == 'Windows 7'
844
- result['os.vendor'].should == 'Microsoft'
845
+ expect(result['os.product']).to eq('Windows 7')
846
+ expect(result['os.vendor']).to eq('Microsoft')
845
847
  end
846
848
 
847
849
  it 'should convert Windows Server 2012 to Windows 2012' do
848
850
  match = { 'os.product' => 'Windows Server 2012' }
849
851
  result = host.send(:normalize_match, match)
850
- result['os.product'].should == 'Windows 2012'
852
+ expect(result['os.product']).to eq('Windows 2012')
851
853
  end
852
854
  end
853
855
 
@@ -856,55 +858,55 @@ describe Mdm::Host do
856
858
  it 'should detect Windows XP as a client' do
857
859
  match = { 'os.product' => 'Windows XP' }
858
860
  result = host.send(:guess_purpose_from_match, match)
859
- result.should == 'client'
861
+ expect(result).to eq('client')
860
862
  end
861
863
 
862
864
  it 'should detect Windows 8.1 as a client' do
863
865
  match = { 'os.product' => 'Windows 8.1' }
864
866
  result = host.send(:guess_purpose_from_match, match)
865
- result.should == 'client'
867
+ expect(result).to eq('client')
866
868
  end
867
869
 
868
870
  it 'should detect Windows 2000 as a server' do
869
871
  match = { 'os.product' => 'Windows 2000' }
870
872
  result = host.send(:guess_purpose_from_match, match)
871
- result.should == 'server'
873
+ expect(result).to eq('server')
872
874
  end
873
875
 
874
876
  it 'should detect Windows Server 2012 as a server' do
875
877
  match = { 'os.product' => 'Windows Server 2012' }
876
878
  result = host.send(:guess_purpose_from_match, match)
877
- result.should == 'server'
879
+ expect(result).to eq('server')
878
880
  end
879
881
 
880
882
  it 'should detect Linux as a server' do
881
883
  match = { 'os.product' => 'Linux' }
882
884
  result = host.send(:guess_purpose_from_match, match)
883
- result.should == 'server'
885
+ expect(result).to eq('server')
884
886
  end
885
887
 
886
888
  it 'should detect JetDirect as a printer' do
887
889
  match = { 'os.product' => 'JetDirect', 'os.device' => 'Print server' }
888
890
  result = host.send(:guess_purpose_from_match, match)
889
- result.should == 'printer'
891
+ expect(result).to eq('printer')
890
892
  end
891
893
 
892
894
  it 'should detect Unknown Printer as a printer' do
893
895
  match = { 'os.product' => 'Unknown Printer' }
894
896
  result = host.send(:guess_purpose_from_match, match)
895
- result.should == 'printer'
897
+ expect(result).to eq('printer')
896
898
  end
897
899
 
898
900
  it 'should detect Linksys Router as a router' do
899
901
  match = { 'os.product' => 'Linksys', 'os.device' => 'Router' }
900
902
  result = host.send(:guess_purpose_from_match, match)
901
- result.should == 'router'
903
+ expect(result).to eq('router')
902
904
  end
903
905
 
904
906
  it 'should detect CheckPoint Firewall-1 as a firewall' do
905
907
  match = { 'os.vendor' => 'Check Point', 'os.product' => 'Firewall-1' }
906
908
  result = host.send(:guess_purpose_from_match, match)
907
- result.should == 'firewall'
909
+ expect(result).to eq('firewall')
908
910
  end
909
911
  end
910
912
 
@@ -913,22 +915,22 @@ describe Mdm::Host do
913
915
  it 'should return all the correct data for Windows XP SP3 x86' do
914
916
  fingerprint = FactoryGirl.build(:mdm_session_fingerprint, :host => host)
915
917
  result = host.send(:normalize_scanner_fp, fingerprint).first
916
- result['os.product'].should == 'Windows XP'
917
- result['os.version'].should == 'SP3'
918
- result['os.arch'].should == 'x86'
919
- result['host.name'].should == nil
920
- result['os.certainty'].to_f.should == 0.8
918
+ expect(result['os.product']).to eq('Windows XP')
919
+ expect(result['os.version']).to eq('SP3')
920
+ expect(result['os.arch']).to eq('x86')
921
+ expect(result['host.name']).to eq(nil)
922
+ expect(result['os.certainty'].to_f).to eq(0.8)
921
923
  end
922
924
 
923
925
  it 'should return all the correct data for Windows 2008 SP1 x64' do
924
926
  fp_data = { :os => 'Microsoft Windows 2008 SP1', :arch => 'x64'}
925
927
  fingerprint = FactoryGirl.build(:mdm_session_fingerprint, :host => host, :data => fp_data)
926
928
  result = host.send(:normalize_scanner_fp, fingerprint).first
927
- result['os.product'].should == 'Windows Server 2008'
928
- result['os.version'].should == 'SP1'
929
- result['os.arch'].should == 'x64'
930
- result['host.name'].should == nil
931
- result['os.certainty'].to_f.should == 0.8
929
+ expect(result['os.product']).to eq('Windows Server 2008')
930
+ expect(result['os.version']).to eq('SP1')
931
+ expect(result['os.arch']).to eq('x64')
932
+ expect(result['host.name']).to eq(nil)
933
+ expect(result['os.certainty'].to_f).to eq(0.8)
932
934
  end
933
935
 
934
936
  it 'should fingerprint Metasploitable correctly' do
@@ -936,21 +938,21 @@ describe Mdm::Host do
936
938
  fp_data = { :os => 'Linux 2.6.24-16-server (i386)', :name => 'metasploitable'}
937
939
  fingerprint = FactoryGirl.build(:mdm_session_fingerprint, :host => host, :data => fp_data)
938
940
  result = host.send(:normalize_scanner_fp, fingerprint).first
939
- result['os.product'].should == 'Linux'
940
- result['host.name'].should == 'metasploitable'
941
- result['os.version'].should == '2.6.24-16-server'
942
- result['os.arch'].should == 'x86'
943
- result['os.certainty'].to_f.should == 0.8
941
+ expect(result['os.product']).to eq('Linux')
942
+ expect(result['host.name']).to eq('metasploitable')
943
+ expect(result['os.version']).to eq('2.6.24-16-server')
944
+ expect(result['os.arch']).to eq('x86')
945
+ expect(result['os.certainty'].to_f).to eq(0.8)
944
946
  end
945
947
 
946
948
  it 'should just populate os_name if it is unsure' do
947
949
  fp_data = { :os => 'Darwin 12.3.0 x86_64 i386'}
948
950
  fingerprint = FactoryGirl.build(:mdm_session_fingerprint, :host => host, :data => fp_data)
949
951
  result = host.send(:normalize_scanner_fp, fingerprint).first
950
- result['os.product'].should == 'Darwin 12.3.0 x86_64 i386'
951
- result['os.version'].should == nil
952
- result['os.arch'].should == nil
953
- result['os.certainty'].should == 0.8
952
+ expect(result['os.product']).to eq('Darwin 12.3.0 x86_64 i386')
953
+ expect(result['os.version']).to eq(nil)
954
+ expect(result['os.arch']).to eq(nil)
955
+ expect(result['os.certainty']).to eq(0.8)
954
956
  end
955
957
  end
956
958
 
@@ -958,27 +960,27 @@ describe Mdm::Host do
958
960
  it 'should return OS name for a Windows XP fingerprint' do
959
961
  fingerprint = FactoryGirl.build(:mdm_nmap_fingerprint, :host => host)
960
962
  result = host.send(:normalize_scanner_fp, fingerprint).first
961
- result['os.product'].should == 'Windows XP'
962
- result['os.certainty'].to_f.should == described_class::MAX_NMAP_CERTAINTY
963
+ expect(result['os.product']).to eq('Windows XP')
964
+ expect(result['os.certainty'].to_f).to eq(described_class::MAX_NMAP_CERTAINTY)
963
965
  end
964
966
 
965
967
  it 'should return OS name for a Metasploitable fingerprint' do
966
968
  fp_data = {:os_vendor=>"Linux", :os_family=>"Linux", :os_version=>"2.6.X", :os_accuracy=>100}
967
969
  fingerprint = FactoryGirl.build(:mdm_nmap_fingerprint, :host => host, :data => fp_data)
968
970
  result = host.send(:normalize_scanner_fp, fingerprint).first
969
- result['os.product'].should == 'Linux'
970
- result['os.version'].should == '2.6.X'
971
- result['os.certainty'].to_f.should == described_class::MAX_NMAP_CERTAINTY
971
+ expect(result['os.product']).to eq('Linux')
972
+ expect(result['os.version']).to eq('2.6.X')
973
+ expect(result['os.certainty'].to_f).to eq(described_class::MAX_NMAP_CERTAINTY)
972
974
  end
973
975
 
974
976
  it 'should return OS name and flavor fo an OSX fingerprint' do
975
977
  fp_data = {:os_vendor=>"Apple", :os_family=>"Mac OS X", :os_version=>"10.8.X", :os_accuracy=>100}
976
978
  fingerprint = FactoryGirl.build(:mdm_nmap_fingerprint, :host => host, :data => fp_data)
977
979
  result = host.send(:normalize_scanner_fp, fingerprint).first
978
- result['os.product'].should == 'Mac OS X'
979
- result['os.vendor'].should == 'Apple'
980
- result['os.version'].should == '10.8.X'
981
- result['os.certainty'].to_f.should == described_class::MAX_NMAP_CERTAINTY
980
+ expect(result['os.product']).to eq('Mac OS X')
981
+ expect(result['os.vendor']).to eq('Apple')
982
+ expect(result['os.version']).to eq('10.8.X')
983
+ expect(result['os.certainty'].to_f).to eq(described_class::MAX_NMAP_CERTAINTY)
982
984
  end
983
985
  end
984
986
 
@@ -987,19 +989,19 @@ describe Mdm::Host do
987
989
  it 'should return a generic Windows fingerprint with no product info' do
988
990
  fingerprint = FactoryGirl.build(:mdm_nexpose_fingerprint, :host => host)
989
991
  result = host.send(:normalize_scanner_fp, fingerprint).first
990
- result['os.product'].should == 'Windows'
991
- result['os.arch'].should == 'x86'
992
- result['os.certainty'].to_f.should == 0.67
992
+ expect(result['os.product']).to eq('Windows')
993
+ expect(result['os.arch']).to eq('x86')
994
+ expect(result['os.certainty'].to_f).to eq(0.67)
993
995
  end
994
996
 
995
997
  it 'should recognize a Windows 7 fingerprint' do
996
998
  fp_data = {:family=>"Windows", :certainty=>"0.67", :vendor=>"Microsoft", :arch=>"x86", :product => 'Windows 7', :version => 'SP1'}
997
999
  fingerprint = FactoryGirl.build(:mdm_nexpose_fingerprint, :host => host, :data => fp_data)
998
1000
  result = host.send(:normalize_scanner_fp, fingerprint).first
999
- result['os.product'].should == 'Windows 7'
1000
- result['os.version'].should == 'SP1'
1001
- result['os.arch'].should == 'x86'
1002
- result['os.certainty'].to_f.should == 0.67
1001
+ expect(result['os.product']).to eq('Windows 7')
1002
+ expect(result['os.version']).to eq('SP1')
1003
+ expect(result['os.arch']).to eq('x86')
1004
+ expect(result['os.certainty'].to_f).to eq(0.67)
1003
1005
  end
1004
1006
  end
1005
1007
 
@@ -1007,30 +1009,30 @@ describe Mdm::Host do
1007
1009
  fp_data = {:family=>"Mac OS X", :certainty=>"0.80", :vendor=>"Apple"}
1008
1010
  fingerprint = FactoryGirl.build(:mdm_nexpose_fingerprint, :host => host, :data => fp_data)
1009
1011
  result = host.send(:normalize_scanner_fp, fingerprint).first
1010
- result['os.product'].should == 'Mac OS X'
1011
- result['os.vendor'].should == "Apple"
1012
+ expect(result['os.product']).to eq('Mac OS X')
1013
+ expect(result['os.vendor']).to eq("Apple")
1012
1014
  end
1013
1015
 
1014
1016
  it 'should recognize a Cisco fingerprint' do
1015
1017
  fp_data = {:family=>"IOS", :certainty=>"1.00", :vendor=>"Cisco", :version=>"11.2(8)SA2"}
1016
1018
  fingerprint = FactoryGirl.build(:mdm_nexpose_fingerprint, :host => host, :data => fp_data)
1017
1019
  result = host.send(:normalize_scanner_fp, fingerprint).first
1018
- result['os.product'].should == 'IOS'
1019
- result['os.vendor'].should == 'Cisco'
1020
+ expect(result['os.product']).to eq('IOS')
1021
+ expect(result['os.vendor']).to eq('Cisco')
1020
1022
  end
1021
1023
 
1022
1024
  it 'should recognize an embedded fingerprint' do
1023
1025
  fp_data = {:family=>"embedded", :certainty=>"1.00", :vendor=>"Footek"}
1024
1026
  fingerprint = FactoryGirl.build(:mdm_nexpose_fingerprint, :host => host, :data => fp_data)
1025
1027
  result = host.send(:normalize_scanner_fp, fingerprint).first
1026
- result['os.product'].should == 'Footek'
1028
+ expect(result['os.product']).to eq('Footek')
1027
1029
  end
1028
1030
 
1029
1031
  it 'should handle an unknown fingerprint' do
1030
1032
  fp_data = {:certainty=>"1.00", :vendor=>"Footek"}
1031
1033
  fingerprint = FactoryGirl.build(:mdm_nexpose_fingerprint, :host => host, :data => fp_data)
1032
1034
  result = host.send(:normalize_scanner_fp, fingerprint).first
1033
- result['os.product'].should == 'Footek'
1035
+ expect(result['os.product']).to eq('Footek')
1034
1036
  end
1035
1037
 
1036
1038
 
@@ -1040,18 +1042,18 @@ describe Mdm::Host do
1040
1042
  it 'should recognize a Windows fingerprint' do
1041
1043
  fingerprint = FactoryGirl.build(:mdm_retina_fingerprint, :host => host)
1042
1044
  result = host.send(:normalize_scanner_fp, fingerprint).first
1043
- result['os.product'].should == 'Windows Server 2003'
1044
- result['os.arch'].should == 'x64'
1045
- result['os.version'].should == 'SP2'
1046
- result['os.certainty'].to_f.should == 0.8
1045
+ expect(result['os.product']).to eq( 'Windows Server 2003')
1046
+ expect(result['os.arch']).to eq('x64')
1047
+ expect(result['os.version']).to eq('SP2')
1048
+ expect(result['os.certainty'].to_f).to eq(0.8)
1047
1049
  end
1048
1050
 
1049
1051
  it 'should otherwise jsut copy the fingerprint to os_name' do
1050
1052
  fp_data = { :os => 'Linux 2.6.X (i386)'}
1051
1053
  fingerprint = FactoryGirl.build(:mdm_retina_fingerprint, :host => host, :data => fp_data)
1052
1054
  result = host.send(:normalize_scanner_fp, fingerprint).first
1053
- result['os.product'].should == 'Linux 2.6.X (i386)'
1054
- result['os.certainty'].to_f.should == 0.8
1055
+ expect(result['os.product']).to eq( 'Linux 2.6.X (i386)')
1056
+ expect(result['os.certainty'].to_f).to eq(0.8)
1055
1057
  end
1056
1058
  end
1057
1059
  end