metasploit-model 0.25.7 → 0.26.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. checksums.yaml +8 -8
  2. data/app/models/metasploit/model/search/operation/association.rb +57 -0
  3. data/app/models/metasploit/model/search/operator/association.rb +24 -14
  4. data/app/models/metasploit/model/search/operator/base.rb +19 -3
  5. data/app/models/metasploit/model/search/operator/single.rb +21 -1
  6. data/app/models/metasploit/model/search/query.rb +20 -1
  7. data/lib/metasploit/model/association/tree.rb +130 -0
  8. data/lib/metasploit/model/search.rb +61 -27
  9. data/lib/metasploit/model/search/association.rb +152 -8
  10. data/lib/metasploit/model/search/attribute.rb +112 -22
  11. data/lib/metasploit/model/search/operator.rb +53 -1
  12. data/lib/metasploit/model/search/operator/help.rb +39 -1
  13. data/lib/metasploit/model/search/with.rb +44 -1
  14. data/lib/metasploit/model/version.rb +2 -2
  15. data/spec/app/models/metasploit/model/search/operation/association_spec.rb +67 -0
  16. data/spec/app/models/metasploit/model/search/operator/association_spec.rb +76 -76
  17. data/spec/app/models/metasploit/model/search/operator/deprecated/author_spec.rb +54 -18
  18. data/spec/app/models/metasploit/model/search/operator/deprecated/authority_spec.rb +20 -8
  19. data/spec/app/models/metasploit/model/search/operator/deprecated/platform_spec.rb +20 -8
  20. data/spec/app/models/metasploit/model/search/operator/deprecated/ref_spec.rb +86 -26
  21. data/spec/app/models/metasploit/model/search/operator/deprecated/text_spec.rb +63 -21
  22. data/spec/lib/metasploit/model/search/association/tree_spec.rb +385 -0
  23. data/spec/lib/metasploit/model/search/association_spec.rb +99 -10
  24. data/spec/lib/metasploit/model/search_spec.rb +48 -107
  25. data/spec/support/shared/examples/search/query/metasploit/model/search/operator/deprecated/authority.rb +19 -7
  26. metadata +7 -1
@@ -10,24 +10,113 @@ describe Metasploit::Model::Search::Association do
10
10
  end
11
11
 
12
12
  context 'search_association' do
13
- it 'should add Symbol to search_association_set' do
14
- association_string = 'associated_things'
13
+ subject(:search_association) {
14
+ base_class.search_association association
15
+ }
15
16
 
16
- base_class.class_eval do
17
- search_association association_string
17
+ let(:association) {
18
+ :root_association
19
+ }
20
+
21
+ context 'with previous call to search_association with same association' do
22
+ before(:each) do
23
+ base_class.search_association association
24
+ end
25
+
26
+ it 'does not change search_association_tree' do
27
+ expect {
28
+ search_association
29
+ }.not_to change(base_class, :search_association_tree)
18
30
  end
31
+ end
19
32
 
20
- base_class.search_association_set.should include(association_string.to_sym)
33
+ context 'with association tree rooted on association' do
34
+ before(:each) do
35
+ base_class.search_associations association => :child_association
36
+ end
37
+
38
+ it 'leaves the original association tree in place' do
39
+ expect {
40
+ search_association
41
+ }.not_to change(base_class, :search_association_tree)
42
+ end
43
+ end
44
+
45
+ context 'without association in search_association_tree' do
46
+ it 'adds association to search_association_tree with nil children' do
47
+ search_association
48
+
49
+ search_association_tree = base_class.search_association_tree
50
+
51
+ expect(search_association_tree).to have_key(association)
52
+ expect(search_association_tree[association]).to be_nil
53
+ end
21
54
  end
22
55
  end
23
56
 
