metasploit_data_models 0.24.0 → 0.24.1.pre.rspec.pre.3.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +3 -3
- data/Gemfile +1 -3
- data/app/models/metasploit_data_models/ip_address/v4/segmented.rb +1 -1
- data/app/models/metasploit_data_models/search/visitor/where.rb +1 -1
- data/app/validators/password_is_strong_validator.rb +1 -1
- data/lib/mdm/host/operating_system_normalization.rb +0 -10
- data/lib/metasploit_data_models/version.rb +2 -2
- data/metasploit_data_models.gemspec +1 -1
- data/spec/app/models/mdm/api_key_spec.rb +1 -3
- data/spec/app/models/mdm/client_spec.rb +9 -11
- data/spec/app/models/mdm/cred_spec.rb +42 -54
- data/spec/app/models/mdm/event_spec.rb +21 -23
- data/spec/app/models/mdm/exploit_attempt_spec.rb +19 -21
- data/spec/app/models/mdm/exploited_host_spec.rb +11 -13
- data/spec/app/models/mdm/host_detail_spec.rb +15 -17
- data/spec/app/models/mdm/host_spec.rb +261 -260
- data/spec/app/models/mdm/host_tag_spec.rb +6 -8
- data/spec/app/models/mdm/listener_spec.rb +30 -32
- data/spec/app/models/mdm/loot_spec.rb +21 -23
- data/spec/app/models/mdm/macro_spec.rb +1 -3
- data/spec/app/models/mdm/mod_ref_spec.rb +1 -3
- data/spec/app/models/mdm/module/action_spec.rb +10 -12
- data/spec/app/models/mdm/module/arch_spec.rb +10 -12
- data/spec/app/models/mdm/module/author_spec.rb +22 -17
- data/spec/app/models/mdm/module/detail_spec.rb +184 -75
- data/spec/app/models/mdm/module/mixin_spec.rb +10 -12
- data/spec/app/models/mdm/module/platform_spec.rb +10 -12
- data/spec/app/models/mdm/module/ref_spec.rb +10 -12
- data/spec/app/models/mdm/module/target_spec.rb +13 -15
- data/spec/app/models/mdm/nexpose_console_spec.rb +35 -37
- data/spec/app/models/mdm/note_spec.rb +23 -25
- data/spec/app/models/mdm/profile_spec.rb +1 -3
- data/spec/app/models/mdm/ref_spec.rb +10 -12
- data/spec/app/models/mdm/route_spec.rb +6 -8
- data/spec/app/models/mdm/service_spec.rb +38 -40
- data/spec/app/models/mdm/session_event_spec.rb +10 -12
- data/spec/app/models/mdm/session_spec.rb +13 -15
- data/spec/app/models/mdm/tag_spec.rb +29 -29
- data/spec/app/models/mdm/task_cred_spec.rb +9 -11
- data/spec/app/models/mdm/task_host_spec.rb +9 -11
- data/spec/app/models/mdm/task_service_spec.rb +9 -11
- data/spec/app/models/mdm/task_session_spec.rb +7 -9
- data/spec/app/models/mdm/task_spec.rb +27 -29
- data/spec/app/models/mdm/user_spec.rb +17 -19
- data/spec/app/models/mdm/vuln_attempt_spec.rb +14 -16
- data/spec/app/models/mdm/vuln_detail_spec.rb +26 -28
- data/spec/app/models/mdm/vuln_ref_spec.rb +8 -10
- data/spec/app/models/mdm/vuln_spec.rb +24 -26
- data/spec/app/models/mdm/web_form_spec.rb +11 -13
- data/spec/app/models/mdm/web_page_spec.rb +19 -21
- data/spec/app/models/mdm/web_site_spec.rb +21 -23
- data/spec/app/models/mdm/web_vuln_spec.rb +63 -65
- data/spec/app/models/mdm/wmap_request_spec.rb +1 -3
- data/spec/app/models/mdm/wmap_target_spec.rb +1 -3
- data/spec/app/models/mdm/workspace_spec.rb +97 -100
- data/spec/app/models/metasploit_data_models/automatic_exploitation/match_result_spec.rb +3 -5
- data/spec/app/models/metasploit_data_models/automatic_exploitation/match_set_spec.rb +13 -15
- data/spec/app/models/metasploit_data_models/automatic_exploitation/match_spec.rb +1 -3
- data/spec/app/models/metasploit_data_models/automatic_exploitation/run_spec.rb +1 -3
- data/spec/app/models/metasploit_data_models/ip_address/v4/cidr_spec.rb +10 -12
- data/spec/app/models/metasploit_data_models/ip_address/v4/nmap_spec.rb +4 -6
- data/spec/app/models/metasploit_data_models/ip_address/v4/range_spec.rb +21 -23
- data/spec/app/models/metasploit_data_models/ip_address/v4/segment/nmap/list_spec.rb +9 -11
- data/spec/app/models/metasploit_data_models/ip_address/v4/segment/nmap/range_spec.rb +21 -23
- data/spec/app/models/metasploit_data_models/ip_address/v4/segment/segmented_spec.rb +4 -6
- data/spec/app/models/metasploit_data_models/ip_address/v4/segment/single_spec.rb +22 -15
- data/spec/app/models/metasploit_data_models/ip_address/v4/single_spec.rb +4 -6
- data/spec/app/models/metasploit_data_models/module_run_spec.rb +1 -3
- data/spec/app/models/metasploit_data_models/search/operation/ip_address_spec.rb +18 -20
- data/spec/app/models/metasploit_data_models/search/operation/port/number_spec.rb +6 -8
- data/spec/app/models/metasploit_data_models/search/operation/port/range_spec.rb +8 -10
- data/spec/app/models/metasploit_data_models/search/operation/range_spec.rb +8 -10
- data/spec/app/models/metasploit_data_models/search/operator/ip_address_spec.rb +2 -4
- data/spec/app/models/metasploit_data_models/search/operator/multitext_spec.rb +8 -10
- data/spec/app/models/metasploit_data_models/search/operator/port/list_spec.rb +6 -8
- data/spec/app/models/metasploit_data_models/search/visitor/attribute_spec.rb +9 -11
- data/spec/app/models/metasploit_data_models/search/visitor/includes_spec.rb +5 -7
- data/spec/app/models/metasploit_data_models/search/visitor/joins_spec.rb +17 -19
- data/spec/app/models/metasploit_data_models/search/visitor/method_spec.rb +5 -7
- data/spec/app/models/metasploit_data_models/search/visitor/relation_spec.rb +61 -23
- data/spec/app/models/metasploit_data_models/search/visitor/where_spec.rb +8 -10
- data/spec/app/validators/parameters_validator_spec.rb +29 -29
- data/spec/app/validators/password_is_strong_validator_spec.rb +54 -46
- data/spec/dummy/db/structure.sql +1 -0
- data/spec/lib/base64_serializer_spec.rb +19 -19
- data/spec/lib/metasploit_data_models/ip_address/cidr_spec.rb +18 -12
- data/spec/lib/metasploit_data_models/ip_address/range_spec.rb +4 -6
- data/spec/lib/metasploit_data_models/match/child_spec.rb +2 -4
- data/spec/lib/metasploit_data_models/match/parent_spec.rb +4 -6
- data/spec/lib/metasploit_data_models/version_spec.rb +3 -5
- data/spec/spec_helper.rb +72 -6
- data/spec/support/shared/examples/mdm/module/detail/does_not_support_stance_with_mtype.rb +2 -2
- data/spec/support/shared/examples/mdm/module/detail/supports_stance_with_mtype.rb +4 -4
- data/spec/support/shared/examples/metasploit_data_models/search/operation/ipaddress/match.rb +2 -2
- data/spec/support/shared/examples/metasploit_data_models/search/visitor/includes/visit/with_children.rb +5 -5
- data/spec/support/shared/examples/metasploit_data_models/search/visitor/includes/visit/with_metasploit_model_search_operation_base.rb +5 -5
- data/spec/support/shared/examples/metasploit_data_models/search/visitor/where/visit/with_equality.rb +3 -3
- data/spec/support/shared/examples/metasploit_data_models/search/visitor/where/visit/with_metasploit_model_search_group_base.rb +7 -6
- metadata +6 -6
@@ -1,6 +1,4 @@
|
|
1
|
-
|
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 {
|
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 {
|
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.
|
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.
|
92
|
+
allow(visitor.attribute_visitor).to receive(:visit).with(operator).and_return(attribute)
|
95
93
|
|
96
|
-
attribute.
|
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.
|
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.
|
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
|
-
|
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.
|
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.
|
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.
|
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.
|
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.
|
82
|
+
expect(parameters_validator).to receive(:error_at) do |*args|
|
85
83
|
options = args.first
|
86
|
-
options[:prefix].
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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
|
-
|
331
|
-
|
332
|
-
|
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.
|
337
|
+
expect(error).to include(type_signature_sentence)
|
338
338
|
end
|
339
339
|
end
|
340
340
|
end
|
@@ -1,6 +1,4 @@
|
|
1
|
-
|
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').
|
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').
|
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').
|
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').
|
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').
|
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').
|
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).
|
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}!").
|
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").
|
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").
|
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").
|
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").
|
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!").
|
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").
|
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").
|
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!").
|
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').
|
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').
|
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').
|
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").
|
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").
|
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").
|
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}").
|
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)
|
216
|
-
|
217
|
-
|
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
|
-
|
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.
|
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").
|
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.
|
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").
|
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.
|
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").
|
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.
|
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").
|
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.
|
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").
|
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.
|
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").
|
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.
|
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").
|
326
|
+
expect(errors.include?("must not be a predictable sequence of characters")).to eq(true)
|
319
327
|
end
|
320
328
|
end
|
321
329
|
|