metasploit_data_models 0.24.1.pre.rspec.pre.3.pre.1 → 0.24.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 +3 -1
- 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 +10 -0
- data/lib/metasploit_data_models/version.rb +1 -2
- data/metasploit_data_models.gemspec +1 -1
- data/spec/app/models/mdm/api_key_spec.rb +3 -1
- data/spec/app/models/mdm/client_spec.rb +11 -9
- data/spec/app/models/mdm/cred_spec.rb +54 -42
- data/spec/app/models/mdm/event_spec.rb +23 -21
- data/spec/app/models/mdm/exploit_attempt_spec.rb +21 -19
- data/spec/app/models/mdm/exploited_host_spec.rb +13 -11
- data/spec/app/models/mdm/host_detail_spec.rb +17 -15
- data/spec/app/models/mdm/host_spec.rb +260 -261
- data/spec/app/models/mdm/host_tag_spec.rb +8 -6
- data/spec/app/models/mdm/listener_spec.rb +32 -30
- data/spec/app/models/mdm/loot_spec.rb +23 -21
- data/spec/app/models/mdm/macro_spec.rb +3 -1
- data/spec/app/models/mdm/mod_ref_spec.rb +3 -1
- data/spec/app/models/mdm/module/action_spec.rb +12 -10
- data/spec/app/models/mdm/module/arch_spec.rb +12 -10
- data/spec/app/models/mdm/module/author_spec.rb +17 -22
- data/spec/app/models/mdm/module/detail_spec.rb +75 -184
- data/spec/app/models/mdm/module/mixin_spec.rb +12 -10
- data/spec/app/models/mdm/module/platform_spec.rb +12 -10
- data/spec/app/models/mdm/module/ref_spec.rb +12 -10
- data/spec/app/models/mdm/module/target_spec.rb +15 -13
- data/spec/app/models/mdm/nexpose_console_spec.rb +37 -35
- data/spec/app/models/mdm/note_spec.rb +25 -23
- data/spec/app/models/mdm/profile_spec.rb +3 -1
- data/spec/app/models/mdm/ref_spec.rb +12 -10
- data/spec/app/models/mdm/route_spec.rb +8 -6
- data/spec/app/models/mdm/service_spec.rb +40 -38
- data/spec/app/models/mdm/session_event_spec.rb +12 -10
- data/spec/app/models/mdm/session_spec.rb +15 -13
- data/spec/app/models/mdm/tag_spec.rb +29 -29
- data/spec/app/models/mdm/task_cred_spec.rb +11 -9
- data/spec/app/models/mdm/task_host_spec.rb +11 -9
- data/spec/app/models/mdm/task_service_spec.rb +11 -9
- data/spec/app/models/mdm/task_session_spec.rb +9 -7
- data/spec/app/models/mdm/task_spec.rb +29 -27
- data/spec/app/models/mdm/user_spec.rb +19 -17
- data/spec/app/models/mdm/vuln_attempt_spec.rb +16 -14
- data/spec/app/models/mdm/vuln_detail_spec.rb +28 -26
- data/spec/app/models/mdm/vuln_ref_spec.rb +10 -8
- data/spec/app/models/mdm/vuln_spec.rb +26 -24
- data/spec/app/models/mdm/web_form_spec.rb +13 -11
- data/spec/app/models/mdm/web_page_spec.rb +21 -19
- data/spec/app/models/mdm/web_site_spec.rb +23 -21
- data/spec/app/models/mdm/web_vuln_spec.rb +65 -63
- data/spec/app/models/mdm/wmap_request_spec.rb +3 -1
- data/spec/app/models/mdm/wmap_target_spec.rb +3 -1
- data/spec/app/models/mdm/workspace_spec.rb +100 -97
- data/spec/app/models/metasploit_data_models/automatic_exploitation/match_result_spec.rb +5 -3
- data/spec/app/models/metasploit_data_models/automatic_exploitation/match_set_spec.rb +15 -13
- data/spec/app/models/metasploit_data_models/automatic_exploitation/match_spec.rb +3 -1
- data/spec/app/models/metasploit_data_models/automatic_exploitation/run_spec.rb +3 -1
- data/spec/app/models/metasploit_data_models/ip_address/v4/cidr_spec.rb +12 -10
- data/spec/app/models/metasploit_data_models/ip_address/v4/nmap_spec.rb +6 -4
- data/spec/app/models/metasploit_data_models/ip_address/v4/range_spec.rb +23 -21
- data/spec/app/models/metasploit_data_models/ip_address/v4/segment/nmap/list_spec.rb +11 -9
- data/spec/app/models/metasploit_data_models/ip_address/v4/segment/nmap/range_spec.rb +23 -21
- data/spec/app/models/metasploit_data_models/ip_address/v4/segment/segmented_spec.rb +6 -4
- data/spec/app/models/metasploit_data_models/ip_address/v4/segment/single_spec.rb +15 -22
- data/spec/app/models/metasploit_data_models/ip_address/v4/single_spec.rb +6 -4
- data/spec/app/models/metasploit_data_models/module_run_spec.rb +3 -1
- data/spec/app/models/metasploit_data_models/search/operation/ip_address_spec.rb +20 -18
- data/spec/app/models/metasploit_data_models/search/operation/port/number_spec.rb +8 -6
- data/spec/app/models/metasploit_data_models/search/operation/port/range_spec.rb +10 -8
- data/spec/app/models/metasploit_data_models/search/operation/range_spec.rb +10 -8
- data/spec/app/models/metasploit_data_models/search/operator/ip_address_spec.rb +4 -2
- data/spec/app/models/metasploit_data_models/search/operator/multitext_spec.rb +10 -8
- data/spec/app/models/metasploit_data_models/search/operator/port/list_spec.rb +8 -6
- data/spec/app/models/metasploit_data_models/search/visitor/attribute_spec.rb +11 -9
- data/spec/app/models/metasploit_data_models/search/visitor/includes_spec.rb +7 -5
- data/spec/app/models/metasploit_data_models/search/visitor/joins_spec.rb +19 -17
- data/spec/app/models/metasploit_data_models/search/visitor/method_spec.rb +7 -5
- data/spec/app/models/metasploit_data_models/search/visitor/relation_spec.rb +23 -61
- data/spec/app/models/metasploit_data_models/search/visitor/where_spec.rb +10 -8
- data/spec/app/validators/parameters_validator_spec.rb +29 -29
- data/spec/app/validators/password_is_strong_validator_spec.rb +46 -54
- data/spec/factories/mdm/module/details.rb +1 -1
- data/spec/lib/base64_serializer_spec.rb +19 -19
- data/spec/lib/metasploit_data_models/ip_address/cidr_spec.rb +12 -18
- data/spec/lib/metasploit_data_models/ip_address/range_spec.rb +6 -4
- data/spec/lib/metasploit_data_models/match/child_spec.rb +4 -2
- data/spec/lib/metasploit_data_models/match/parent_spec.rb +6 -4
- data/spec/lib/metasploit_data_models/version_spec.rb +5 -3
- data/spec/spec_helper.rb +6 -72
- 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 +6 -7
- metadata +7 -7
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MetasploitDataModels::Search::Operator::IPAddress do
|
2
4
|
subject(:operator) {
|
3
5
|
described_class.new
|
4
6
|
}
|
@@ -12,6 +14,6 @@ RSpec.describe MetasploitDataModels::Search::Operator::IPAddress, type: :model d
|
|
12
14
|
nil
|
13
15
|
}
|
14
16
|
|
15
|
-
it {
|
17
|
+
it { should be_a MetasploitDataModels::Search::Operation::IPAddress }
|
16
18
|
end
|
17
19
|
end
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MetasploitDataModels::Search::Operator::Multitext do
|
2
4
|
subject(:multitext_operator) {
|
3
5
|
described_class.new(
|
4
6
|
attributes
|
@@ -10,8 +12,8 @@ RSpec.describe MetasploitDataModels::Search::Operator::Multitext, type: :model d
|
|
10
12
|
}
|
11
13
|
|
12
14
|
context 'validations' do
|
13
|
-
it {
|
14
|
-
it {
|
15
|
+
it { should ensure_length_of(:operator_names).is_at_least(2) }
|
16
|
+
it { should validate_presence_of :name }
|
15
17
|
end
|
16
18
|
|
17
19
|
context '#children' do
|
@@ -43,7 +45,7 @@ RSpec.describe MetasploitDataModels::Search::Operator::Multitext, type: :model d
|
|
43
45
|
nil
|
44
46
|
}
|
45
47
|
|
46
|
-
it {
|
48
|
+
it { should == [] }
|
47
49
|
end
|
48
50
|
|
49
51
|
context 'with empty String' do
|
@@ -51,7 +53,7 @@ RSpec.describe MetasploitDataModels::Search::Operator::Multitext, type: :model d
|
|
51
53
|
''
|
52
54
|
}
|
53
55
|
|
54
|
-
it {
|
56
|
+
it { should == [] }
|
55
57
|
end
|
56
58
|
|
57
59
|
context 'without quotes' do
|
@@ -80,7 +82,7 @@ RSpec.describe MetasploitDataModels::Search::Operator::Multitext, type: :model d
|
|
80
82
|
}
|
81
83
|
|
82
84
|
it 'generates a single union for quoted words as a single argument' do
|
83
|
-
expect(children
|
85
|
+
expect(children).to have(1).items
|
84
86
|
|
85
87
|
child = children.first
|
86
88
|
|
@@ -99,7 +101,7 @@ RSpec.describe MetasploitDataModels::Search::Operator::Multitext, type: :model d
|
|
99
101
|
}
|
100
102
|
|
101
103
|
context 'default' do
|
102
|
-
it {
|
104
|
+
it { should be_nil }
|
103
105
|
end
|
104
106
|
|
105
107
|
context 'setter' do
|
@@ -121,7 +123,7 @@ RSpec.describe MetasploitDataModels::Search::Operator::Multitext, type: :model d
|
|
121
123
|
}
|
122
124
|
|
123
125
|
context 'default' do
|
124
|
-
it {
|
126
|
+
it { should == [] }
|
125
127
|
end
|
126
128
|
end
|
127
129
|
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MetasploitDataModels::Search::Operator::Port::List do
|
2
4
|
subject(:port_list_operator) {
|
3
5
|
described_class.new(
|
4
6
|
klass: klass
|
@@ -15,7 +17,7 @@ RSpec.describe MetasploitDataModels::Search::Operator::Port::List, type: :model
|
|
15
17
|
described_class::SEPARATOR
|
16
18
|
}
|
17
19
|
|
18
|
-
it {
|
20
|
+
it { should == ',' }
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
@@ -25,7 +27,7 @@ RSpec.describe MetasploitDataModels::Search::Operator::Port::List, type: :model
|
|
25
27
|
}
|
26
28
|
|
27
29
|
context 'default' do
|
28
|
-
it {
|
30
|
+
it { should == :port }
|
29
31
|
end
|
30
32
|
|
31
33
|
context 'setter' do
|
@@ -85,7 +87,7 @@ RSpec.describe MetasploitDataModels::Search::Operator::Port::List, type: :model
|
|
85
87
|
operation_range.value
|
86
88
|
}
|
87
89
|
|
88
|
-
it {
|
90
|
+
it { should be_a Range }
|
89
91
|
end
|
90
92
|
end
|
91
93
|
end
|
@@ -119,7 +121,7 @@ RSpec.describe MetasploitDataModels::Search::Operator::Port::List, type: :model
|
|
119
121
|
operation_range.value
|
120
122
|
}
|
121
123
|
|
122
|
-
it {
|
124
|
+
it { should be_an Integer }
|
123
125
|
end
|
124
126
|
end
|
125
127
|
end
|
@@ -157,6 +159,6 @@ RSpec.describe MetasploitDataModels::Search::Operator::Port::List, type: :model
|
|
157
159
|
described_class.operator_name
|
158
160
|
}
|
159
161
|
|
160
|
-
it {
|
162
|
+
it { should == 'port_list' }
|
161
163
|
end
|
162
164
|
end
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MetasploitDataModels::Search::Visitor::Attribute do
|
2
4
|
subject(:visitor) do
|
3
5
|
described_class.new
|
4
6
|
end
|
@@ -20,7 +22,7 @@ RSpec.describe MetasploitDataModels::Search::Visitor::Attribute, type: :model do
|
|
20
22
|
node_class = options.fetch(:node_class)
|
21
23
|
|
22
24
|
context "with #{node_class}" do
|
23
|
-
it {
|
25
|
+
it { should be_a Arel::Attributes::Attribute }
|
24
26
|
|
25
27
|
context '#name' do
|
26
28
|
subject(:name) do
|
@@ -28,7 +30,7 @@ RSpec.describe MetasploitDataModels::Search::Visitor::Attribute, type: :model do
|
|
28
30
|
end
|
29
31
|
|
30
32
|
it "should be #{node_class}#attribute" do
|
31
|
-
|
33
|
+
name.should == node.attribute
|
32
34
|
end
|
33
35
|
end
|
34
36
|
|
@@ -38,7 +40,7 @@ RSpec.describe MetasploitDataModels::Search::Visitor::Attribute, type: :model do
|
|
38
40
|
end
|
39
41
|
|
40
42
|
it "should be Class#arel_table for #{node_class}#klass" do
|
41
|
-
|
43
|
+
relation.should == node.klass.arel_table
|
42
44
|
end
|
43
45
|
end
|
44
46
|
end
|
@@ -56,19 +58,19 @@ RSpec.describe MetasploitDataModels::Search::Visitor::Attribute, type: :model do
|
|
56
58
|
end
|
57
59
|
|
58
60
|
it 'should visit Metasploit::Model::Search::Operator::Association#source_operator' do
|
59
|
-
|
60
|
-
|
61
|
+
visitor.should_receive(:visit).with(node).and_call_original
|
62
|
+
visitor.should_receive(:visit).with(source_operator)
|
61
63
|
|
62
64
|
visit
|
63
65
|
end
|
64
66
|
|
65
67
|
it 'should return visit of Metasploit::Model::Search::Operator::Association#source_operator' do
|
66
|
-
|
68
|
+
visitor.should_receive(:visit).with(node).and_call_original
|
67
69
|
|
68
70
|
visited = double('Source Operator Visited')
|
69
|
-
|
71
|
+
visitor.stub(:visit).with(source_operator).and_return(visited)
|
70
72
|
|
71
|
-
|
73
|
+
visit.should == visited
|
72
74
|
end
|
73
75
|
end
|
74
76
|
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MetasploitDataModels::Search::Visitor::Includes do
|
2
4
|
subject(:visitor) do
|
3
5
|
described_class.new
|
4
6
|
end
|
@@ -120,7 +122,7 @@ RSpec.describe MetasploitDataModels::Search::Visitor::Includes, type: :model do
|
|
120
122
|
Metasploit::Model::Search::Operator::Attribute.new
|
121
123
|
end
|
122
124
|
|
123
|
-
it {
|
125
|
+
it { should == [] }
|
124
126
|
end
|
125
127
|
|
126
128
|
context 'with MetasploitDataModels::Search::Operator::Port::List' do
|
@@ -128,7 +130,7 @@ RSpec.describe MetasploitDataModels::Search::Visitor::Includes, type: :model do
|
|
128
130
|
MetasploitDataModels::Search::Operator::Port::List.new
|
129
131
|
end
|
130
132
|
|
131
|
-
it {
|
133
|
+
it { should == [] }
|
132
134
|
end
|
133
135
|
|
134
136
|
context 'with Metasploit::Model::Search::Query#tree' do
|
@@ -158,7 +160,7 @@ RSpec.describe MetasploitDataModels::Search::Visitor::Includes, type: :model do
|
|
158
160
|
"name:\"#{name}\""
|
159
161
|
end
|
160
162
|
|
161
|
-
it {
|
163
|
+
it { should be_empty }
|
162
164
|
end
|
163
165
|
|
164
166
|
context 'with services.name' do
|
@@ -170,7 +172,7 @@ RSpec.describe MetasploitDataModels::Search::Visitor::Includes, type: :model do
|
|
170
172
|
"services.name:\"#{name}\""
|
171
173
|
end
|
172
174
|
|
173
|
-
it {
|
175
|
+
it { should include :services }
|
174
176
|
end
|
175
177
|
end
|
176
178
|
end
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MetasploitDataModels::Search::Visitor::Joins do
|
2
4
|
subject(:visitor) do
|
3
5
|
described_class.new
|
4
6
|
end
|
@@ -31,10 +33,10 @@ RSpec.describe MetasploitDataModels::Search::Visitor::Joins, type: :model do
|
|
31
33
|
|
32
34
|
it 'should visit each child' do
|
33
35
|
# needed for call to visit subject
|
34
|
-
|
36
|
+
visitor.should_receive(:visit).with(node).and_call_original
|
35
37
|
|
36
38
|
children.each do |child|
|
37
|
-
|
39
|
+
visitor.should_receive(:visit).with(child).and_return([])
|
38
40
|
end
|
39
41
|
|
40
42
|
visit
|
@@ -43,15 +45,15 @@ RSpec.describe MetasploitDataModels::Search::Visitor::Joins, type: :model do
|
|
43
45
|
it 'should return Array of all child visits' do
|
44
46
|
child_visits = []
|
45
47
|
|
46
|
-
|
48
|
+
visitor.should_receive(:visit).with(node).and_call_original
|
47
49
|
|
48
50
|
children.each_with_index do |child, i|
|
49
51
|
child_visit = ["Visited Child #{i}"]
|
50
|
-
|
52
|
+
visitor.stub(:visit).with(child).and_return(child_visit)
|
51
53
|
child_visits.concat(child_visit)
|
52
54
|
end
|
53
55
|
|
54
|
-
|
56
|
+
visit.should == child_visits
|
55
57
|
end
|
56
58
|
end
|
57
59
|
end
|
@@ -79,7 +81,7 @@ RSpec.describe MetasploitDataModels::Search::Visitor::Joins, type: :model do
|
|
79
81
|
}
|
80
82
|
end
|
81
83
|
|
82
|
-
it {
|
84
|
+
it { should == [] }
|
83
85
|
end
|
84
86
|
|
85
87
|
context 'with association and attribute' do
|
@@ -115,7 +117,7 @@ RSpec.describe MetasploitDataModels::Search::Visitor::Joins, type: :model do
|
|
115
117
|
]
|
116
118
|
end
|
117
119
|
|
118
|
-
it {
|
120
|
+
it { should == [] }
|
119
121
|
end
|
120
122
|
|
121
123
|
context 'with the same child join for all' do
|
@@ -143,7 +145,7 @@ RSpec.describe MetasploitDataModels::Search::Visitor::Joins, type: :model do
|
|
143
145
|
end
|
144
146
|
|
145
147
|
it 'should include association' do
|
146
|
-
|
148
|
+
visit.should include association
|
147
149
|
end
|
148
150
|
end
|
149
151
|
|
@@ -213,13 +215,13 @@ RSpec.describe MetasploitDataModels::Search::Visitor::Joins, type: :model do
|
|
213
215
|
|
214
216
|
it 'should include common associations' do
|
215
217
|
common_associations.each do |association|
|
216
|
-
|
218
|
+
visit.should include(association)
|
217
219
|
end
|
218
220
|
end
|
219
221
|
|
220
222
|
it 'should not include disjoint associations' do
|
221
223
|
disjoint_associations.each do |association|
|
222
|
-
|
224
|
+
visit.should_not include(association)
|
223
225
|
end
|
224
226
|
end
|
225
227
|
end
|
@@ -229,7 +231,7 @@ RSpec.describe MetasploitDataModels::Search::Visitor::Joins, type: :model do
|
|
229
231
|
[]
|
230
232
|
end
|
231
233
|
|
232
|
-
it {
|
234
|
+
it { should == [] }
|
233
235
|
end
|
234
236
|
end
|
235
237
|
end
|
@@ -239,7 +241,7 @@ RSpec.describe MetasploitDataModels::Search::Visitor::Joins, type: :model do
|
|
239
241
|
[]
|
240
242
|
end
|
241
243
|
|
242
|
-
it {
|
244
|
+
it { should == [] }
|
243
245
|
end
|
244
246
|
end
|
245
247
|
end
|
@@ -337,7 +339,7 @@ RSpec.describe MetasploitDataModels::Search::Visitor::Joins, type: :model do
|
|
337
339
|
Metasploit::Model::Search::Operator::Attribute.new
|
338
340
|
end
|
339
341
|
|
340
|
-
it {
|
342
|
+
it { should == [] }
|
341
343
|
end
|
342
344
|
|
343
345
|
context 'with MetasploitDataModels::Search::Operator::Port::List' do
|
@@ -345,7 +347,7 @@ RSpec.describe MetasploitDataModels::Search::Visitor::Joins, type: :model do
|
|
345
347
|
MetasploitDataModels::Search::Operator::Port::List.new
|
346
348
|
end
|
347
349
|
|
348
|
-
it {
|
350
|
+
it { should == [] }
|
349
351
|
end
|
350
352
|
|
351
353
|
context 'with Metasploit::Model::Search::Query#tree' do
|
@@ -375,7 +377,7 @@ RSpec.describe MetasploitDataModels::Search::Visitor::Joins, type: :model do
|
|
375
377
|
"name:\"#{name}\""
|
376
378
|
end
|
377
379
|
|
378
|
-
it {
|
380
|
+
it { should be_empty }
|
379
381
|
end
|
380
382
|
|
381
383
|
context 'with services.name' do
|
@@ -387,7 +389,7 @@ RSpec.describe MetasploitDataModels::Search::Visitor::Joins, type: :model do
|
|
387
389
|
"services.name:\"#{name}\""
|
388
390
|
end
|
389
391
|
|
390
|
-
it {
|
392
|
+
it { should include :services }
|
391
393
|
end
|
392
394
|
end
|
393
395
|
end
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MetasploitDataModels::Search::Visitor::Method do
|
2
4
|
subject(:visitor) do
|
3
5
|
described_class.new
|
4
6
|
end
|
@@ -19,7 +21,7 @@ RSpec.describe MetasploitDataModels::Search::Visitor::Method, type: :model do
|
|
19
21
|
Metasploit::Model::Search::Group::Intersection
|
20
22
|
end
|
21
23
|
|
22
|
-
it {
|
24
|
+
it { should == :and }
|
23
25
|
end
|
24
26
|
|
25
27
|
context 'with Metasploit::Model::Search::Operation::Group::Intersection' do
|
@@ -27,7 +29,7 @@ RSpec.describe MetasploitDataModels::Search::Visitor::Method, type: :model do
|
|
27
29
|
Metasploit::Model::Search::Operation::Group::Intersection
|
28
30
|
end
|
29
31
|
|
30
|
-
it {
|
32
|
+
it { should == :and }
|
31
33
|
end
|
32
34
|
|
33
35
|
context 'with Metasploit::Model::Search::Group::Union' do
|
@@ -35,7 +37,7 @@ RSpec.describe MetasploitDataModels::Search::Visitor::Method, type: :model do
|
|
35
37
|
Metasploit::Model::Search::Group::Union
|
36
38
|
end
|
37
39
|
|
38
|
-
it {
|
40
|
+
it { should == :or }
|
39
41
|
end
|
40
42
|
|
41
43
|
context 'with Metasploit::Model::Search::Operation::Group::Union' do
|
@@ -43,7 +45,7 @@ RSpec.describe MetasploitDataModels::Search::Visitor::Method, type: :model do
|
|
43
45
|
Metasploit::Model::Search::Operation::Group::Union
|
44
46
|
end
|
45
47
|
|
46
|
-
it {
|
48
|
+
it { should == :or }
|
47
49
|
end
|
48
50
|
end
|
49
51
|
end
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MetasploitDataModels::Search::Visitor::Relation do
|
2
4
|
subject(:visitor) do
|
3
5
|
described_class.new(
|
4
6
|
:query => query
|
@@ -29,7 +31,7 @@ RSpec.describe MetasploitDataModels::Search::Visitor::Relation, type: :model do
|
|
29
31
|
|
30
32
|
context 'validations' do
|
31
33
|
context 'query' do
|
32
|
-
it {
|
34
|
+
it { should validate_presence_of(:query) }
|
33
35
|
|
34
36
|
context 'valid' do
|
35
37
|
let(:error) do
|
@@ -46,7 +48,7 @@ RSpec.describe MetasploitDataModels::Search::Visitor::Relation, type: :model do
|
|
46
48
|
end
|
47
49
|
|
48
50
|
before(:each) do
|
49
|
-
|
51
|
+
query.stub(:valid? => query)
|
50
52
|
|
51
53
|
visitor.valid?
|
52
54
|
end
|
@@ -57,7 +59,7 @@ RSpec.describe MetasploitDataModels::Search::Visitor::Relation, type: :model do
|
|
57
59
|
end
|
58
60
|
|
59
61
|
it 'should not record error' do
|
60
|
-
|
62
|
+
errors.should_not include(error)
|
61
63
|
end
|
62
64
|
end
|
63
65
|
|
@@ -67,7 +69,7 @@ RSpec.describe MetasploitDataModels::Search::Visitor::Relation, type: :model do
|
|
67
69
|
end
|
68
70
|
|
69
71
|
it 'should record error' do
|
70
|
-
|
72
|
+
errors.should_not include(error)
|
71
73
|
end
|
72
74
|
end
|
73
75
|
end
|
@@ -78,7 +80,7 @@ RSpec.describe MetasploitDataModels::Search::Visitor::Relation, type: :model do
|
|
78
80
|
end
|
79
81
|
|
80
82
|
it 'should not record error' do
|
81
|
-
|
83
|
+
errors.should_not include(error)
|
82
84
|
end
|
83
85
|
end
|
84
86
|
end
|
@@ -96,16 +98,16 @@ RSpec.describe MetasploitDataModels::Search::Visitor::Relation, type: :model do
|
|
96
98
|
end
|
97
99
|
|
98
100
|
it 'should visit Metasploit::Model::Search::Query#tree' do
|
99
|
-
|
101
|
+
includes_visitor.should_receive(:visit).with(query.tree)
|
100
102
|
|
101
103
|
visit
|
102
104
|
end
|
103
105
|
|
104
106
|
it 'should pass visited to ActiveRecord::Relation#includes' do
|
105
107
|
visited = double('Visited')
|
106
|
-
|
108
|
+
includes_visitor.stub(:visit).with(query.tree).and_return(visited)
|
107
109
|
|
108
|
-
|
110
|
+
ActiveRecord::Relation.any_instance.should_receive(:includes).with(visited).and_return(query.klass.scoped)
|
109
111
|
|
110
112
|
visit
|
111
113
|
end
|
@@ -117,16 +119,16 @@ RSpec.describe MetasploitDataModels::Search::Visitor::Relation, type: :model do
|
|
117
119
|
end
|
118
120
|
|
119
121
|
it 'should visit Metasploit::Model::Search::Query#tree' do
|
120
|
-
|
122
|
+
joins_visitor.should_receive(:visit).with(query.tree)
|
121
123
|
|
122
124
|
visit
|
123
125
|
end
|
124
126
|
|
125
127
|
it 'should pass visited to ActiveRecord::Relation#joins' do
|
126
128
|
visited = double('Visited')
|
127
|
-
|
129
|
+
joins_visitor.stub(:visit).with(query.tree).and_return(visited)
|
128
130
|
|
129
|
-
|
131
|
+
ActiveRecord::Relation.any_instance.should_receive(:joins).with(visited).and_return(query.klass.scoped)
|
130
132
|
|
131
133
|
visit
|
132
134
|
end
|
@@ -138,16 +140,16 @@ RSpec.describe MetasploitDataModels::Search::Visitor::Relation, type: :model do
|
|
138
140
|
end
|
139
141
|
|
140
142
|
it 'should visit Metasploit::Model::Search::Query#tree' do
|
141
|
-
|
143
|
+
where_visitor.should_receive(:visit).with(query.tree)
|
142
144
|
|
143
145
|
visit
|
144
146
|
end
|
145
147
|
|
146
148
|
it 'should pass visited to ActiveRecord::Relation#includes' do
|
147
149
|
visited = double('Visited')
|
148
|
-
|
150
|
+
where_visitor.stub(:visit).with(query.tree).and_return(visited)
|
149
151
|
|
150
|
-
|
152
|
+
ActiveRecord::Relation.any_instance.should_receive(:where).with(visited).and_return(query.klass.scoped)
|
151
153
|
|
152
154
|
visit
|
153
155
|
end
|
@@ -868,29 +870,9 @@ RSpec.describe MetasploitDataModels::Search::Visitor::Relation, type: :model do
|
|
868
870
|
visitor.visitor_by_relation_method
|
869
871
|
end
|
870
872
|
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
}
|
875
|
-
|
876
|
-
it { is_expected.to be_a MetasploitDataModels::Search::Visitor::Joins }
|
877
|
-
end
|
878
|
-
|
879
|
-
context 'includes' do
|
880
|
-
subject(:includes) {
|
881
|
-
visitor_by_relation_method[:includes]
|
882
|
-
}
|
883
|
-
|
884
|
-
it { is_expected.to be_a MetasploitDataModels::Search::Visitor::Includes }
|
885
|
-
end
|
886
|
-
|
887
|
-
context 'where' do
|
888
|
-
subject(:where) {
|
889
|
-
visitor_by_relation_method[:where]
|
890
|
-
}
|
891
|
-
|
892
|
-
it { is_expected.to be_a MetasploitDataModels::Search::Visitor::Where }
|
893
|
-
end
|
873
|
+
its([:joins]) { should be_a MetasploitDataModels::Search::Visitor::Joins }
|
874
|
+
its([:includes]) { should be_a MetasploitDataModels::Search::Visitor::Includes }
|
875
|
+
its([:where]) { should be_a MetasploitDataModels::Search::Visitor::Where }
|
894
876
|
end
|
895
877
|
|
896
878
|
context 'visitor_class_by_relation_method' do
|
@@ -898,28 +880,8 @@ RSpec.describe MetasploitDataModels::Search::Visitor::Relation, type: :model do
|
|
898
880
|
described_class.visitor_class_by_relation_method
|
899
881
|
end
|
900
882
|
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
}
|
905
|
-
|
906
|
-
it { is_expected.to eq(MetasploitDataModels::Search::Visitor::Joins) }
|
907
|
-
end
|
908
|
-
|
909
|
-
context 'includes' do
|
910
|
-
subject(:includes) {
|
911
|
-
visitor_class_by_relation_method[:includes]
|
912
|
-
}
|
913
|
-
|
914
|
-
it { is_expected.to eq(MetasploitDataModels::Search::Visitor::Includes) }
|
915
|
-
end
|
916
|
-
|
917
|
-
context 'where' do
|
918
|
-
subject(:where) {
|
919
|
-
visitor_class_by_relation_method[:where]
|
920
|
-
}
|
921
|
-
|
922
|
-
it { is_expected.to eq(MetasploitDataModels::Search::Visitor::Where) }
|
923
|
-
end
|
883
|
+
its([:joins]) { should == MetasploitDataModels::Search::Visitor::Joins }
|
884
|
+
its([:includes]) { should == MetasploitDataModels::Search::Visitor::Includes }
|
885
|
+
its([:where]) { should == MetasploitDataModels::Search::Visitor::Where }
|
924
886
|
end
|
925
887
|
end
|