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::Operator::IPAddress do
|
1
|
+
RSpec.describe MetasploitDataModels::Search::Operator::IPAddress, type: :model do
|
4
2
|
subject(:operator) {
|
5
3
|
described_class.new
|
6
4
|
}
|
@@ -14,6 +12,6 @@ describe MetasploitDataModels::Search::Operator::IPAddress do
|
|
14
12
|
nil
|
15
13
|
}
|
16
14
|
|
17
|
-
it {
|
15
|
+
it { is_expected.to be_a MetasploitDataModels::Search::Operation::IPAddress }
|
18
16
|
end
|
19
17
|
end
|
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
describe MetasploitDataModels::Search::Operator::Multitext do
|
1
|
+
RSpec.describe MetasploitDataModels::Search::Operator::Multitext, type: :model do
|
4
2
|
subject(:multitext_operator) {
|
5
3
|
described_class.new(
|
6
4
|
attributes
|
@@ -12,8 +10,8 @@ describe MetasploitDataModels::Search::Operator::Multitext do
|
|
12
10
|
}
|
13
11
|
|
14
12
|
context 'validations' do
|
15
|
-
it {
|
16
|
-
it {
|
13
|
+
it { is_expected.to ensure_length_of(:operator_names).is_at_least(2) }
|
14
|
+
it { is_expected.to validate_presence_of :name }
|
17
15
|
end
|
18
16
|
|
19
17
|
context '#children' do
|
@@ -45,7 +43,7 @@ describe MetasploitDataModels::Search::Operator::Multitext do
|
|
45
43
|
nil
|
46
44
|
}
|
47
45
|
|
48
|
-
it {
|
46
|
+
it { is_expected.to eq([]) }
|
49
47
|
end
|
50
48
|
|
51
49
|
context 'with empty String' do
|
@@ -53,7 +51,7 @@ describe MetasploitDataModels::Search::Operator::Multitext do
|
|
53
51
|
''
|
54
52
|
}
|
55
53
|
|
56
|
-
it {
|
54
|
+
it { is_expected.to eq([]) }
|
57
55
|
end
|
58
56
|
|
59
57
|
context 'without quotes' do
|
@@ -82,7 +80,7 @@ describe MetasploitDataModels::Search::Operator::Multitext do
|
|
82
80
|
}
|
83
81
|
|
84
82
|
it 'generates a single union for quoted words as a single argument' do
|
85
|
-
expect(children).to
|
83
|
+
expect(children.length).to eq(1)
|
86
84
|
|
87
85
|
child = children.first
|
88
86
|
|
@@ -101,7 +99,7 @@ describe MetasploitDataModels::Search::Operator::Multitext do
|
|
101
99
|
}
|
102
100
|
|
103
101
|
context 'default' do
|
104
|
-
it {
|
102
|
+
it { is_expected.to be_nil }
|
105
103
|
end
|
106
104
|
|
107
105
|
context 'setter' do
|
@@ -123,7 +121,7 @@ describe MetasploitDataModels::Search::Operator::Multitext do
|
|
123
121
|
}
|
124
122
|
|
125
123
|
context 'default' do
|
126
|
-
it {
|
124
|
+
it { is_expected.to eq([]) }
|
127
125
|
end
|
128
126
|
end
|
129
127
|
|
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
describe MetasploitDataModels::Search::Operator::Port::List do
|
1
|
+
RSpec.describe MetasploitDataModels::Search::Operator::Port::List, type: :model do
|
4
2
|
subject(:port_list_operator) {
|
5
3
|
described_class.new(
|
6
4
|
klass: klass
|
@@ -17,7 +15,7 @@ describe MetasploitDataModels::Search::Operator::Port::List do
|
|
17
15
|
described_class::SEPARATOR
|
18
16
|
}
|
19
17
|
|
20
|
-
it {
|
18
|
+
it { is_expected.to eq(',') }
|
21
19
|
end
|
22
20
|
end
|
23
21
|
|
@@ -27,7 +25,7 @@ describe MetasploitDataModels::Search::Operator::Port::List do
|
|
27
25
|
}
|
28
26
|
|
29
27
|
context 'default' do
|
30
|
-
it {
|
28
|
+
it { is_expected.to eq(:port) }
|
31
29
|
end
|
32
30
|
|
33
31
|
context 'setter' do
|
@@ -87,7 +85,7 @@ describe MetasploitDataModels::Search::Operator::Port::List do
|
|
87
85
|
operation_range.value
|
88
86
|
}
|
89
87
|
|
90
|
-
it {
|
88
|
+
it { is_expected.to be_a Range }
|
91
89
|
end
|
92
90
|
end
|
93
91
|
end
|
@@ -121,7 +119,7 @@ describe MetasploitDataModels::Search::Operator::Port::List do
|
|
121
119
|
operation_range.value
|
122
120
|
}
|
123
121
|
|
124
|
-
it {
|
122
|
+
it { is_expected.to be_an Integer }
|
125
123
|
end
|
126
124
|
end
|
127
125
|
end
|
@@ -159,6 +157,6 @@ describe MetasploitDataModels::Search::Operator::Port::List do
|
|
159
157
|
described_class.operator_name
|
160
158
|
}
|
161
159
|
|
162
|
-
it {
|
160
|
+
it { is_expected.to eq('port_list') }
|
163
161
|
end
|
164
162
|
end
|
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
describe MetasploitDataModels::Search::Visitor::Attribute do
|
1
|
+
RSpec.describe MetasploitDataModels::Search::Visitor::Attribute, type: :model do
|
4
2
|
subject(:visitor) do
|
5
3
|
described_class.new
|
6
4
|
end
|
@@ -22,7 +20,7 @@ describe MetasploitDataModels::Search::Visitor::Attribute do
|
|
22
20
|
node_class = options.fetch(:node_class)
|
23
21
|
|
24
22
|
context "with #{node_class}" do
|
25
|
-
it {
|
23
|
+
it { is_expected.to be_a Arel::Attributes::Attribute }
|
26
24
|
|
27
25
|
context '#name' do
|
28
26
|
subject(:name) do
|
@@ -30,7 +28,7 @@ describe MetasploitDataModels::Search::Visitor::Attribute do
|
|
30
28
|
end
|
31
29
|
|
32
30
|
it "should be #{node_class}#attribute" do
|
33
|
-
name.
|
31
|
+
expect(name).to eq(node.attribute)
|
34
32
|
end
|
35
33
|
end
|
36
34
|
|
@@ -40,7 +38,7 @@ describe MetasploitDataModels::Search::Visitor::Attribute do
|
|
40
38
|
end
|
41
39
|
|
42
40
|
it "should be Class#arel_table for #{node_class}#klass" do
|
43
|
-
relation.
|
41
|
+
expect(relation).to eq(node.klass.arel_table)
|
44
42
|
end
|
45
43
|
end
|
46
44
|
end
|
@@ -58,19 +56,19 @@ describe MetasploitDataModels::Search::Visitor::Attribute do
|
|
58
56
|
end
|
59
57
|
|
60
58
|
it 'should visit Metasploit::Model::Search::Operator::Association#source_operator' do
|
61
|
-
visitor.
|
62
|
-
visitor.
|
59
|
+
expect(visitor).to receive(:visit).with(node).and_call_original
|
60
|
+
expect(visitor).to receive(:visit).with(source_operator)
|
63
61
|
|
64
62
|
visit
|
65
63
|
end
|
66
64
|
|
67
65
|
it 'should return visit of Metasploit::Model::Search::Operator::Association#source_operator' do
|
68
|
-
visitor.
|
66
|
+
expect(visitor).to receive(:visit).with(node).and_call_original
|
69
67
|
|
70
68
|
visited = double('Source Operator Visited')
|
71
|
-
visitor.
|
69
|
+
allow(visitor).to receive(:visit).with(source_operator).and_return(visited)
|
72
70
|
|
73
|
-
visit.
|
71
|
+
expect(visit).to eq(visited)
|
74
72
|
end
|
75
73
|
end
|
76
74
|
|
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
describe MetasploitDataModels::Search::Visitor::Includes do
|
1
|
+
RSpec.describe MetasploitDataModels::Search::Visitor::Includes, type: :model do
|
4
2
|
subject(:visitor) do
|
5
3
|
described_class.new
|
6
4
|
end
|
@@ -122,7 +120,7 @@ describe MetasploitDataModels::Search::Visitor::Includes do
|
|
122
120
|
Metasploit::Model::Search::Operator::Attribute.new
|
123
121
|
end
|
124
122
|
|
125
|
-
it {
|
123
|
+
it { is_expected.to eq([]) }
|
126
124
|
end
|
127
125
|
|
128
126
|
context 'with MetasploitDataModels::Search::Operator::Port::List' do
|
@@ -130,7 +128,7 @@ describe MetasploitDataModels::Search::Visitor::Includes do
|
|
130
128
|
MetasploitDataModels::Search::Operator::Port::List.new
|
131
129
|
end
|
132
130
|
|
133
|
-
it {
|
131
|
+
it { is_expected.to eq([]) }
|
134
132
|
end
|
135
133
|
|
136
134
|
context 'with Metasploit::Model::Search::Query#tree' do
|
@@ -160,7 +158,7 @@ describe MetasploitDataModels::Search::Visitor::Includes do
|
|
160
158
|
"name:\"#{name}\""
|
161
159
|
end
|
162
160
|
|
163
|
-
it {
|
161
|
+
it { is_expected.to be_empty }
|
164
162
|
end
|
165
163
|
|
166
164
|
context 'with services.name' do
|
@@ -172,7 +170,7 @@ describe MetasploitDataModels::Search::Visitor::Includes do
|
|
172
170
|
"services.name:\"#{name}\""
|
173
171
|
end
|
174
172
|
|
175
|
-
it {
|
173
|
+
it { is_expected.to include :services }
|
176
174
|
end
|
177
175
|
end
|
178
176
|
end
|
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
describe MetasploitDataModels::Search::Visitor::Joins do
|
1
|
+
RSpec.describe MetasploitDataModels::Search::Visitor::Joins, type: :model do
|
4
2
|
subject(:visitor) do
|
5
3
|
described_class.new
|
6
4
|
end
|
@@ -33,10 +31,10 @@ describe MetasploitDataModels::Search::Visitor::Joins do
|
|
33
31
|
|
34
32
|
it 'should visit each child' do
|
35
33
|
# needed for call to visit subject
|
36
|
-
visitor.
|
34
|
+
expect(visitor).to receive(:visit).with(node).and_call_original
|
37
35
|
|
38
36
|
children.each do |child|
|
39
|
-
visitor.
|
37
|
+
expect(visitor).to receive(:visit).with(child).and_return([])
|
40
38
|
end
|
41
39
|
|
42
40
|
visit
|
@@ -45,15 +43,15 @@ describe MetasploitDataModels::Search::Visitor::Joins do
|
|
45
43
|
it 'should return Array of all child visits' do
|
46
44
|
child_visits = []
|
47
45
|
|
48
|
-
visitor.
|
46
|
+
expect(visitor).to receive(:visit).with(node).and_call_original
|
49
47
|
|
50
48
|
children.each_with_index do |child, i|
|
51
49
|
child_visit = ["Visited Child #{i}"]
|
52
|
-
visitor.
|
50
|
+
allow(visitor).to receive(:visit).with(child).and_return(child_visit)
|
53
51
|
child_visits.concat(child_visit)
|
54
52
|
end
|
55
53
|
|
56
|
-
visit.
|
54
|
+
expect(visit).to eq(child_visits)
|
57
55
|
end
|
58
56
|
end
|
59
57
|
end
|
@@ -81,7 +79,7 @@ describe MetasploitDataModels::Search::Visitor::Joins do
|
|
81
79
|
}
|
82
80
|
end
|
83
81
|
|
84
|
-
it {
|
82
|
+
it { is_expected.to eq([]) }
|
85
83
|
end
|
86
84
|
|
87
85
|
context 'with association and attribute' do
|
@@ -117,7 +115,7 @@ describe MetasploitDataModels::Search::Visitor::Joins do
|
|
117
115
|
]
|
118
116
|
end
|
119
117
|
|
120
|
-
it {
|
118
|
+
it { is_expected.to eq([]) }
|
121
119
|
end
|
122
120
|
|
123
121
|
context 'with the same child join for all' do
|
@@ -145,7 +143,7 @@ describe MetasploitDataModels::Search::Visitor::Joins do
|
|
145
143
|
end
|
146
144
|
|
147
145
|
it 'should include association' do
|
148
|
-
visit.
|
146
|
+
expect(visit).to include association
|
149
147
|
end
|
150
148
|
end
|
151
149
|
|
@@ -215,13 +213,13 @@ describe MetasploitDataModels::Search::Visitor::Joins do
|
|
215
213
|
|
216
214
|
it 'should include common associations' do
|
217
215
|
common_associations.each do |association|
|
218
|
-
visit.
|
216
|
+
expect(visit).to include(association)
|
219
217
|
end
|
220
218
|
end
|
221
219
|
|
222
220
|
it 'should not include disjoint associations' do
|
223
221
|
disjoint_associations.each do |association|
|
224
|
-
visit.
|
222
|
+
expect(visit).not_to include(association)
|
225
223
|
end
|
226
224
|
end
|
227
225
|
end
|
@@ -231,7 +229,7 @@ describe MetasploitDataModels::Search::Visitor::Joins do
|
|
231
229
|
[]
|
232
230
|
end
|
233
231
|
|
234
|
-
it {
|
232
|
+
it { is_expected.to eq([]) }
|
235
233
|
end
|
236
234
|
end
|
237
235
|
end
|
@@ -241,7 +239,7 @@ describe MetasploitDataModels::Search::Visitor::Joins do
|
|
241
239
|
[]
|
242
240
|
end
|
243
241
|
|
244
|
-
it {
|
242
|
+
it { is_expected.to eq([]) }
|
245
243
|
end
|
246
244
|
end
|
247
245
|
end
|
@@ -339,7 +337,7 @@ describe MetasploitDataModels::Search::Visitor::Joins do
|
|
339
337
|
Metasploit::Model::Search::Operator::Attribute.new
|
340
338
|
end
|
341
339
|
|
342
|
-
it {
|
340
|
+
it { is_expected.to eq([]) }
|
343
341
|
end
|
344
342
|
|
345
343
|
context 'with MetasploitDataModels::Search::Operator::Port::List' do
|
@@ -347,7 +345,7 @@ describe MetasploitDataModels::Search::Visitor::Joins do
|
|
347
345
|
MetasploitDataModels::Search::Operator::Port::List.new
|
348
346
|
end
|
349
347
|
|
350
|
-
it {
|
348
|
+
it { is_expected.to eq([]) }
|
351
349
|
end
|
352
350
|
|
353
351
|
context 'with Metasploit::Model::Search::Query#tree' do
|
@@ -377,7 +375,7 @@ describe MetasploitDataModels::Search::Visitor::Joins do
|
|
377
375
|
"name:\"#{name}\""
|
378
376
|
end
|
379
377
|
|
380
|
-
it {
|
378
|
+
it { is_expected.to be_empty }
|
381
379
|
end
|
382
380
|
|
383
381
|
context 'with services.name' do
|
@@ -389,7 +387,7 @@ describe MetasploitDataModels::Search::Visitor::Joins do
|
|
389
387
|
"services.name:\"#{name}\""
|
390
388
|
end
|
391
389
|
|
392
|
-
it {
|
390
|
+
it { is_expected.to include :services }
|
393
391
|
end
|
394
392
|
end
|
395
393
|
end
|
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
describe MetasploitDataModels::Search::Visitor::Method do
|
1
|
+
RSpec.describe MetasploitDataModels::Search::Visitor::Method, type: :model do
|
4
2
|
subject(:visitor) do
|
5
3
|
described_class.new
|
6
4
|
end
|
@@ -21,7 +19,7 @@ describe MetasploitDataModels::Search::Visitor::Method do
|
|
21
19
|
Metasploit::Model::Search::Group::Intersection
|
22
20
|
end
|
23
21
|
|
24
|
-
it {
|
22
|
+
it { is_expected.to eq(:and) }
|
25
23
|
end
|
26
24
|
|
27
25
|
context 'with Metasploit::Model::Search::Operation::Group::Intersection' do
|
@@ -29,7 +27,7 @@ describe MetasploitDataModels::Search::Visitor::Method do
|
|
29
27
|
Metasploit::Model::Search::Operation::Group::Intersection
|
30
28
|
end
|
31
29
|
|
32
|
-
it {
|
30
|
+
it { is_expected.to eq(:and) }
|
33
31
|
end
|
34
32
|
|
35
33
|
context 'with Metasploit::Model::Search::Group::Union' do
|
@@ -37,7 +35,7 @@ describe MetasploitDataModels::Search::Visitor::Method do
|
|
37
35
|
Metasploit::Model::Search::Group::Union
|
38
36
|
end
|
39
37
|
|
40
|
-
it {
|
38
|
+
it { is_expected.to eq(:or) }
|
41
39
|
end
|
42
40
|
|
43
41
|
context 'with Metasploit::Model::Search::Operation::Group::Union' do
|
@@ -45,7 +43,7 @@ describe MetasploitDataModels::Search::Visitor::Method do
|
|
45
43
|
Metasploit::Model::Search::Operation::Group::Union
|
46
44
|
end
|
47
45
|
|
48
|
-
it {
|
46
|
+
it { is_expected.to eq(:or) }
|
49
47
|
end
|
50
48
|
end
|
51
49
|
end
|
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
describe MetasploitDataModels::Search::Visitor::Relation do
|
1
|
+
RSpec.describe MetasploitDataModels::Search::Visitor::Relation, type: :model do
|
4
2
|
subject(:visitor) do
|
5
3
|
described_class.new(
|
6
4
|
:query => query
|
@@ -31,7 +29,7 @@ describe MetasploitDataModels::Search::Visitor::Relation do
|
|
31
29
|
|
32
30
|
context 'validations' do
|
33
31
|
context 'query' do
|
34
|
-
it {
|
32
|
+
it { is_expected.to validate_presence_of(:query) }
|
35
33
|
|
36
34
|
context 'valid' do
|
37
35
|
let(:error) do
|
@@ -48,7 +46,7 @@ describe MetasploitDataModels::Search::Visitor::Relation do
|
|
48
46
|
end
|
49
47
|
|
50
48
|
before(:each) do
|
51
|
-
query.
|
49
|
+
allow(query).to receive(:valid?).and_return(query)
|
52
50
|
|
53
51
|
visitor.valid?
|
54
52
|
end
|
@@ -59,7 +57,7 @@ describe MetasploitDataModels::Search::Visitor::Relation do
|
|
59
57
|
end
|
60
58
|
|
61
59
|
it 'should not record error' do
|
62
|
-
errors.
|
60
|
+
expect(errors).not_to include(error)
|
63
61
|
end
|
64
62
|
end
|
65
63
|
|
@@ -69,7 +67,7 @@ describe MetasploitDataModels::Search::Visitor::Relation do
|
|
69
67
|
end
|
70
68
|
|
71
69
|
it 'should record error' do
|
72
|
-
errors.
|
70
|
+
expect(errors).not_to include(error)
|
73
71
|
end
|
74
72
|
end
|
75
73
|
end
|
@@ -80,7 +78,7 @@ describe MetasploitDataModels::Search::Visitor::Relation do
|
|
80
78
|
end
|
81
79
|
|
82
80
|
it 'should not record error' do
|
83
|
-
errors.
|
81
|
+
expect(errors).not_to include(error)
|
84
82
|
end
|
85
83
|
end
|
86
84
|
end
|
@@ -98,16 +96,16 @@ describe MetasploitDataModels::Search::Visitor::Relation do
|
|
98
96
|
end
|
99
97
|
|
100
98
|
it 'should visit Metasploit::Model::Search::Query#tree' do
|
101
|
-
includes_visitor.
|
99
|
+
expect(includes_visitor).to receive(:visit).with(query.tree)
|
102
100
|
|
103
101
|
visit
|
104
102
|
end
|
105
103
|
|
106
104
|
it 'should pass visited to ActiveRecord::Relation#includes' do
|
107
105
|
visited = double('Visited')
|
108
|
-
includes_visitor.
|
106
|
+
allow(includes_visitor).to receive(:visit).with(query.tree).and_return(visited)
|
109
107
|
|
110
|
-
ActiveRecord::Relation.
|
108
|
+
expect_any_instance_of(ActiveRecord::Relation).to receive(:includes).with(visited).and_return(query.klass.scoped)
|
111
109
|
|
112
110
|
visit
|
113
111
|
end
|
@@ -119,16 +117,16 @@ describe MetasploitDataModels::Search::Visitor::Relation do
|
|
119
117
|
end
|
120
118
|
|
121
119
|
it 'should visit Metasploit::Model::Search::Query#tree' do
|
122
|
-
joins_visitor.
|
120
|
+
expect(joins_visitor).to receive(:visit).with(query.tree)
|
123
121
|
|
124
122
|
visit
|
125
123
|
end
|
126
124
|
|
127
125
|
it 'should pass visited to ActiveRecord::Relation#joins' do
|
128
126
|
visited = double('Visited')
|
129
|
-
joins_visitor.
|
127
|
+
allow(joins_visitor).to receive(:visit).with(query.tree).and_return(visited)
|
130
128
|
|
131
|
-
ActiveRecord::Relation.
|
129
|
+
expect_any_instance_of(ActiveRecord::Relation).to receive(:joins).with(visited).and_return(query.klass.scoped)
|
132
130
|
|
133
131
|
visit
|
134
132
|
end
|
@@ -140,16 +138,16 @@ describe MetasploitDataModels::Search::Visitor::Relation do
|
|
140
138
|
end
|
141
139
|
|
142
140
|
it 'should visit Metasploit::Model::Search::Query#tree' do
|
143
|
-
where_visitor.
|
141
|
+
expect(where_visitor).to receive(:visit).with(query.tree)
|
144
142
|
|
145
143
|
visit
|
146
144
|
end
|
147
145
|
|
148
146
|
it 'should pass visited to ActiveRecord::Relation#includes' do
|
149
147
|
visited = double('Visited')
|
150
|
-
where_visitor.
|
148
|
+
allow(where_visitor).to receive(:visit).with(query.tree).and_return(visited)
|
151
149
|
|
152
|
-
ActiveRecord::Relation.
|
150
|
+
expect_any_instance_of(ActiveRecord::Relation).to receive(:where).with(visited).and_return(query.klass.scoped)
|
153
151
|
|
154
152
|
visit
|
155
153
|
end
|
@@ -870,9 +868,29 @@ describe MetasploitDataModels::Search::Visitor::Relation do
|
|
870
868
|
visitor.visitor_by_relation_method
|
871
869
|
end
|
872
870
|
|
873
|
-
|
874
|
-
|
875
|
-
|
871
|
+
context 'joins' do
|
872
|
+
subject(:joins) {
|
873
|
+
visitor_by_relation_method[:joins]
|
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
|
876
894
|
end
|
877
895
|
|
878
896
|
context 'visitor_class_by_relation_method' do
|
@@ -880,8 +898,28 @@ describe MetasploitDataModels::Search::Visitor::Relation do
|
|
880
898
|
described_class.visitor_class_by_relation_method
|
881
899
|
end
|
882
900
|
|
883
|
-
|
884
|
-
|
885
|
-
|
901
|
+
context 'joins' do
|
902
|
+
subject(:joins) {
|
903
|
+
visitor_class_by_relation_method[:joins]
|
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
|
886
924
|
end
|
887
925
|
end
|