24
- context 'search_association_set' do
25
- let(:search_association_set) do
26
- base_class.search_association_set
57
+ context 'search_associations' do
58
+ subject(:search_associations) {
59
+ base_class.search_associations *associations
60
+ }
61
+
62
+ let(:associations) {
63
+ [
64
+ :association
65
+ ]
66
+ }
67
+
68
+ let(:expanded_associations) {
69
+ {
70
+ association: nil
71
+ }
72
+ }
73
+
74
+ it 'expands associations' do
75
+ expect(Metasploit::Model::Association::Tree).to receive(:expand).with(associations).and_return(
76
+ expanded_associations
77
+ )
78
+
79
+ search_associations
80
+ end
81
+
82
+ it 'merges the expanded associations with the current search_association_tree' do
83
+ expect(Metasploit::Model::Association::Tree).to receive(:expand).and_return(expanded_associations)
84
+
85
+ search_association_tree = {preexisting: nil}
86
+ expect(base_class).to receive(:search_association_tree).and_return(search_association_tree)
87
+
88
+ expect(Metasploit::Model::Association::Tree).to receive(:merge).with(
89
+ search_association_tree,
90
+ expanded_associations
91
+ )
92
+
93
+ search_associations
27
94
  end
95
+ end
96
+
97
+ context 'search_association_operators' do
98
+ subject(:search_association_operators) {
99
+ base_class.search_association_operators
100
+ }
101
+
102
+ let(:search_association_tree) {
103
+ {
104
+ parent: {
105
+ child: nil
106
+ }
107
+ }
108
+ }
109
+
110
+ it 'converts search_association_tree to operators' do
111
+ expect(base_class).to receive(:search_association_tree).and_return(search_association_tree)
112
+ expect(Metasploit::Model::Association::Tree).to receive(:operators).with(
113
+ search_association_tree,
114
+ hash_including(
115
+ class: base_class
116
+ )
117
+ )
28
118
 
29
- it 'should default to an empty Set' do
30
- search_association_set.should == Set.new
119
+ search_association_operators
31
120
  end
32
121
  end
33
122
  end
@@ -52,139 +52,80 @@ describe Metasploit::Model::Search do
52
52
  end
53
53
 
54
54
  context 'with search association' do
55
+ let(:associated_attribute) do
56
+ :association_name
57
+ end
58
+
55
59
  let(:association) do
56
60
  :associated_things
57
61
  end
58
62
 
63
+ let(:association_class) do
64
+ Class.new
65
+ end
66
+
67
+ let(:class_name) do
68
+ 'AssociatedThing'
69
+ end
70
+
59
71
  before(:each) do
60
72
  base_class.search_association association
73
+ base_class.send(:include, Metasploit::Model::Association)
74
+
75
+ stub_const(class_name, association_class)
76
+
77
+ # Include after stub so search_i18n_scope can use Class#name without error
78
+ association_class.send(:include, Metasploit::Model::Search)
79
+ association_class.search_attribute associated_attribute, :type => :string
80
+
81
+ base_class.association association, :class_name => class_name
61
82
  end
62
83
 
63
- context 'with reflect_on_association' do
64
- before(:each) do
65
- base_class.send(:include, Metasploit::Model::Association)
84
+ context 'operator' do
85
+ subject(:operator) do
86
+ search_operator_by_name[expected_name]
87
+ end
88
+
89
+ let(:expected_name) do
90
+ "#{association}.#{associated_attribute}".to_sym
66
91
  end
67
92
 
68
- context 'with association' do
69
- let(:associated_attribute) do
70
- :association_name
71
- end
93
+ it { should be_a Metasploit::Model::Search::Operator::Association }
72
94
 
73
- let(:association_class) do
74
- Class.new
95
+ context 'association' do
96
+ subject(:operator_association) do
97
+ operator.association
75
98
  end
76
99
 
77
- let(:class_name) do
78
- 'AssociatedThing'
100
+ it 'should be the registered association' do
101
+ operator_association.should == association
79
102
  end
103
+ end
80
104
 
81
- before(:each) do
82
- stub_const(class_name, association_class)
83
-
84
- # Include after stub so search_i18n_scope can use Class#name without error
85
- association_class.send(:include, Metasploit::Model::Search)
86
- association_class.search_attribute associated_attribute, :type => :string
105
+ context 'source_operator' do
106
+ subject(:source_operator) do
107
+ operator.source_operator
108
+ end
87
109
 
