metasploit-model 0.27.3-java → 0.27.4-java
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.
- checksums.yaml +4 -4
- 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,147 +1,144 @@
|
|
|
1
1
|
require 'rspec/core/shared_example_group'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
3
|
+
# Helper methods for running specs for metasploit-model.
|
|
4
|
+
module Metasploit::Model::Spec
|
|
5
|
+
extend ActiveSupport::Autoload
|
|
6
|
+
|
|
7
|
+
autoload :Error
|
|
8
|
+
autoload :I18nExceptionHandler
|
|
9
|
+
autoload :PathnameCollision
|
|
10
|
+
autoload :Template
|
|
11
|
+
autoload :TemporaryPathname
|
|
12
|
+
|
|
13
|
+
extend Metasploit::Model::Spec::TemporaryPathname
|
|
14
|
+
# without this, Module.shared_examples_for will be used and RSpec will count shared_examples created with
|
|
15
|
+
# {shared_examples_for} to not be declared at the top-level.
|
|
16
|
+
extend RSpec::Core::SharedExampleGroup::TopLevelDSL
|
|
17
|
+
|
|
18
|
+
# Defines a shared examples for a `Module` under the {Metasploit::Model} namespace. This `Module` is assumed to
|
|
19
|
+
# be a mixin that can be mixed into an ActiveModel in metasploit-framework or an ActiveRecord in
|
|
20
|
+
# metasploit_data_models. Shared examples declared using this method get access to boiler plate methods used
|
|
21
|
+
# for all the {Metasploit::Model} mixin `Modules`:
|
|
22
|
+
#
|
|
23
|
+
# * <relative_variable_name>_class
|
|
24
|
+
# * <relative_variable_name>_factory
|
|
25
|
+
# * factory_namespace
|
|
26
|
+
# * relative_variable_name
|
|
27
|
+
# * #<relative_variable_name>_class
|
|
28
|
+
# * #<relative_variable_name>_factory
|
|
29
|
+
#
|
|
30
|
+
# @example boiler plate methods for Module::Ancestor
|
|
31
|
+
# # defined shared example's name will be 'Metasploit::Model::Module::Ancestor', but you only need to give the
|
|
32
|
+
# # name relative to 'Metasploit::Model'.
|
|
33
|
+
# Metasploit::Model::Spec.shared_examples_for 'Module::Ancestor' do
|
|
34
|
+
# module_ancestor_class # '<namespace_name>::Module::Ancestor'
|
|
35
|
+
# module_ancestor_factory # '<factory_namespace>_module_ancestor'
|
|
36
|
+
# factory_namespace # namespace_name converted to underscore with / replaced by _
|
|
37
|
+
# relative_variable_name # 'module_ancestor'
|
|
38
|
+
#
|
|
39
|
+
# let(:base_class) do # automatically defined for you
|
|
40
|
+
# module_ancestor_class # same as class method module_ancestor_class
|
|
41
|
+
# end
|
|
42
|
+
#
|
|
43
|
+
# context 'factories' do # have to define this yourself since not all mixins use factories.
|
|
44
|
+
# context module_ancestor_factory do # using class method
|
|
45
|
+
# subject(module_ancestor_factory) do # using class method
|
|
46
|
+
# FactoryGirl.build(module_ancestor_factory) # using instance method
|
|
47
|
+
# end
|
|
48
|
+
# end
|
|
49
|
+
# end
|
|
50
|
+
# end
|
|
51
|
+
#
|
|
52
|
+
# @example Using shared example
|
|
53
|
+
# describe Metasploit::Model::Module::Ancestor do
|
|
54
|
+
# it_should_behave_like 'Metasploit::Model::Module::Ancestor',
|
|
55
|
+
# namespace_name: 'Dummy'
|
|
56
|
+
# end
|
|
57
|
+
#
|
|
58
|
+
# @param relative_name [String] name relative to 'Metasploit::Model' prefix. For example, to declare
|
|
59
|
+
# 'Metasploit::Model::Module::Ancestor' shared example, `relative_name` would be just 'Module::Ancestor'.
|
|
60
|
+
# @yield Body of shared examples.
|
|
61
|
+
# @yieldreturn [void]
|
|
62
|
+
# @return [void]
|
|
63
|
+
def self.shared_examples_for(relative_name, &block)
|
|
64
|
+
fully_qualified_name = "Metasploit::Model::#{relative_name}"
|
|
65
|
+
|
|
66
|
+
relative_variable_name = relative_name.underscore.gsub('/', '_')
|
|
67
|
+
class_method_name = "#{relative_variable_name}_class"
|
|
68
|
+
factory_method_name = "#{relative_variable_name}_factory"
|
|
69
|
+
|
|
70
|
+
# capture block to pass to super so that source_location can be overridden to be block's source_location so that
|
|
71
|
+
# errors are reported correctly from RSpec.
|
|
72
|
+
wrapper = ->(options={}) {
|
|
73
|
+
options.assert_valid_keys(:namespace_name)
|
|
74
|
+
namespace_name = options.fetch(:namespace_name)
|
|
75
|
+
|
|
76
|
+
class_name = "#{namespace_name}::#{relative_name}"
|
|
77
|
+
|
|
23
78
|
#
|
|
24
|
-
#
|
|
25
|
-
# * <relative_variable_name>_factory
|
|
26
|
-
# * factory_namespace
|
|
27
|
-
# * relative_variable_name
|
|
28
|
-
# * #<relative_variable_name>_class
|
|
29
|
-
# * #<relative_variable_name>_factory
|
|
79
|
+
# Singleton methods to emulate local variable used to define examples and lets
|
|
30
80
|
#
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
81
|
+
|
|
82
|
+
define_singleton_method(class_method_name) do
|
|
83
|
+
class_name.constantize
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
define_singleton_method(factory_method_name) do
|
|
87
|
+
"#{factory_namespace}_#{relative_variable_name}"
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
define_singleton_method(:factory_namespace) do
|
|
91
|
+
namespace_name.underscore.gsub('/', '_')
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
define_singleton_method(:namespace_name) do
|
|
95
|
+
namespace_name
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
define_singleton_method(:relative_variable_name) do
|
|
99
|
+
relative_variable_name
|
|
100
|
+
end
|
|
101
|
+
|
|
39
102
|
#
|
|
40
|
-
#
|
|
41
|
-
# module_ancestor_class # same as class method module_ancestor_class
|
|
42
|
-
# end
|
|
103
|
+
# Defines to emulate local variable used inside lets
|
|
43
104
|
#
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
105
|
+
|
|
106
|
+
define_method(class_method_name) do
|
|
107
|
+
self.class.send(class_method_name)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
define_method(factory_method_name) do
|
|
111
|
+
self.class.send(factory_method_name)
|
|
112
|
+
end
|
|
113
|
+
|
|
52
114
|
#
|
|
53
|
-
#
|
|
54
|
-
# describe Metasploit::Model::Module::Ancestor do
|
|
55
|
-
# it_should_behave_like 'Metasploit::Model::Module::Ancestor',
|
|
56
|
-
# namespace_name: 'Dummy'
|
|
57
|
-
# end
|
|
115
|
+
# Default subject uses factory
|
|
58
116
|
#
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
# @yieldreturn [void]
|
|
63
|
-
# @return [void]
|
|
64
|
-
def self.shared_examples_for(relative_name, &block)
|
|
65
|
-
fully_qualified_name = "Metasploit::Model::#{relative_name}"
|
|
66
|
-
|
|
67
|
-
relative_variable_name = relative_name.underscore.gsub('/', '_')
|
|
68
|
-
class_method_name = "#{relative_variable_name}_class"
|
|
69
|
-
factory_method_name = "#{relative_variable_name}_factory"
|
|
70
|
-
|
|
71
|
-
# capture block to pass to super so that source_location can be overridden to be block's source_location so that
|
|
72
|
-
# errors are reported correctly from RSpec.
|
|
73
|
-
wrapper = ->(options={}) {
|
|
74
|
-
options.assert_valid_keys(:namespace_name)
|
|
75
|
-
namespace_name = options.fetch(:namespace_name)
|
|
76
|
-
|
|
77
|
-
class_name = "#{namespace_name}::#{relative_name}"
|
|
78
|
-
|
|
79
|
-
#
|
|
80
|
-
# Singleton methods to emulate local variable used to define examples and lets
|
|
81
|
-
#
|
|
82
|
-
|
|
83
|
-
define_singleton_method(class_method_name) do
|
|
84
|
-
class_name.constantize
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
define_singleton_method(factory_method_name) do
|
|
88
|
-
"#{factory_namespace}_#{relative_variable_name}"
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
define_singleton_method(:factory_namespace) do
|
|
92
|
-
namespace_name.underscore.gsub('/', '_')
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
define_singleton_method(:namespace_name) do
|
|
96
|
-
namespace_name
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
define_singleton_method(:relative_variable_name) do
|
|
100
|
-
relative_variable_name
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
#
|
|
104
|
-
# Defines to emulate local variable used inside lets
|
|
105
|
-
#
|
|
106
|
-
|
|
107
|
-
define_method(class_method_name) do
|
|
108
|
-
self.class.send(class_method_name)
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
define_method(factory_method_name) do
|
|
112
|
-
self.class.send(factory_method_name)
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
#
|
|
116
|
-
# Default subject uses factory
|
|
117
|
-
#
|
|
118
|
-
|
|
119
|
-
subject(relative_variable_name) do
|
|
120
|
-
FactoryGirl.build(send(factory_method_name))
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
#
|
|
124
|
-
# lets
|
|
125
|
-
#
|
|
126
|
-
|
|
127
|
-
let(:base_class) do
|
|
128
|
-
self.class.send(class_method_name)
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
it_should_behave_like 'Metasploit::Model::Translation',
|
|
132
|
-
metasploit_model_ancestor: fully_qualified_name.constantize
|
|
133
|
-
|
|
134
|
-
module_eval(&block)
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
# Delegate source_location so that RSpec will report block's source_location as the declaration location of
|
|
138
|
-
# the shared location instead of this method.
|
|
139
|
-
wrapper.define_singleton_method(:source_location) do
|
|
140
|
-
block.source_location
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
super(fully_qualified_name, &wrapper)
|
|
117
|
+
|
|
118
|
+
subject(relative_variable_name) do
|
|
119
|
+
FactoryGirl.build(send(factory_method_name))
|
|
144
120
|
end
|
|
121
|
+
|
|
122
|
+
#
|
|
123
|
+
# lets
|
|
124
|
+
#
|
|
125
|
+
|
|
126
|
+
let(:base_class) do
|
|
127
|
+
self.class.send(class_method_name)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
it_should_behave_like 'Metasploit::Model::Translation',
|
|
131
|
+
metasploit_model_ancestor: fully_qualified_name.constantize
|
|
132
|
+
|
|
133
|
+
module_eval(&block)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
# Delegate source_location so that RSpec will report block's source_location as the declaration location of
|
|
137
|
+
# the shared location instead of this method.
|
|
138
|
+
wrapper.define_singleton_method(:source_location) do
|
|
139
|
+
block.source_location
|
|
145
140
|
end
|
|
141
|
+
|
|
142
|
+
super(fully_qualified_name, &wrapper)
|
|
146
143
|
end
|
|
147
|
-
end
|
|
144
|
+
end
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
# Error raised by Metasploit::Model::Spec methods.
|
|
5
|
-
class Error < StandardError
|
|
6
|
-
end
|
|
7
|
-
end
|
|
8
|
-
end
|
|
9
|
-
end
|
|
1
|
+
# Error raised by Metasploit::Model::Spec methods.
|
|
2
|
+
class Metasploit::Model::Spec::Error < StandardError
|
|
3
|
+
end
|
|
@@ -1,30 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def self.check!(pathname)
|
|
15
|
-
if pathname.exist?
|
|
16
|
-
raise new(pathname)
|
|
17
|
-
end
|
|
18
|
-
end
|
|
1
|
+
# Error raised if a Pathname already exists on disk when one of the real_paths for metasploit-models factories
|
|
2
|
+
# is generated or derived, which would indicate that a prior spec did not clean up properly.
|
|
3
|
+
class Metasploit::Model::Spec::PathnameCollision < Metasploit::Model::Spec::Error
|
|
4
|
+
# Checks if there is a pathname collision.
|
|
5
|
+
#
|
|
6
|
+
# @param (see #initialize)
|
|
7
|
+
# @return [void]
|
|
8
|
+
# @raise [Metasploit::Model::Spec::PathnameCollision] if `pathname.exist?` is `true`.
|
|
9
|
+
def self.check!(pathname)
|
|
10
|
+
if pathname.exist?
|
|
11
|
+
raise new(pathname)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
19
14
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
# @param pathname [Pathname] Pathname that already exists on disk
|
|
16
|
+
def initialize(pathname)
|
|
17
|
+
super(
|
|
18
|
+
"#{pathname} already exists. " \
|
|
24
19
|
"Metasploit::Model::Spec.remove_temporary_pathname was not called after the previous spec."
|
|
25
|
-
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
20
|
+
)
|
|
29
21
|
end
|
|
30
|
-
end
|
|
22
|
+
end
|
|
@@ -1,62 +1,53 @@
|
|
|
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
|
-
def remove_temporary_pathname
|
|
26
|
-
begin
|
|
27
|
-
removal_pathname = temporary_pathname
|
|
28
|
-
rescue Metasploit::Model::Spec::Error
|
|
29
|
-
removal_pathname = nil
|
|
30
|
-
end
|
|
1
|
+
# @example Temporary pathname creation and removal
|
|
2
|
+
#
|
|
3
|
+
# # spec/spec_helper.rb
|
|
4
|
+
# RSpec.config do |config|
|
|
5
|
+
# config.before(:suite) do
|
|
6
|
+
# Metasploit::Model::Spec.temporary_pathname = MyApp.root.join('spec', 'tmp')
|
|
7
|
+
# # Clean up any left over files from a previously aborted suite
|
|
8
|
+
# Metasploit::Model::Spec.remove_temporary_pathname
|
|
9
|
+
# end
|
|
10
|
+
#
|
|
11
|
+
# config.after(:each) do
|
|
12
|
+
# Metasploit::Model::Spec.remove_temporary_pathname
|
|
13
|
+
# end
|
|
14
|
+
# end
|
|
15
|
+
module Metasploit::Model::Spec::TemporaryPathname
|
|
16
|
+
# Removes {#temporary_pathname} from disk if it's been set and exists on disk.
|
|
17
|
+
#
|
|
18
|
+
# @return [void]
|
|
19
|
+
def remove_temporary_pathname
|
|
20
|
+
begin
|
|
21
|
+
removal_pathname = temporary_pathname
|
|
22
|
+
rescue Metasploit::Model::Spec::Error
|
|
23
|
+
removal_pathname = nil
|
|
24
|
+
end
|
|
31
25
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
26
|
+
if removal_pathname and removal_pathname.exist?
|
|
27
|
+
removal_pathname.rmtree
|
|
28
|
+
end
|
|
29
|
+
end
|
|
36
30
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
31
|
+
# Pathname to hold temporary files for metasploit-model factories and sequence. The directory must be be
|
|
32
|
+
# safely writable and removable for specs that need to use the file system.
|
|
33
|
+
#
|
|
34
|
+
# @return [Pathname]
|
|
35
|
+
# @raise [Metasploit::Model::Spec::Error] if {#temporary_pathname} is not set prior to calling this method.
|
|
36
|
+
def temporary_pathname
|
|
37
|
+
unless instance_variable_defined?(:@temporary_pathname)
|
|
38
|
+
raise Metasploit::Model::Spec::Error, 'Metasploit::Model::Spec.temporary_pathname not set prior to use'
|
|
39
|
+
end
|
|
46
40
|
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
@temporary_pathname
|
|
42
|
+
end
|
|
49
43
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|
|
44
|
+
# Sets the pathname to use for temporary directories and files used in metasploit_data_models factories and
|
|
45
|
+
# sequences.
|
|
46
|
+
#
|
|
47
|
+
# @param pathname [Pathname] path to a directory. It does not need to exist, but need to be in a writable parent
|
|
48
|
+
# directory so it can be removed by {#remove_temporary_pathname}.
|
|
49
|
+
# @return [Pathname] `pathname`
|
|
50
|
+
def temporary_pathname=(pathname)
|
|
51
|
+
@temporary_pathname = pathname
|
|
61
52
|
end
|
|
62
53
|
end
|