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 MetasploitDataModels::Search::Visitor::Where do
1
+ RSpec.describe MetasploitDataModels::Search::Visitor::Where, type: :model do
4
2
  subject(:visitor) do
5
3
  described_class.new
6
4
  end
@@ -12,7 +10,7 @@ describe MetasploitDataModels::Search::Visitor::Where do
12
10
  visitor.attribute_visitor
13
11
  end
14
12
 
15
- it { should be_a MetasploitDataModels::Search::Visitor::Attribute }
13
+ it { is_expected.to be_a MetasploitDataModels::Search::Visitor::Attribute }
16
14
  end
17
15
 
18
16
  context '#method_visitor' do
@@ -20,7 +18,7 @@ describe MetasploitDataModels::Search::Visitor::Where do
20
18
  visitor.method_visitor
21
19
  end
22
20
 
23
- it { should be_a MetasploitDataModels::Search::Visitor::Method }
21
+ it { is_expected.to be_a MetasploitDataModels::Search::Visitor::Method }
24
22
  end
25
23
 
26
24
  context '#visit' do
@@ -84,16 +82,16 @@ describe MetasploitDataModels::Search::Visitor::Where do
84
82
  end
85
83
 
86
84
  it 'should visit operation.operator with attribute_visitor' do
87
- visitor.attribute_visitor.should_receive(:visit).with(operator).and_call_original
85
+ expect(visitor.attribute_visitor).to receive(:visit).with(operator).and_call_original
88
86
 
89
87
  visit
90
88
  end
91
89
 
92
90
  it 'should call matches on Arel::Attributes::Attribute from attribute_visitor' do
93
91
  attribute = double('Visited Operator')
94
- visitor.attribute_visitor.stub(:visit).with(operator).and_return(attribute)
92
+ allow(visitor.attribute_visitor).to receive(:visit).with(operator).and_return(attribute)
95
93
 
96
- attribute.should_receive(:matches).with("%#{value}%")
94
+ expect(attribute).to receive(:matches).with("%#{value}%")
97
95
 
98
96
  visit
99
97
  end
@@ -165,7 +163,7 @@ describe MetasploitDataModels::Search::Visitor::Where do
165
163
  end
166
164
 
167
165
  it 'should match module_instances.name with ILIKE' do
168
- visit.to_sql.should == "\"hosts\".\"name\" ILIKE '%#{name}%'"
166
+ expect(visit.to_sql).to eq("\"hosts\".\"name\" ILIKE '%#{name}%'")
169
167
  end
170
168
  end
171
169
 
@@ -179,7 +177,7 @@ describe MetasploitDataModels::Search::Visitor::Where do
179
177
  end
180
178
 
181
179
  it 'should match module_actions.name with ILIKE' do
182
- visit.to_sql.should == "\"services\".\"name\" ILIKE '%#{name}%'"
180
+ expect(visit.to_sql).to eq("\"services\".\"name\" ILIKE '%#{name}%'")
183
181
  end
184
182
  end
185
183
  end
@@ -1,6 +1,4 @@
1
- require 'spec_helper'
2
-
3
- describe ParametersValidator do
1
+ RSpec.describe ParametersValidator do
4
2
  subject(:parameters_validator) do
5
3
  described_class.new(
6
4
  :attributes => attributes
@@ -29,7 +27,7 @@ describe ParametersValidator do
29
27
 
30
28
  context 'CONSTANTS' do
31
29
  it 'should define TYPE_SIGNATURE_SENTENCE' do
32
- described_class::TYPE_SIGNATURE_SENTENCE.should == type_signature_sentence
30
+ expect(described_class::TYPE_SIGNATURE_SENTENCE).to eq(type_signature_sentence)
33
31
  end
34
32
  end
35
33
 
@@ -48,7 +46,7 @@ describe ParametersValidator do
48
46
  end
49
47
 
50
48
  it 'should include prefix' do
51
- error_at.should include(prefix)
49
+ expect(error_at).to include(prefix)
52
50
  end
53
51
 
54
52
  it 'should include location_clause in same sentence as prefix' do
@@ -58,11 +56,11 @@ describe ParametersValidator do
58
56
  :index => index
59
57
  )
60
58
 
61
- error_at.should include("#{prefix} #{location_clause}.")
59
+ expect(error_at).to include("#{prefix} #{location_clause}.")
62
60
  end
63
61
 
64
62
  it 'should include TYPE_SIGNATURE_SENTENCE' do
65
- error_at.should include(type_signature_sentence)
63
+ expect(error_at).to include(type_signature_sentence)
66
64
  end