88
- base_class.association association, :class_name => class_name
110
+ let(:direct_attribute_operator) do
111
+ association_class.search_operator_by_name.values.first
89
112
  end
90
113
 
91
- context 'operator' do
92
- subject(:operator) do
93
- search_operator_by_name[expected_name]
94
- end
95
-
96
- let(:expected_name) do
97
- "#{association}.#{associated_attribute}".to_sym
98
- end
99
-
100
- it { should be_a Metasploit::Model::Search::Operator::Association }
101
-
102
- context 'association' do
103
- subject(:operator_association) do
104
- operator.association
105
- end
106
-
107
- it 'should be the registered association' do
108
- operator_association.should == association
109
- end
110
- end
111
-
112
- context 'attribute_operator' do
113
- subject(:indirect_attribute_operator) do
114
- operator.attribute_operator
115
- end
116
-
117
- let(:direct_attribute_operator) do
118
- association_class.search_operator_by_name.values.first
119
- end
120
-
121
- it 'should be operator from associated class' do
122
- indirect_attribute_operator.should == direct_attribute_operator
123
- end
124
- end
125
-
126
- context 'klass' do
127
- subject(:klass) do
128
- operator.klass
129
- end
130
-
131
- it 'should be class that called search_operator_by_name' do
132
- klass.should == base_class
133
- end
134
- end
114
+ it 'should be operator from associated class' do
115
+ source_operator.should == direct_attribute_operator
135
116
  end
136
117
  end
137
118
 
138
- context 'without association' do
139
- it 'should raise Metasploit::Model::Association::Error' do
140
- expect {
141
- search_operator_by_name
142
- }.to raise_error(Metasploit::Model::Association::Error)
119
+ context 'klass' do
120
+ subject(:klass) do
121
+ operator.klass
143
122
  end
144
123
 
145
- context 'error' do
146
- let(:error) do
147
- begin
148
- search_operator_by_name
149
- rescue Metasploit::Model::Association::Error => error
150
- error
151
- end
152
- end
153
-
154
- context 'model' do
155
- subject(:model) do
156
- error.model
157
- end
158
-
159
- it 'should be class on which search_operator_by_name was called' do
160
- model.should == base_class
161
- end
162
- end
163
-
164
- context 'name' do
165
- subject(:name) do
166
- error.name
167
- end
168
-
169
- it 'should be association name' do
170
- name.should == association
171
- end
172
- end
124
+ it 'should be class that called search_operator_by_name' do
125
+ klass.should == base_class
173
126
  end
174
127
  end
175
128
  end
176
-
177
- context 'without reflect_on_association' do
178
- it 'should raise ArgumentError' do
179
- expect {
180
- search_operator_by_name
181
- }.to raise_error(
182
- NameError,
183
- "#{base_class} does not respond to reflect_on_association. " \
184
- "It can be added to ActiveModels by including Metasploit::Model::Association into the class."
185
- )
186
- end
187
- end
188
129
  end
189
130
 
190
131
  context 'with search with' do
@@ -37,7 +37,19 @@ shared_examples_for 'search query with Metasploit::Model::Search::Operator::Depr
37
37
  operation_with_formatted_operator('authorities.abbreviation')
38
38
  end
39
39
 
40
- its(:value) { should == formatted_operator }
40
+ context 'Metasploit::Model::Search::Operation::Association#source_operation' do
41
+ subject(:source_operation) {
42
+ operation.source_operation
43
+ }
44
+
45
+ context 'Metasploit::Model::Search::Operation::Base#value' do
46
+ subject(:value) {
47
+ source_operation.value
48
+ }
49
+
50
+ it { should == formatted_operator }
51
+ end
52
+ end
41
53
  end
42
54
 
43
55
  context 'references.designation' do
@@ -45,13 +57,13 @@ shared_examples_for 'search query with Metasploit::Model::Search::Operator::Depr
45
57
  operation_with_formatted_operator('references.designation')
