metasploit_data_models 0.17.1 → 0.17.2.pre.metasploit.pre.data.pre.models.pre.search

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +8 -8
  2. data/.travis.yml +4 -0
  3. data/Gemfile +2 -0
  4. data/app/models/mdm/host.rb +24 -0
  5. data/app/models/mdm/service.rb +9 -0
  6. data/app/models/metasploit_data_models/search/visitor/attribute.rb +13 -0
  7. data/app/models/metasploit_data_models/search/visitor/includes.rb +28 -0
  8. data/app/models/metasploit_data_models/search/visitor/joins.rb +47 -0
  9. data/app/models/metasploit_data_models/search/visitor/method.rb +13 -0
  10. data/app/models/metasploit_data_models/search/visitor/relation.rb +87 -0
  11. data/app/models/metasploit_data_models/search/visitor/where.rb +65 -0
  12. data/config/locales/en.yml +7 -0
  13. data/lib/metasploit_data_models.rb +1 -0
  14. data/lib/metasploit_data_models/search.rb +6 -0
  15. data/lib/metasploit_data_models/search/visitor.rb +8 -0
  16. data/lib/metasploit_data_models/version.rb +1 -1
  17. data/metasploit_data_models.gemspec +1 -0
  18. data/spec/app/models/metasploit_data_models/search/visitor/attribute_spec.rb +74 -0
  19. data/spec/app/models/metasploit_data_models/search/visitor/includes_spec.rb +124 -0
  20. data/spec/app/models/metasploit_data_models/search/visitor/joins_spec.rb +292 -0
  21. data/spec/app/models/metasploit_data_models/search/visitor/method_spec.rb +33 -0
  22. data/spec/app/models/metasploit_data_models/search/visitor/relation_spec.rb +253 -0
  23. data/spec/app/models/metasploit_data_models/search/visitor/where_spec.rb +147 -0
  24. data/spec/dummy/config/initializers/active_record_migrations.rb +4 -0
  25. data/spec/factories/mdm/services.rb +5 -0
  26. data/spec/support/shared/examples/metasploit_data_models/search/visitor/includes/visit/with_children.rb +38 -0
  27. data/spec/support/shared/examples/metasploit_data_models/search/visitor/includes/visit/with_metasploit_model_search_operation_base.rb +26 -0
  28. data/spec/support/shared/examples/metasploit_data_models/search/visitor/relation/visit/matching_record.rb +37 -0
  29. data/spec/support/shared/examples/metasploit_data_models/search/visitor/relation/visit/matching_record/with_metasploit_model_search_opeator_deprecated_platform.rb +31 -0
  30. data/spec/support/shared/examples/metasploit_data_models/search/visitor/relation/visit/matching_record/with_metasploit_model_search_operator_deprecated_authority.rb +78 -0
  31. data/spec/support/shared/examples/metasploit_data_models/search/visitor/where/visit/with_equality.rb +34 -0
  32. data/spec/support/shared/examples/metasploit_data_models/search/visitor/where/visit/with_metasploit_model_search_group_base.rb +50 -0
  33. metadata +61 -4
