metasploit-model 0.27.3 → 0.27.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.rspec +1 -1
- data/app/models/metasploit/model/association/reflection.rb +0 -3
- data/app/models/metasploit/model/module/ancestor/spec/template.rb +0 -3
- data/app/models/metasploit/model/module/class/spec/template.rb +0 -4
- data/app/models/metasploit/model/module/instance/spec/template.rb +0 -4
- data/app/models/metasploit/model/search/group/base.rb +0 -3
- data/app/models/metasploit/model/search/group/intersection.rb +0 -3
- data/app/models/metasploit/model/search/group/union.rb +0 -3
- data/app/models/metasploit/model/search/operation/association.rb +0 -2
- data/app/models/metasploit/model/search/operation/base.rb +0 -3
- data/app/models/metasploit/model/search/operation/boolean.rb +0 -2
- data/app/models/metasploit/model/search/operation/date.rb +0 -2
- data/app/models/metasploit/model/search/operation/group/base.rb +0 -2
- data/app/models/metasploit/model/search/operation/group/intersection.rb +0 -2
- data/app/models/metasploit/model/search/operation/group/union.rb +0 -2
- data/app/models/metasploit/model/search/operation/integer.rb +1 -5
- data/app/models/metasploit/model/search/operation/null.rb +0 -2
- data/app/models/metasploit/model/search/operation/set.rb +5 -2
- data/app/models/metasploit/model/search/operation/set/integer.rb +1 -3
- data/app/models/metasploit/model/search/operation/set/string.rb +1 -3
- data/app/models/metasploit/model/search/operation/string.rb +1 -5
- data/app/models/metasploit/model/search/operator/association.rb +0 -2
- data/app/models/metasploit/model/search/operator/attribute.rb +0 -2
- data/app/models/metasploit/model/search/operator/base.rb +0 -4
- data/app/models/metasploit/model/search/operator/delegation.rb +0 -2
- data/app/models/metasploit/model/search/operator/deprecated/app.rb +0 -2
- data/app/models/metasploit/model/search/operator/deprecated/author.rb +0 -2
- data/app/models/metasploit/model/search/operator/deprecated/authority.rb +0 -2
- data/app/models/metasploit/model/search/operator/deprecated/platform.rb +0 -2
- data/app/models/metasploit/model/search/operator/deprecated/ref.rb +0 -2
- data/app/models/metasploit/model/search/operator/deprecated/text.rb +0 -2
- data/app/models/metasploit/model/search/operator/group/base.rb +0 -2
- data/app/models/metasploit/model/search/operator/group/intersection.rb +0 -2
- data/app/models/metasploit/model/search/operator/group/union.rb +0 -2
- data/app/models/metasploit/model/search/operator/null.rb +0 -2
- data/app/models/metasploit/model/search/operator/single.rb +0 -2
- data/app/models/metasploit/model/search/query.rb +0 -3
- data/app/models/metasploit/model/spec/template.rb +0 -3
- data/app/models/metasploit/model/visitation/visitor.rb +0 -3
- data/lib/metasploit/model.rb +14 -8
- data/lib/metasploit/model/architecture.rb +320 -326
- data/lib/metasploit/model/association.rb +43 -46
- data/lib/metasploit/model/association/error.rb +29 -33
- data/lib/metasploit/model/association/tree.rb +119 -125
- data/lib/metasploit/model/author.rb +45 -51
- data/lib/metasploit/model/authority.rb +139 -146
- data/lib/metasploit/model/authority/bid.rb +0 -2
- data/lib/metasploit/model/authority/cve.rb +0 -2
- data/lib/metasploit/model/authority/msb.rb +0 -2
- data/lib/metasploit/model/authority/osvdb.rb +0 -2
- data/lib/metasploit/model/authority/pmasa.rb +0 -2
- data/lib/metasploit/model/authority/secunia.rb +0 -2
- data/lib/metasploit/model/authority/us_cert_vu.rb +0 -2
- data/lib/metasploit/model/authority/waraxe.rb +0 -2
- data/lib/metasploit/model/authority/zdi.rb +0 -2
- data/lib/metasploit/model/base.rb +0 -2
- data/lib/metasploit/model/derivation.rb +95 -99
- data/lib/metasploit/model/derivation/full_name.rb +16 -22
- data/lib/metasploit/model/email_address.rb +122 -128
- data/lib/metasploit/model/engine.rb +26 -21
- data/lib/metasploit/model/error.rb +3 -7
- data/lib/metasploit/model/file.rb +0 -2
- data/lib/metasploit/model/invalid.rb +11 -17
- data/lib/metasploit/model/login.rb +0 -3
- data/lib/metasploit/model/login/status.rb +0 -2
- data/lib/metasploit/model/module.rb +19 -23
- data/lib/metasploit/model/module/action.rb +50 -58
- data/lib/metasploit/model/module/ancestor.rb +456 -465
- data/lib/metasploit/model/module/ancestor/spec.rb +3 -2
- data/lib/metasploit/model/module/architecture.rb +27 -35
- data/lib/metasploit/model/module/author.rb +38 -47
- data/lib/metasploit/model/module/class.rb +358 -366
- data/lib/metasploit/model/module/class/spec.rb +3 -2
- data/lib/metasploit/model/module/handler.rb +28 -34
- data/lib/metasploit/model/module/instance.rb +586 -596
- data/lib/metasploit/model/module/instance/spec.rb +3 -2
- data/lib/metasploit/model/module/path.rb +157 -166
- data/lib/metasploit/model/module/platform.rb +25 -33
- data/lib/metasploit/model/module/rank.rb +71 -79
- data/lib/metasploit/model/module/reference.rb +25 -33
- data/lib/metasploit/model/module/stance.rb +15 -21
- data/lib/metasploit/model/module/target.rb +76 -84
- data/lib/metasploit/model/module/target/architecture.rb +27 -37
- data/lib/metasploit/model/module/target/platform.rb +27 -37
- data/lib/metasploit/model/module/type.rb +35 -41
- data/lib/metasploit/model/nilify_blanks.rb +39 -43
- data/lib/metasploit/model/platform.rb +231 -237
- data/lib/metasploit/model/real_pathname.rb +12 -16
- data/lib/metasploit/model/realm.rb +0 -2
- data/lib/metasploit/model/realm/key.rb +0 -2
- data/lib/metasploit/model/reference.rb +102 -108
- data/lib/metasploit/model/search.rb +94 -97
- data/lib/metasploit/model/search/association.rb +163 -169
- data/lib/metasploit/model/search/attribute.rb +131 -139
- data/lib/metasploit/model/search/group.rb +5 -2
- data/lib/metasploit/model/search/operation.rb +32 -29
- data/lib/metasploit/model/search/operation/group.rb +5 -2
- data/lib/metasploit/model/search/operation/value.rb +7 -0
- data/lib/metasploit/model/search/operation/{integer/value.rb → value/integer.rb} +1 -1
- data/lib/metasploit/model/search/operation/{string/value.rb → value/string.rb} +1 -1
- data/lib/metasploit/model/search/operator.rb +65 -65
- data/lib/metasploit/model/search/operator/deprecated.rb +8 -2
- data/lib/metasploit/model/search/operator/group.rb +5 -2
- data/lib/metasploit/model/search/operator/help.rb +71 -79
- data/lib/metasploit/model/search/with.rb +72 -78
- data/lib/metasploit/model/spec.rb +133 -136
- data/lib/metasploit/model/spec/error.rb +3 -9
- data/lib/metasploit/model/spec/i18n_exception_handler.rb +0 -2
- data/lib/metasploit/model/spec/pathname_collision.rb +19 -27
- data/lib/metasploit/model/spec/template/write.rb +0 -2
- data/lib/metasploit/model/spec/temporary_pathname.rb +47 -56
- data/lib/metasploit/model/translation.rb +0 -2
- data/lib/metasploit/model/version.rb +1 -1
- data/lib/metasploit/model/visitation.rb +7 -10
- data/lib/metasploit/model/visitation/visit.rb +79 -85
- data/metasploit-model.gemspec +1 -1
- data/spec/app/models/metasploit/model/search/operation/integer_spec.rb +1 -1
- data/spec/app/models/metasploit/model/search/operation/set/integer_spec.rb +1 -1
- data/spec/app/models/metasploit/model/search/operation/set/string_spec.rb +1 -1
- data/spec/app/models/metasploit/model/search/operation/string_spec.rb +1 -1
- data/spec/dummy/config/application.rb +1 -0
- data/spec/lib/metasploit/model/search/operation/{integer/value_spec.rb → value/integer_spec.rb} +2 -2
- data/spec/lib/metasploit/model/search/operation/{string/value_spec.rb → value/string_spec.rb} +2 -2
- data/spec/support/shared/examples/metasploit/model/search/operation/{integer/value.rb → value/integer.rb} +2 -2
- data/spec/support/shared/examples/metasploit/model/search/operation/{string/value.rb → value/string.rb} +2 -2
- metadata +16 -13
@@ -1,6 +1,9 @@
|
|
1
|
-
require 'metasploit/model/search'
|
2
|
-
|
3
1
|
# Namespace for search groups, such as {Metasploit::Model::Search::Group::Intersection intersections} or
|
4
2
|
# {Metasploit::Model::Search::Group::Union unions}.
|
5
3
|
module Metasploit::Model::Search::Group
|
4
|
+
extend ActiveSupport::Autoload
|
5
|
+
|
6
|
+
autoload :Base
|
7
|
+
autoload :Intersection
|
8
|
+
autoload :Union
|
6
9
|
end
|
@@ -1,35 +1,38 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
# operation.
|
6
|
-
module Operation
|
7
|
-
extend ActiveSupport::Autoload
|
1
|
+
# Namespace for search operations. {parse} acts as a factory to parse a `String` and return a type-specific
|
2
|
+
# operation.
|
3
|
+
module Metasploit::Model::Search::Operation
|
4
|
+
extend ActiveSupport::Autoload
|
8
5
|
|
9
|
-
|
6
|
+
autoload :Association
|
7
|
+
autoload :Base
|
8
|
+
autoload :Boolean
|
9
|
+
autoload :Date
|
10
|
+
autoload :Group
|
11
|
+
autoload :Integer
|
12
|
+
autoload :Null
|
13
|
+
autoload :Set
|
14
|
+
autoload :String
|
15
|
+
autoload :Value
|
10
16
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
# @param options [Hash{Symbol => Object}]
|
18
|
+
# @option options [Metasploit::Module::Search::Query] :query The query that the parsed operation is a part.
|
19
|
+
# @option options [String] :formatted_operation A '<operator>:<value>' string.
|
20
|
+
# @return [Metasploit::Model::Search::Operation::Base, Array<Metasploit::Model::Search::Operation::Base>]
|
21
|
+
# operation(s) parsed from the formatted operation.
|
22
|
+
# @raise [KeyError] unless :formatted_operation is given.
|
23
|
+
# @raise [KeyError] unless :query is given.
|
24
|
+
def self.parse(options={})
|
25
|
+
formatted_operation = options.fetch(:formatted_operation)
|
26
|
+
query = options.fetch(:query)
|
21
27
|
|
22
|
-
|
23
|
-
|
28
|
+
formatted_operator, formatted_value = formatted_operation.split(':', 2)
|
29
|
+
operator = query.parse_operator(formatted_operator)
|
24
30
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
31
|
+
# formatted_value will be nil if formatted_operation did not contain a ':', it should be treated the same
|
32
|
+
# as nothing after the ':'.
|
33
|
+
formatted_value ||= ''
|
34
|
+
operation_or_operations = operator.operate_on(formatted_value)
|
29
35
|
|
30
|
-
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
36
|
+
operation_or_operations
|
34
37
|
end
|
35
|
-
end
|
38
|
+
end
|
@@ -1,5 +1,8 @@
|
|
1
|
-
require 'metasploit/model/search/operation'
|
2
|
-
|
3
1
|
# Namespace for operations that form groups directly from single operator.
|
4
2
|
module Metasploit::Model::Search::Operation::Group
|
3
|
+
extend ActiveSupport::Autoload
|
4
|
+
|
5
|
+
autoload :Base
|
6
|
+
autoload :Intersection
|
7
|
+
autoload :Union
|
5
8
|
end
|
@@ -1,66 +1,66 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
# {include:Metasploit::Model::Search::Operator::Single}
|
57
|
-
module Operator
|
58
|
-
extend ActiveSupport::Autoload
|
1
|
+
# # Declaring operator classes
|
2
|
+
#
|
3
|
+
# ## Interface
|
4
|
+
#
|
5
|
+
# Operators do not need to subclass any specific superclass, but they are expected to define certain methods.
|
6
|
+
#
|
7
|
+
# class MyOperator
|
8
|
+
# #
|
9
|
+
# # Instance Methods
|
10
|
+
# #
|
11
|
+
#
|
12
|
+
# # @param klass [Class] The klass on which `search_with` was called.
|
13
|
+
# def initialize(attributes={})
|
14
|
+
# # ...
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# # Description of what this operator searches for.
|
18
|
+
# #
|
19
|
+
# # @return [String]
|
20
|
+
# def help
|
21
|
+
# # ...
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# # Name of this operator. The name of the operator is matched to the string before the ':' in a formatted
|
25
|
+
# # operation.
|
26
|
+
# #
|
27
|
+
# # @return [Symbol]
|
28
|
+
# def name
|
29
|
+
# # ...
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# # Creates a one or more operations based on `formatted_value`.
|
33
|
+
# #
|
34
|
+
# # @return [#operator, Array<#operator>] Operation with this operator as the operation's `operator`.
|
35
|
+
# def operate_on(formatted_value)
|
36
|
+
# # ...
|
37
|
+
# end
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
# ## Help
|
41
|
+
#
|
42
|
+
# Instead of having define your own `#help` method for your operator `Class`, you can `include`
|
43
|
+
# {Metasploit::Model::Search::Operator::Help}.
|
44
|
+
#
|
45
|
+
# {include:Metasploit::Model::Search::Operator::Help}
|
46
|
+
#
|
47
|
+
# ## {Metasploit::Model::Search::Operator::Base}
|
48
|
+
#
|
49
|
+
# {include:Metasploit::Model::Search::Operator::Base}
|
50
|
+
#
|
51
|
+
# ## {Metasploit::Model::Search::Operator::Single}
|
52
|
+
#
|
53
|
+
# {include:Metasploit::Model::Search::Operator::Single}
|
54
|
+
module Metasploit::Model::Search::Operator
|
55
|
+
extend ActiveSupport::Autoload
|
59
56
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
57
|
+
autoload :Association
|
58
|
+
autoload :Attribute
|
59
|
+
autoload :Base
|
60
|
+
autoload :Delegation
|
61
|
+
autoload :Deprecated
|
62
|
+
autoload :Group
|
63
|
+
autoload :Help
|
64
|
+
autoload :Null
|
65
|
+
autoload :Single
|
66
|
+
end
|
@@ -1,6 +1,12 @@
|
|
1
|
-
require 'metasploit/model/search/operator'
|
2
|
-
|
3
1
|
# Namespace for search operators that mimic behavior of the msfconsole search operators prior to the search operator
|
4
2
|
# generalization introduced by {Metasploit::Model::Search}.
|
5
3
|
module Metasploit::Model::Search::Operator::Deprecated
|
4
|
+
extend ActiveSupport::Autoload
|
5
|
+
|
6
|
+
autoload :App
|
7
|
+
autoload :Author
|
8
|
+
autoload :Authority
|
9
|
+
autoload :Platform
|
10
|
+
autoload :Ref
|
11
|
+
autoload :Text
|
6
12
|
end
|
@@ -1,85 +1,77 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
# @see https://github.com/rails/rails/blob/6c2810b8ed692004dca43e554982cdfdb8517b80/activemodel/lib/active_model/errors.rb#L408-L435
|
52
|
-
def help
|
53
|
-
defaults = []
|
54
|
-
klass_i18n_scope = klass.i18n_scope
|
1
|
+
# This allows the help to be looked up using `I18n`, and for the
|
2
|
+
# help to be customized based on the following criteria:
|
3
|
+
#
|
4
|
+
# `klass` on which the operator is declared, including any `Module#ancestors` and the operator `name`
|
5
|
+
#
|
6
|
+
# # config/locales/<lang>.yml
|
7
|
+
# <lang>:
|
8
|
+
# <klass.i18n_scope>:
|
9
|
+
# ancestors:
|
10
|
+
# <klass_ancestor.model_name.i18n_key>:
|
11
|
+
# search:
|
12
|
+
# operator:
|
13
|
+
# names:
|
14
|
+
# <name>:
|
15
|
+
# help: "Help for searching <name> on <klass>"
|
16
|
+
#
|
17
|
+
# `class` of the operator, including any `Module#ancestors` and the operator `name`
|
18
|
+
#
|
19
|
+
# # config/locales/<lang>.yml
|
20
|
+
# <lang>:
|
21
|
+
# <operator.class.i18n_scope>:
|
22
|
+
# search:
|
23
|
+
# operator:
|
24
|
+
# ancestors:
|
25
|
+
# <operator_class_ancestor.model_name.i18n_key>:
|
26
|
+
# <name>:
|
27
|
+
# help: "Help for searching <name> using <operator.class>"
|
28
|
+
#
|
29
|
+
# `class` of the operator, including any `Module#ancestors` without the operator `name`
|
30
|
+
#
|
31
|
+
# # config/locales/<lang>.yml
|
32
|
+
# <lang>:
|
33
|
+
# <operator.class.i18n_scope>:
|
34
|
+
# search:
|
35
|
+
# operator:
|
36
|
+
# ancestors:
|
37
|
+
# <operator_class_ancestor.model_name.i18n_key>:
|
38
|
+
# help: "Help for searching using <operator.class>"
|
39
|
+
#
|
40
|
+
module Metasploit::Model::Search::Operator::Help
|
41
|
+
# @note This uses I18n.translate along with {Metasploit::Model::Translation#search_i18n_scope},
|
42
|
+
# the value is not cached to support changing the I18n.locale and getting the correct help message for that
|
43
|
+
# locale.
|
44
|
+
#
|
45
|
+
# The help for this operator.
|
46
|
+
#
|
47
|
+
# @see https://github.com/rails/rails/blob/6c2810b8ed692004dca43e554982cdfdb8517b80/activemodel/lib/active_model/errors.rb#L408-L435
|
48
|
+
def help
|
49
|
+
defaults = []
|
50
|
+
klass_i18n_scope = klass.i18n_scope
|
55
51
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
52
|
+
klass.lookup_ancestors.each do |ancestor|
|
53
|
+
# a specific operator for a given Class#ancestors member
|
54
|
+
defaults << :"#{klass_i18n_scope}.ancestors.#{ancestor.model_name.i18n_key}.search.operator.names.#{name}.help"
|
55
|
+
end
|
60
56
|
|
61
|
-
|
62
|
-
|
57
|
+
operator_class = self.class
|
58
|
+
operator_i18n_scope = operator_class.i18n_scope
|
63
59
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
60
|
+
operator_class.lookup_ancestors.each do |ancestor|
|
61
|
+
# a specific name for a given operator
|
62
|
+
defaults << :"#{operator_i18n_scope}.search.operator.ancestors.#{ancestor.model_name.i18n_key}.names.#{name}.help"
|
63
|
+
# a specific operator class
|
64
|
+
defaults << :"#{operator_i18n_scope}.search.operator.ancestors.#{ancestor.model_name.i18n_key}.help"
|
65
|
+
end
|
70
66
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
67
|
+
# use first default as key because it is most specific default, that is closest to klass.
|
68
|
+
key = defaults.shift
|
69
|
+
options = {
|
70
|
+
default: defaults,
|
71
|
+
model: klass.model_name.human,
|
72
|
+
name: name
|
73
|
+
}
|
78
74
|
|
79
|
-
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
75
|
+
::I18n.translate(key, options)
|
84
76
|
end
|
85
|
-
end
|
77
|
+
end
|
@@ -1,83 +1,77 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
# end
|
48
|
-
module With
|
49
|
-
extend ActiveSupport::Concern
|
1
|
+
# Generalizes {Metasploit::Model::Search::Attribute operators from attributes} to anything directly registered as
|
2
|
+
# an operator on a class.
|
3
|
+
#
|
4
|
+
# {include:Metasploit::Model::Search::Operator}
|
5
|
+
#
|
6
|
+
# # Testing
|
7
|
+
#
|
8
|
+
# {ClassMethods#search_with} calls can be tested with the 'search_with' shared example. First, ensure
|
9
|
+
# the shared examples from `metasploit-model` are required in your `spec_helper.rb`:
|
10
|
+
#
|
11
|
+
# # spec/spec_helper.rb
|
12
|
+
# support_glob = Metasploit::Model::Engine.root.join('spec', 'support', '**', '*.rb')
|
13
|
+
#
|
14
|
+
# Dir.glob(support_glob) do |path|
|
15
|
+
# require path
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# In the spec fo the `Class` that called `search_with`, use the 'search_with' shared example by passing the
|
19
|
+
# arguments passed to {ClassMethods#search_attribute}.
|
20
|
+
#
|
21
|
+
# # app/models/my_class.rb
|
22
|
+
# class MyClass
|
23
|
+
# include Metasploit::Model::Search
|
24
|
+
#
|
25
|
+
# #
|
26
|
+
# # Search
|
27
|
+
# #
|
28
|
+
#
|
29
|
+
# search_with MyOperatorClass,
|
30
|
+
# foo: :bar
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
# # spec/app/models/my_class_spec.rb
|
34
|
+
# require 'spec_helper'
|
35
|
+
#
|
36
|
+
# describe MyClass do
|
37
|
+
# context 'search' do
|
38
|
+
# context 'attributes' do
|
39
|
+
# it_should_behave_like 'search_with',
|
40
|
+
# MyOperatorClass,
|
41
|
+
# foo: :bar
|
42
|
+
# end
|
43
|
+
# end
|
44
|
+
# end
|
45
|
+
module Metasploit::Model::Search::With
|
46
|
+
extend ActiveSupport::Concern
|
50
47
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
48
|
+
# Defines `search_with` DSL, which is a lower-level way than search_attribute to add operators. `search_with`
|
49
|
+
# allows instance of arbitrary operator_classes to be registered in {#search_with_operator_by_name}.
|
50
|
+
module ClassMethods
|
51
|
+
# Declares that this class should be search with an instance of the given `operator_class`.
|
52
|
+
#
|
53
|
+
# @param operator_class [Class<Metasploit::Model::Search::Operator::Base>] a class to initialize.
|
54
|
+
# @param options [Hash] Options passed to `operator_class.new` along with `{:klass => self}`, so that the
|
55
|
+
# `operator_class` instance knows it was registered as search this class.
|
56
|
+
# @return [Metasploit::Model::Search::Operator::Base]
|
57
|
+
# @raise (see Metasploit::Model::Base#invalid!)
|
58
|
+
def search_with(operator_class, options={})
|
59
|
+
merged_operations = options.merge(
|
60
|
+
:klass => self
|
61
|
+
)
|
62
|
+
operator = operator_class.new(merged_operations)
|
63
|
+
operator.valid!
|
67
64
|
|
68
|
-
|
69
|
-
|
65
|
+
search_with_operator_by_name[operator.name] = operator
|
66
|
+
end
|
70
67
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
68
|
+
# Operators registered with {#search_with}.
|
69
|
+
#
|
70
|
+
# @return [Hash{Symbol => Metasploit::Model::Search::Operator::Base}] Maps
|
71
|
+
# {Metasploit::Model::Search::Operator::Base#name} keys to {Metasploit::Model::Search::Operator::Base#name}
|
72
|
+
# values.
|
73
|
+
def search_with_operator_by_name
|
74
|
+
@search_with_operator_by_name ||= {}
|
81
75
|
end
|
82
76
|
end
|
83
|
-
end
|
77
|
+
end
|