67
65
  end
68
66
 
@@ -81,9 +79,9 @@ describe ParametersValidator do
81
79
  end
82
80
 
83
81
  it 'should include extreme in prefix' do
84
- parameters_validator.should_receive(:error_at) do |*args|
82
+ expect(parameters_validator).to receive(:error_at) do |*args|
85
83
  options = args.first
86
- options[:prefix].should include(extreme.to_s)
84
+ expect(options[:prefix]).to include(extreme.to_s)
87
85
  end
88
86
 
89
87
  length_error_at
@@ -100,11 +98,11 @@ describe ParametersValidator do
100
98
  end
101
99
 
102
100
  it 'should include numerical index' do
103
- location_clause.should include("at index #{index}")
101
+ expect(location_clause).to include("at index #{index}")
104
102
  end
105
103
 
106
104
  it 'should include inspect of element' do
107
- location_clause.should include(element.inspect)
105
+ expect(location_clause).to include(element.inspect)
108
106
  end
109
107
  end
110
108
 
@@ -144,7 +142,7 @@ describe ParametersValidator do
144
142
  end
145
143
 
146
144
  it 'should call #length_error_at with :extreme => :few' do
147
- parameters_validator.should_receive(:length_error_at).with(
145
+ expect(parameters_validator).to receive(:length_error_at).with(
148
146
  hash_including(
149
147
  :extreme => :few
150
148
  )
@@ -156,7 +154,7 @@ describe ParametersValidator do
156
154
  it 'should record error' do
157
155
  validate_each
158
156
 
159
- errors.should_not be_empty
157
+ expect(errors).not_to be_empty
160
158
  end
161
159
  end
162
160
 
@@ -166,7 +164,7 @@ describe ParametersValidator do
166
164
  end
167
165
 
168
166
  it 'should call #length_error_at with :extreme => :many' do
169
- parameters_validator.should_receive(:length_error_at).with(
167
+ expect(parameters_validator).to receive(:length_error_at).with(
170
168
  hash_including(
171
169
  :extreme => :many
172
170
  )
@@ -178,7 +176,7 @@ describe ParametersValidator do
178
176
  it 'should record error' do
179
177
  validate_each
180
178
 
181
- errors.should_not be_empty
179
+ expect(errors).not_to be_empty
182
180
  end
183
181
  end
184
182
 
@@ -203,7 +201,7 @@ describe ParametersValidator do
203
201
  end
204
202
 
205
203
  it 'should call error_at with blank parameter name prefix' do
206
- parameters_validator.should_receive(:error_at).with(
204
+ expect(parameters_validator).to receive(:error_at).with(
207
205
  hash_including(
208
206
  :prefix => 'has blank parameter name'
209
207
  )
@@ -215,7 +213,7 @@ describe ParametersValidator do
215
213
  it 'should record error' do
216
214
  validate_each
217
215
 
218
- errors.should_not be_empty
216
+ expect(errors).not_to be_empty
219
217
  end
220
218
  end
221
219
 
@@ -227,7 +225,7 @@ describe ParametersValidator do
227
225
  it 'should not record error' do
228
226
  validate_each
229
227
 
230
- errors.should be_blank
228
+ expect(errors).to be_blank
231
229
  end
232
230
  end
233
231
  end
@@ -238,7 +236,7 @@ describe ParametersValidator do
238
236
  end
239
237
 
240
238
  it 'should call error_at with non-String prefix' do
241
- parameters_validator.should_receive(:error_at).with(
239
+ expect(parameters_validator).to receive(:error_at).with(
242
240
  hash_including(
243
241
  :prefix => "has non-String parameter name (#{parameter_name.inspect})"
244
242
  )
@@ -250,7 +248,7 @@ describe ParametersValidator do
250
248
  it 'should record error' do
251
249
  validate_each
252
250
 
253
- errors.should_not be_empty
251
+ expect(errors).not_to be_empty
254
252
  end
255
253
  end
256
254
  end
@@ -264,7 +262,7 @@ describe ParametersValidator do
264
262
  it 'should not record error' do
265
263
  validate_each
266
264
 
267
- errors.should be_blank
265
+ expect(errors).to be_blank
268
266
  end
269
267
  end
270
268
 
@@ -274,7 +272,7 @@ describe ParametersValidator do
274
272
  end
275
273
 
276
274
  it 'should call error_at with non-String prefix' do
277
- parameters_validator.should_receive(:error_at).with(
275
+ expect(parameters_validator).to receive(:error_at).with(
278
276
  hash_including(
279
277
  :prefix => "has non-String parameter value (#{parameter_value.inspect})"
280
278
  )
@@ -286,7 +284,7 @@ describe ParametersValidator do
286
284
  it 'should record error' do
287
285
  validate_each
288
286
 
289
- errors.should_not be_empty
287
+ expect(errors).not_to be_empty
290
288
  end
291
289
  end
292
290
  end
@@ -299,7 +297,7 @@ describe ParametersValidator do
299
297
  end
300
298
 
301
299
  it 'should use #error_at with has non-Array for prefix' do
302
- parameters_validator.should_receive(:error_at).with(
300
+ expect(parameters_validator).to receive(:error_at).with(
303
301
  hash_including(
304
302
  :prefix => 'has non-Array'
305
303
  )
@@ -311,7 +309,7 @@ describe ParametersValidator do
311
309
  it 'should record error' do
312
310
  validate_each
313
311
 
314
- errors.should_not be_empty
312
+ expect(errors).not_to be_empty
315
313
  end
316
314
  end
317
315
  end
@@ -327,14 +325,16 @@ describe ParametersValidator do
327
325
  end
328
326
 
329
327
  it 'should error that attribute is not an array' do
330
- errors.any? { |error|
331
- error.include? 'is not an Array.'
332
- }.should be_true
328
+ expect(
329
+ errors.any? { |error|
330
+ error.include? 'is not an Array.'
331
+ }
332
+ ).to eq(true)
333
333
  end
334
334
 
335
335
  it 'should include TYPE_SIGNATURE_SENTENCE' do
336
336
  errors.each do |error|
337
- error.should include(type_signature_sentence)
337
+ expect(error).to include(type_signature_sentence)
338
338
  end
339
339
  end
340
340
  end
@@ -1,6 +1,4 @@
1
- require 'spec_helper'
2
-
3
- describe PasswordIsStrongValidator do
1
+ RSpec.describe PasswordIsStrongValidator do
4
2
 
5
3
  subject(:password_validator) do
6
4
  described_class.new(
@@ -20,23 +18,23 @@ describe PasswordIsStrongValidator do
20
18
  context '#contains_repetition?' do
21
19
 
22
20
  it 'should return true for aaaa' do
23
- password_validator.send(:contains_repetition?, 'aaaa').should be_true
21
+ expect(password_validator.send(:contains_repetition?, 'aaaa')).to eq(true)
24
22
  end
25
23
 
26
24
  it 'should return true for ababab' do
27
- password_validator.send(:contains_repetition?, 'ababab').should be_true
25
+ expect(password_validator.send(:contains_repetition?, 'ababab')).to eq(true)
28
26
  end
29
27
 
30
28
  it 'should return true for abcabcabc' do
31
- password_validator.send(:contains_repetition?, 'abcabcabc').should be_true
29
+ expect(password_validator.send(:contains_repetition?, 'abcabcabc')).to eq(true)
32
30
  end
33
31
 
34
32
  it 'should return true for abcdabcd' do
35
- password_validator.send(:contains_repetition?, 'abcdabcd').should be_true
33
+ expect(password_validator.send(:contains_repetition?, 'abcdabcd')).to eq(true)
36
34
  end
37
35
 
38
36
  it 'should return false for abcd1234abcd' do
39
- password_validator.send(:contains_repetition?, 'abcd1234abcd').should be_false
37
+ expect(password_validator.send(:contains_repetition?, 'abcd1234abcd')).to eq(false)
40
38
  end
41
39
 
42
40
  end
@@ -112,7 +110,7 @@ describe PasswordIsStrongValidator do
112
110
  ]
113
111
 
114
112
  it 'should return all the expected mutations of a password' do
115
- password_validator.send(:mutate_pass, 'metasploit').should == variants
113
+ expect(password_validator.send(:mutate_pass, 'metasploit')).to eq(variants)
116
114
  end
117
115
 
118
116
  end
@@ -123,81 +121,81 @@ describe PasswordIsStrongValidator do
123
121
  PasswordIsStrongValidator::COMMON_PASSWORDS.each do |password|
124
122
 
125
123
  it "should return true for #{password}" do
126
- password_validator.send(:is_common_password?, password).should be_true
124
+ expect(password_validator.send(:is_common_password?, password)).to eq(true)
127
125
  end
128
126
 
129
127
  it "should return true for #{password}!" do
130
- password_validator.send(:is_common_password?, "#{password}!").should be_true
128
+ expect(password_validator.send(:is_common_password?, "#{password}!")).to eq(true)
131
129
  end
132
130
 
133
131
  it "should return true for #{password}1" do
134
- password_validator.send(:is_common_password?, "#{password}1").should be_true
132
+ expect(password_validator.send(:is_common_password?, "#{password}1")).to eq(true)
135
133
  end
136
134
 
137
135
  it "should return true for #{password}9" do
138
- password_validator.send(:is_common_password?, "#{password}1").should be_true
136
+ expect(password_validator.send(:is_common_password?, "#{password}1")).to eq(true)
139
137
  end
140
138
 
141
139
  it "should return true for #{password}99" do
142
- password_validator.send(:is_common_password?, "#{password}12").should be_true
140
+ expect(password_validator.send(:is_common_password?, "#{password}12")).to eq(true)
143
141
  end
144
142
 
145
143
  it "should return true for #{password}123" do
146
- password_validator.send(:is_common_password?, "#{password}123").should be_true
144
+ expect(password_validator.send(:is_common_password?, "#{password}123")).to eq(true)
147
145
  end
148
146
 
149
147
  it "should return true for #{password}123!" do
150
- password_validator.send(:is_common_password?, "#{password}123!").should be_true
148
+ expect(password_validator.send(:is_common_password?, "#{password}123!")).to eq(true)
151
149
  end
152
150
 
153
151
  end
154
152
 
155
153
  it "should return true for r00t" do
156
- password_validator.send(:is_common_password?, "r00t").should be_true
154
+ expect(password_validator.send(:is_common_password?, "r00t")).to eq(true)
157
155
  end
158
156
 
159
157
  it "should return true for m3t@spl0it" do
160
- password_validator.send(:is_common_password?, "m3t@spl0it").should be_true
158
+ expect(password_validator.send(:is_common_password?, "m3t@spl0it")).to eq(true)
161
159
  end
162
160
 
163
161
  it "should return true for m3t@spl0it123!" do
164
- password_validator.send(:is_common_password?, "m3t@spl0it123!").should be_true
162
+ expect(password_validator.send(:is_common_password?, "m3t@spl0it123!")).to eq(true)
165
163
  end
166
164
  end
167
165
 
168
166
  context '#contains_username' do
169
167
 
170
168
  it 'should return true if username and password are the same' do
171
- password_validator.send(:contains_username?, 'admin', 'admin').should be_true
169
+ expect(password_validator.send(:contains_username?, 'admin', 'admin')).to eq(true)
172
170
  end
173
171
 
174
172
  it 'should return true if the password contains the username as part of it' do
175
- password_validator.send(:contains_username?, 'admin', '123admin123').should be_true
173
+ expect(password_validator.send(:contains_username?, 'admin', '123admin123')).to eq(true)
176
174
  end
177
175
 
178
176
  it 'should return false otherwise' do
179
- password_validator.send(:contains_username?, 'admin', 'foobar').should be_false
177
+ expect(password_validator.send(:contains_username?, 'admin', 'foobar')).to eq(false)
180
178
  end
181
179
  end
182
180
 
183
181
  context '#is_simple?' do
184
182
 
185
183
  it "should return true if no number" do
186
- password_validator.send(:is_simple?, "b@carat").should be_true
184
+ expect(password_validator.send(:is_simple?, "b@carat")).to eq(true)
187
185
  end
188
186
 
189
187
  it "should return true if no special char" do
190
- password_validator.send(:is_simple?, "bacarat4").should be_true
188
+ expect(password_validator.send(:is_simple?, "bacarat4")).to eq(true)
191
189
  end
192
190
 
193
191
  it "should return true if no letters" do
194
- password_validator.send(:is_simple?, "1337").should be_true
192
+ expect(password_validator.send(:is_simple?, "1337")).to eq(true)
195
193
  end
196
194
 
197
195
  PasswordIsStrongValidator::SPECIAL_CHARS.each_char do |char|
198
196
 
199
197
  it "should return false with a #{char}" do
200
- password_validator.send(:is_simple?, "bacarat4#{char}").should be_false
198
+ expect(password_validator.send(:is_simple?, "bacarat4#{char}")).to eq(false)
201
199
  end
202
200
  end
203
201
  end
@@ -212,13 +210,23 @@ describe PasswordIsStrongValidator do
212
210
  password_validator.validate_each(record, attribute, value)
213
211
  end
214
212
 
215
- let(:record) do
216
- Object.new.tap { |object|
217
- object.extend ActiveModel::Validations
218
- object.class.module_eval { attr_accessor :username }
219
- object.username = 'admin'
213
+ let(:record) {
214
+ record_class.new.tap { |instance|
215
+ instance.username = 'admin'
220
216
  }
221
- end
217
+ }
218
+
219
+ let(:record_class) {
220
+ Class.new do
221
+ include ActiveModel::Validations
222
+
223
+ #
224
+ # Attributes
225
+ #
226
+
227
+ attr_accessor :username
228
+ end
229
+ }
222
230
 
223
231
 
224
232
  context 'with a password with no special char' do
@@ -226,12 +234,12 @@ describe PasswordIsStrongValidator do
226
234
 
227
235
  it 'should record an error' do
228
236
  validate_each
229
- errors.should_not be_empty
237
+ expect(errors).not_to be_empty
230
238
  end
231
239
 
232
240
  it 'should have an error of "must contain letters, numbers, and at least one special character"' do
233
241
  validate_each
234
- errors.include?("must contain letters, numbers, and at least one special character").should be_true
242
+ expect(errors.include?("must contain letters, numbers, and at least one special character")).to eq(true)
235
243
  end
236
244
  end
237
245
 
@@ -240,12 +248,12 @@ describe PasswordIsStrongValidator do
240
248
 
241
249
  it 'should record an error' do
242
250
  validate_each
243
- errors.should_not be_empty
251
+ expect(errors).not_to be_empty
244
252
  end
245
253
 
246
254
  it 'should have an error of "must contain letters, numbers, and at least one special character"' do
247
255
  validate_each
248
- errors.include?("must contain letters, numbers, and at least one special character").should be_true
256
+ expect(errors.include?("must contain letters, numbers, and at least one special character")).to eq(true)
249
257
  end
250
258
  end
251
259
 
@@ -254,12 +262,12 @@ describe PasswordIsStrongValidator do
254
262
 
255
263
  it 'should record an error' do
256
264
  validate_each
257
- errors.should_not be_empty
265
+ expect(errors).not_to be_empty
258
266
  end
259
267
 
260
268
  it 'should have an error of "must contain letters, numbers, and at least one special character"' do
261
269
  validate_each
262
- errors.include?("must contain letters, numbers, and at least one special character").should be_true
270
+ expect(errors.include?("must contain letters, numbers, and at least one special character")).to eq(true)
263
271
  end
264
272
  end
265
273
 
@@ -268,12 +276,12 @@ describe PasswordIsStrongValidator do
268
276
 
269
277
  it 'should record an error' do
270
278
  validate_each
271
- errors.should_not be_empty
279
+ expect(errors).not_to be_empty
272
280
  end
273
281
 
274
282
  it 'should have an error of "must not contain the username"' do
275
283
  validate_each
276
- errors.include?("must not contain the username").should be_true
284
+ expect(errors.include?("must not contain the username")).to eq(true)
277
285
  end
278
286
  end
279
287
 
@@ -282,12 +290,12 @@ describe PasswordIsStrongValidator do
282
290
 
283
291
  it 'should record an error' do
284
292
  validate_each
285
- errors.should_not be_empty
293
+ expect(errors).not_to be_empty
286
294
  end
287
295
 
288
296
  it 'should have an error of "must not be a common password"' do
289
297
  validate_each
290
- errors.include?("must not be a common password").should be_true
298
+ expect(errors.include?("must not be a common password")).to eq(true)
291
299
  end
292
300
  end
293
301
 
@@ -296,12 +304,12 @@ describe PasswordIsStrongValidator do
296
304
 
297
305
  it 'should record an error' do
298
306
  validate_each
299
- errors.should_not be_empty
307
+ expect(errors).not_to be_empty
300
308
  end
301
309
 
302
310
  it 'should have an error of "must not be a common password"' do
303
311
  validate_each
304
- errors.include?("must not be a common password").should be_true
312
+ expect(errors.include?("must not be a common password")).to eq(true)
305
313
  end
306
314
  end
307
315
 
@@ -310,12 +318,12 @@ describe PasswordIsStrongValidator do
310
318
 
311
319
  it 'should record an error' do
312
320
  validate_each
313
- errors.should_not be_empty
321
+ expect(errors).not_to be_empty
314
322
  end
315
323
 
316
324
  it 'should have an error of "must not be a predictable sequence of characters"' do
317
325
  validate_each
318
- errors.include?("must not be a predictable sequence of characters").should be_true
326
+ expect(errors.include?("must not be a predictable sequence of characters")).to eq(true)
319
327
  end
320
328
  end
321
329