@@ -0,0 +1,26 @@
1
+ shared_examples_for 'MetasploitDataModels::Search::Visitor::Includes#visit with Metasploit::Model::Search::Operation::Base' do
2
+ let(:operator) do
3
+ double('Operation Operator')
4
+ end
5
+
6
+ let(:node) do
7
+ node_class.new(
8
+ :operator => operator
9
+ )
10
+ end
11
+
12
+ it 'should visit operator' do
13
+ visitor.should_receive(:visit).with(node).and_call_original
14
+ visitor.should_receive(:visit).with(operator).and_return([])
15
+
16
+ visit
17
+ end
18
+
19
+ it 'should return operator visit' do
20
+ operator_visit = ["Visited Operator"]
21
+ visitor.should_receive(:visit).with(node).and_call_original
22
+ visitor.stub(:visit).with(operator).and_return(operator_visit)
23
+
24
+ visit.should == operator_visit
25
+ end
26
+ end
@@ -0,0 +1,37 @@
1
+ shared_examples_for 'MetasploitDataModels::Search::Visitor::Relation#visit matching record' do |options={}|
2
+ options.assert_valid_keys(:attribute, :association)
3
+
4
+ attribute = options.fetch(:attribute)
5
+ association = options[:association]
6
+
7
+ if association
8
+ formatted_operator = "#{association}.#{attribute}"
9
+ else
10
+ formatted_operator = attribute.to_s
11
+ end
12
+
13
+ context "with #{formatted_operator}" do
14
+ let(:formatted) do
15
+ "#{formatted_operator}:\"#{value}\""
16
+ end
17
+
18
+ if association
19
+ let(:associated) do
20
+ # wrap in array so single and plural associations can be handled the same.
21
+ Array.wrap(matching_record.send(association)).first
22
+ end
23
+
24
+ let(:value) do
25
+ associated.send(attribute)
26
+ end
27
+ else
28
+ let(:value) do
29
+ matching_record.send(attribute)
30
+ end
31
+ end
32
+
33
+ it 'should find only matching record' do
34
+ expect(visit).to match_array([matching_record])
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,31 @@
1
+ shared_examples_for 'MetasploitDataModels::Search::Visitor::Relation#visit matching record with Metasploit::Model::Search::Operator::Deprecated::Platform' do |options={}|
2
+ options.assert_valid_keys(:name)
3
+
4
+ name = options.fetch(:name)
5
+
6
+ context "with #{name}" do
7
+ let(:formatted) do
8
+ "#{name}:\"#{value}\""
9
+ end
10
+
11
+ context 'with Mdm::Platform#fully_qualified_name' do
12
+ let(:value) do
13
+ matching_record.platforms.sample.fully_qualified_name
14
+ end
15
+
16
+ it 'should find only matching record' do
17
+ expect(visit).to match_array([matching_record])
18
+ end
19
+ end
20
+
21
+ context 'with Mdm::Module::Target#name' do
22
+ let(:value) do
23
+ matching_record.targets.sample.name
24
+ end
25
+
26
+ it 'should find only matching record' do
27
+ expect(visit).to match_array([matching_record])
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,78 @@
1
+ shared_examples_for 'MetasploitDataModels::Search::Visitor::Relation#visit matching record with Metasploit::Model::Search::Operator::Deprecated::Authority' do |options={}|
2
+ options.assert_valid_keys(:abbreviation)
3
+
4
+ abbreviation = options.fetch(:abbreviation)
5
+
6
+ context "with #{abbreviation}" do
7
+ #
8
+ # lets
9
+ #
10
+
11
+ let(:formatted) do
12
+ "#{abbreviation}:#{value}"
13
+ end
14
+
15
+ let(:matching_authority) do
16
+ FactoryGirl.create(
17
+ :mdm_authority,
18
+ :abbreviation => abbreviation
19
+ )
20
+ end
21
+
22
+ let(:matching_record) do
23
+ FactoryGirl.build(
24
+ :mdm_module_instance,
25
+ module_class: matching_module_class,
26
+ # disable factory making references automatically so Mdm::Module::Reference#reference can be set to
27
+ # matching_reference
28
+ module_references_length: 0
29
+ ).tap { |module_instance|
30
+ module_instance.module_references << FactoryGirl.build(
31
+ :mdm_module_reference,
32
+ module_instance: module_instance,
33
+ reference: matching_reference
34
+ )
35
+ }
36
+ end
37
+
38
+ let(:matching_reference) do
39
+ FactoryGirl.create(
40
+ :mdm_reference,
41
+ :authority => matching_authority
42
+ )
43
+ end
44
+
45
+ let(:non_matching_authority) do
46
+ FactoryGirl.create(:mdm_authority)
47
+ end
48
+
49
+ let(:non_matching_record) do
50
+ FactoryGirl.build(
51
+ :mdm_module_instance,
52
+ module_class: non_matching_module_class,
53
+ module_references_length: 0
54
+ ).tap { |module_instance|
55
+ module_instance.module_references << FactoryGirl.build(
56
+ :mdm_module_reference,
57
+ module_instance: module_instance,
58
+ reference: non_matching_reference
59
+ )
60
+ }
61
+ end
62
+
63
+ let(:non_matching_reference) do
64
+ FactoryGirl.create(
65
+ :mdm_reference,
66
+ :authority => non_matching_authority
67
+ )
68
+ end
69
+
70
+ let(:value) do
71
+ matching_reference.designation
72
+ end
73
+
74
+ it 'should find only matching record' do
75
+ expect(visit).to match_array([matching_record])
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,34 @@
1
+ shared_examples_for 'MetasploitDataModels::Search::Visitor::Where#visit with equality operation' do
2
+ let(:node) do
3
+ node_class.new(
4
+ :operator => operator,
5
+ :value => value
6
+ )
7
+ end
8
+
9
+ let(:operator) do
10
+ Metasploit::Model::Search::Operator::Attribute.new(
11
+ # any class that responds to arel_table
12
+ :klass => Mdm::Host
13
+ )
14
+ end
15
+
16
+ let(:value) do
17
+ "value"
18
+ end
19
+
20
+ it 'should visit operation.operator with attribute_visitor' do
21
+ visitor.attribute_visitor.should_receive(:visit).with(operator).and_call_original
22
+
23
+ visit
24
+ end
25
+
26
+ it 'should call eq on Arel::Attributes::Attribute from attribute_visitor' do
27
+ attribute = double('Visited Operator')
28
+ visitor.attribute_visitor.stub(:visit).with(operator).and_return(attribute)
29
+
30
+ attribute.should_receive(:eq).with(value)
31
+
32
+ visit
33
+ end
34
+ end
@@ -0,0 +1,50 @@
1
+ shared_examples_for 'MetasploitDataModels::Search::Visitor::Where#visit with Metasploit::Model::Search::Group::Base' do |options={}|
2
+ options.assert_valid_keys(:arel_class)
3
+
4
+ arel_class = options.fetch(:arel_class)
5
+
6
+ let(:children) do
7
+ 2.times.collect { |n|
8
+ double("Group Child #{n}")
9
+ }
10
+ end
11
+
12
+ let(:node) do
13
+ node_class.new(
14
+ :children => children
15
+ )
16
+ end
17
+
18
+ it 'should visit each child' do
19
+ visitor.should_receive(:visit).with(node).and_call_original
20
+
21
+ children.each do |child|
22
+ visitor.should_receive(:visit).with(child).and_return(Arel::Nodes::Equality.new(1, 1))
23
+ end
24
+
25
+ visit
26
+ end
27
+
28
+ it "should combine children AREL with #{arel_class}" do
29
+ visitor.stub(:visit).with(node).and_call_original
30
+ child_visits = []
31
+
32
+ children.each_with_index do |child, i|
33
+ child_visit = Arel::Nodes::Equality.new(i, i)
34
+ visitor.stub(:visit).with(child).and_return(child_visit)
35
+ child_visits << child_visit
36
+ end
37
+
38
+ root = visit
39
+
40
+ if root.is_a? Arel::Nodes::Grouping
41
+ arel_pair = root.expr
42
+ else
43
+ arel_pair = root
44
+ end
45
+
46
+ arel_pair.should be_a arel_class
47
+
48
+ expect([arel_pair.left, arel_pair.right]).to match_array(child_visits)
49
+ end
50
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metasploit_data_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.1
4
+ version: 0.17.2.pre.metasploit.pre.data.pre.models.pre.search
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Huckins
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2014-05-09 00:00:00.000000000 Z
14
+ date: 2014-06-16 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rake
@@ -89,6 +89,26 @@ dependencies:
89
89
  - - ! '>='