46
58
  end
47
59
 
48
- context 'value' do
49
- subject(:value) do
50
- operation.value
51
- end
60
+ context 'Metasploit::Model::Search::Operation::Association#source_operation' do
61
+ subject(:source_operation) {
62
+ operation.source_operation
63
+ }
52
64
 
53
- it 'should be formatted value' do
54
- value.should == formatted_value
65
+ it 'uses formatted value for value' do
66
+ expect(source_operation.value).to eq(formatted_value)
55
67
  end
56
68
  end
57
69
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metasploit-model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.25.7
4
+ version: 0.26.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke Imhoff
@@ -106,6 +106,7 @@ files:
106
106
  - app/models/metasploit/model/search/group/base.rb
107
107
  - app/models/metasploit/model/search/group/intersection.rb
108
108
  - app/models/metasploit/model/search/group/union.rb
109
+ - app/models/metasploit/model/search/operation/association.rb
109
110
  - app/models/metasploit/model/search/operation/base.rb
110
111
  - app/models/metasploit/model/search/operation/boolean.rb
111
112
  - app/models/metasploit/model/search/operation/date.rb
@@ -147,6 +148,7 @@ files:
147
148
  - lib/metasploit/model/architecture.rb
148
149
  - lib/metasploit/model/association.rb
149
150
  - lib/metasploit/model/association/error.rb
151
+ - lib/metasploit/model/association/tree.rb
150
152
  - lib/metasploit/model/author.rb
151
153
  - lib/metasploit/model/authority.rb
152
154
  - lib/metasploit/model/authority/bid.rb
@@ -225,6 +227,7 @@ files:
225
227
  - spec/app/models/metasploit/model/search/group/base_spec.rb
226
228
  - spec/app/models/metasploit/model/search/group/intersection_spec.rb
227
229
  - spec/app/models/metasploit/model/search/group/union_spec.rb
230
+ - spec/app/models/metasploit/model/search/operation/association_spec.rb
228
231
  - spec/app/models/metasploit/model/search/operation/base_spec.rb
229
232
  - spec/app/models/metasploit/model/search/operation/boolean_spec.rb
230
233
  - spec/app/models/metasploit/model/search/operation/date_spec.rb
@@ -399,6 +402,7 @@ files:
399
402
  - spec/lib/metasploit/model/platform_spec.rb
400
403
  - spec/lib/metasploit/model/realm/key_spec.rb
401
404
  - spec/lib/metasploit/model/reference_spec.rb
405
+ - spec/lib/metasploit/model/search/association/tree_spec.rb
402
406
  - spec/lib/metasploit/model/search/association_spec.rb
403
407
  - spec/lib/metasploit/model/search/attribute_spec.rb
404
408
  - spec/lib/metasploit/model/search/operation/integer/value_spec.rb
@@ -509,6 +513,7 @@ test_files:
509
513
  - spec/app/models/metasploit/model/search/group/base_spec.rb
510
514
  - spec/app/models/metasploit/model/search/group/intersection_spec.rb
511
515
  - spec/app/models/metasploit/model/search/group/union_spec.rb
516
+ - spec/app/models/metasploit/model/search/operation/association_spec.rb
512
517
  - spec/app/models/metasploit/model/search/operation/base_spec.rb
513
518
  - spec/app/models/metasploit/model/search/operation/boolean_spec.rb
514
519
  - spec/app/models/metasploit/model/search/operation/date_spec.rb
@@ -683,6 +688,7 @@ test_files:
683
688
  - spec/lib/metasploit/model/platform_spec.rb
684
689
  - spec/lib/metasploit/model/realm/key_spec.rb
685
690
  - spec/lib/metasploit/model/reference_spec.rb
691
+ - spec/lib/metasploit/model/search/association/tree_spec.rb
686
692
  - spec/lib/metasploit/model/search/association_spec.rb
687
693
  - spec/lib/metasploit/model/search/attribute_spec.rb
688
694
  - spec/lib/metasploit/model/search/operation/integer/value_spec.rb