90
90
  - !ruby/object:Gem::Version
91
91
  version: '0'
92
+ - !ruby/object:Gem::Dependency
93
+ name: metasploit-model
94
+ requirement: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: 0.24.1.pre.semantic.pre.versioning.pre.2.pre.0
99
+ - - <
100
+ - !ruby/object:Gem::Version
101
+ version: '0.25'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: 0.24.1.pre.semantic.pre.versioning.pre.2.pre.0
109
+ - - <
110
+ - !ruby/object:Gem::Version
111
+ version: '0.25'
92
112
  - !ruby/object:Gem::Dependency
93
113
  name: redcarpet
94
114
  requirement: !ruby/object:Gem::Requirement
@@ -186,10 +206,17 @@ files:
186
206
  - app/models/mdm/wmap_request.rb
187
207
  - app/models/mdm/wmap_target.rb
188
208
  - app/models/mdm/workspace.rb
209
+ - app/models/metasploit_data_models/search/visitor/attribute.rb
210
+ - app/models/metasploit_data_models/search/visitor/includes.rb
211
+ - app/models/metasploit_data_models/search/visitor/joins.rb
212
+ - app/models/metasploit_data_models/search/visitor/method.rb
213
+ - app/models/metasploit_data_models/search/visitor/relation.rb
214
+ - app/models/metasploit_data_models/search/visitor/where.rb
189
215
  - app/validators/ip_format_validator.rb
190
216
  - app/validators/parameters_validator.rb
191
217
  - app/validators/password_is_strong_validator.rb
192
218
  - bin/mdm_console
219
+ - config/locales/en.yml
193
220
  - console_db.yml
194
221
  - db/migrate/000_create_tables.rb
195
222
  - db/migrate/001_add_wmap_tables.rb
@@ -306,6 +333,8 @@ files:
306
333
  - lib/metasploit_data_models/change_required_columns_to_null_false.rb
307
334
  - lib/metasploit_data_models/engine.rb
308
335
  - lib/metasploit_data_models/models.rb
336
+ - lib/metasploit_data_models/search.rb
337
+ - lib/metasploit_data_models/search/visitor.rb
309
338
  - lib/metasploit_data_models/serialized_prefs.rb
310
339
  - lib/metasploit_data_models/validators.rb
311
340
  - lib/metasploit_data_models/version.rb
@@ -353,6 +382,12 @@ files:
353
382
  - spec/app/models/mdm/web_site_spec.rb
354
383
  - spec/app/models/mdm/web_vuln_spec.rb
355
384
  - spec/app/models/mdm/workspace_spec.rb
385
+ - spec/app/models/metasploit_data_models/search/visitor/attribute_spec.rb
386
+ - spec/app/models/metasploit_data_models/search/visitor/includes_spec.rb
387
+ - spec/app/models/metasploit_data_models/search/visitor/joins_spec.rb
388
+ - spec/app/models/metasploit_data_models/search/visitor/method_spec.rb
389
+ - spec/app/models/metasploit_data_models/search/visitor/relation_spec.rb
390
+ - spec/app/models/metasploit_data_models/search/visitor/where_spec.rb
356
391
  - spec/app/validators/parameters_validator_spec.rb
357
392
  - spec/app/validators/password_is_strong_validator_spec.rb
358
393
  - spec/dummy/Rakefile
@@ -372,6 +407,7 @@ files:
372
407
  - spec/dummy/config/environments/development.rb
373
408
  - spec/dummy/config/environments/production.rb
374
409
  - spec/dummy/config/environments/test.rb
410
+ - spec/dummy/config/initializers/active_record_migrations.rb
375
411
  - spec/dummy/config/initializers/backtrace_silencers.rb
376
412
  - spec/dummy/config/initializers/inflections.rb
377
413
  - spec/dummy/config/initializers/mime_types.rb
@@ -438,6 +474,13 @@ files:
438
474
  - spec/spec_helper.rb
439
475
  - spec/support/shared/examples/mdm/module/detail/does_not_support_stance_with_mtype.rb
440
476
  - spec/support/shared/examples/mdm/module/detail/supports_stance_with_mtype.rb
477
+ - spec/support/shared/examples/metasploit_data_models/search/visitor/includes/visit/with_children.rb
478
+ - spec/support/shared/examples/metasploit_data_models/search/visitor/includes/visit/with_metasploit_model_search_operation_base.rb
479
+ - spec/support/shared/examples/metasploit_data_models/search/visitor/relation/visit/matching_record.rb
480
+ - spec/support/shared/examples/metasploit_data_models/search/visitor/relation/visit/matching_record/with_metasploit_model_search_opeator_deprecated_platform.rb
481
+ - spec/support/shared/examples/metasploit_data_models/search/visitor/relation/visit/matching_record/with_metasploit_model_search_operator_deprecated_authority.rb
482
+ - spec/support/shared/examples/metasploit_data_models/search/visitor/where/visit/with_equality.rb
483
+ - spec/support/shared/examples/metasploit_data_models/search/visitor/where/visit/with_metasploit_model_search_group_base.rb
441
484
  homepage: ''
442
485
  licenses: []
443
486
  metadata: {}
@@ -452,9 +495,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
452
495
  version: '0'
453
496
  required_rubygems_version: !ruby/object:Gem::Requirement
454
497
  requirements:
455
- - - ! '>='
498
+ - - ! '>'
456
499
  - !ruby/object:Gem::Version
457
- version: '0'
500
+ version: 1.3.1
458
501
  requirements: []
459
502
  rubyforge_project:
460
503
  rubygems_version: 2.2.2
@@ -503,6 +546,12 @@ test_files:
503
546
  - spec/app/models/mdm/web_site_spec.rb
504
547
  - spec/app/models/mdm/web_vuln_spec.rb
505
548
  - spec/app/models/mdm/workspace_spec.rb
549
+ - spec/app/models/metasploit_data_models/search/visitor/attribute_spec.rb
550
+ - spec/app/models/metasploit_data_models/search/visitor/includes_spec.rb
551
+ - spec/app/models/metasploit_data_models/search/visitor/joins_spec.rb
552
+ - spec/app/models/metasploit_data_models/search/visitor/method_spec.rb
553
+ - spec/app/models/metasploit_data_models/search/visitor/relation_spec.rb
554
+ - spec/app/models/metasploit_data_models/search/visitor/where_spec.rb
506
555
  - spec/app/validators/parameters_validator_spec.rb
507
556
  - spec/app/validators/password_is_strong_validator_spec.rb
508
557
  - spec/dummy/Rakefile
@@ -522,6 +571,7 @@ test_files:
522
571
  - spec/dummy/config/environments/development.rb
523
572
  - spec/dummy/config/environments/production.rb
524
573
  - spec/dummy/config/environments/test.rb
574
+ - spec/dummy/config/initializers/active_record_migrations.rb
525
575
  - spec/dummy/config/initializers/backtrace_silencers.rb
526
576
  - spec/dummy/config/initializers/inflections.rb
527
577
  - spec/dummy/config/initializers/mime_types.rb
@@ -588,4 +638,11 @@ test_files:
588
638
  - spec/spec_helper.rb
589
639
  - spec/support/shared/examples/mdm/module/detail/does_not_support_stance_with_mtype.rb
590
640
  - spec/support/shared/examples/mdm/module/detail/supports_stance_with_mtype.rb
641
+ - spec/support/shared/examples/metasploit_data_models/search/visitor/includes/visit/with_children.rb
642
+ - spec/support/shared/examples/metasploit_data_models/search/visitor/includes/visit/with_metasploit_model_search_operation_base.rb
643
+ - spec/support/shared/examples/metasploit_data_models/search/visitor/relation/visit/matching_record.rb
644
+ - spec/support/shared/examples/metasploit_data_models/search/visitor/relation/visit/matching_record/with_metasploit_model_search_opeator_deprecated_platform.rb
645
+ - spec/support/shared/examples/metasploit_data_models/search/visitor/relation/visit/matching_record/with_metasploit_model_search_operator_deprecated_authority.rb
646
+ - spec/support/shared/examples/metasploit_data_models/search/visitor/where/visit/with_equality.rb
647
+ - spec/support/shared/examples/metasploit_data_models/search/visitor/where/visit/with_metasploit_model_search_group_base.rb
591
648
  has_rdoc: