ronin 1.0.0 → 1.1.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +0 -1
- data/ChangeLog.md +67 -3
- data/Gemfile +20 -12
- data/README.md +3 -5
- data/gemspec.yml +5 -5
- data/lib/ronin/address.rb +8 -3
- data/lib/ronin/arch.rb +39 -14
- data/lib/ronin/author.rb +2 -0
- data/lib/ronin/auto_load.rb +67 -0
- data/lib/ronin/campaign.rb +15 -2
- data/lib/ronin/class_methods.rb +7 -1
- data/lib/ronin/config.rb +5 -0
- data/lib/ronin/credential.rb +14 -3
- data/lib/ronin/database/database.rb +38 -12
- data/lib/ronin/database/migrations.rb +3 -1
- data/lib/ronin/database/migrations/add_created_at_column_to_targets_table.rb +48 -0
- data/lib/ronin/database/migrations/add_updated_at_column_to_campaigns_table.rb +47 -0
- data/lib/ronin/database/migrations/create_licenses_table.rb +1 -1
- data/lib/ronin/database/migrations/create_passwords_table.rb +1 -1
- data/lib/ronin/database/migrations/{create_cached_files_table.rb → create_script_paths_table.rb} +4 -4
- data/lib/ronin/database/migrations/migration.rb +3 -6
- data/lib/ronin/database/migrations/migrations.rb +3 -3
- data/lib/ronin/email_address.rb +20 -3
- data/lib/ronin/environment.rb +0 -3
- data/lib/ronin/host_name.rb +20 -6
- data/lib/ronin/host_name_ip_address.rb +2 -3
- data/lib/ronin/installation.rb +92 -23
- data/lib/ronin/ip_address.rb +31 -8
- data/lib/ronin/ip_address_mac_address.rb +2 -3
- data/lib/ronin/license.rb +1 -1
- data/lib/ronin/mac_address.rb +6 -4
- data/lib/ronin/model/class_methods.rb +4 -0
- data/lib/ronin/model/has_authors/class_methods.rb +4 -0
- data/lib/ronin/model/has_authors/has_authors.rb +4 -0
- data/lib/ronin/model/has_description/class_methods.rb +2 -0
- data/lib/ronin/model/has_description/has_description.rb +2 -0
- data/lib/ronin/model/has_license/class_methods.rb +2 -0
- data/lib/ronin/model/has_license/has_license.rb +4 -0
- data/lib/ronin/model/has_name/class_methods.rb +2 -0
- data/lib/ronin/model/has_name/has_name.rb +4 -0
- data/lib/ronin/model/has_title/class_methods.rb +2 -0
- data/lib/ronin/model/has_title/has_title.rb +2 -0
- data/lib/ronin/model/has_unique_name/class_methods.rb +2 -0
- data/lib/ronin/model/has_unique_name/has_unique_name.rb +7 -1
- data/lib/ronin/model/has_version/class_methods.rb +4 -0
- data/lib/ronin/model/has_version/has_version.rb +2 -0
- data/lib/ronin/model/model.rb +2 -0
- data/lib/ronin/model/types.rb +1 -7
- data/lib/ronin/model/types/description.rb +2 -0
- data/lib/ronin/network/mixins/esmtp.rb +40 -25
- data/lib/ronin/network/mixins/http.rb +336 -73
- data/lib/ronin/network/mixins/imap.rb +38 -25
- data/lib/ronin/network/mixins/pop3.rb +34 -21
- data/lib/ronin/network/mixins/smtp.rb +40 -25
- data/lib/ronin/network/mixins/tcp.rb +66 -41
- data/lib/ronin/network/mixins/telnet.rb +43 -30
- data/lib/ronin/network/mixins/udp.rb +59 -40
- data/lib/ronin/open_port.rb +12 -5
- data/lib/ronin/organization.rb +1 -2
- data/lib/ronin/os.rb +10 -3
- data/lib/ronin/os_guess.rb +2 -3
- data/lib/ronin/password.rb +11 -3
- data/lib/ronin/port.rb +7 -2
- data/lib/ronin/{engine/exceptions/deploy_failed.rb → repositories.rb} +4 -6
- data/lib/ronin/repository.rb +110 -37
- data/lib/ronin/ronin.rb +4 -3
- data/lib/ronin/{engine.rb → script.rb} +2 -1
- data/lib/ronin/{engine → script}/buildable.rb +43 -29
- data/lib/ronin/script/class_methods.rb +84 -0
- data/lib/ronin/{engine → script}/deployable.rb +61 -40
- data/lib/ronin/{engine → script}/exceptions.rb +4 -3
- data/lib/ronin/script/exceptions/deploy_failed.rb +27 -0
- data/lib/ronin/{engine/exceptions/not_built.rb → script/exceptions/exception.rb} +2 -2
- data/lib/ronin/{engine/exceptions/verification_failed.rb → script/exceptions/not_built.rb} +4 -2
- data/lib/ronin/script/exceptions/test_failed.rb +27 -0
- data/lib/ronin/script/instance_methods.rb +217 -0
- data/lib/ronin/script/path.rb +277 -0
- data/lib/ronin/{engine/engine.rb → script/script.rb} +52 -15
- data/lib/ronin/{engine/verifiable.rb → script/testable.rb} +97 -68
- data/lib/ronin/service.rb +1 -2
- data/lib/ronin/service_credential.rb +1 -2
- data/lib/ronin/software.rb +3 -2
- data/lib/ronin/spec/database.rb +0 -4
- data/lib/ronin/target.rb +11 -3
- data/lib/ronin/tcp_port.rb +3 -2
- data/lib/ronin/udp_port.rb +2 -0
- data/lib/ronin/ui/cli/cli.rb +6 -0
- data/lib/ronin/ui/cli/command.rb +48 -12
- data/lib/ronin/ui/cli/commands/campaigns.rb +3 -3
- data/lib/ronin/ui/cli/commands/console.rb +2 -1
- data/lib/ronin/ui/cli/commands/creds.rb +3 -3
- data/lib/ronin/ui/cli/commands/database.rb +1 -17
- data/lib/ronin/ui/cli/commands/emails.rb +3 -3
- data/lib/ronin/ui/cli/commands/hosts.rb +3 -7
- data/lib/ronin/ui/cli/commands/ips.rb +3 -7
- data/lib/ronin/ui/cli/commands/repos.rb +5 -17
- data/lib/ronin/ui/cli/commands/urls.rb +3 -3
- data/lib/ronin/ui/cli/model_command.rb +82 -97
- data/lib/ronin/ui/cli/resources_command.rb +89 -0
- data/lib/ronin/ui/cli/script_command.rb +115 -0
- data/lib/ronin/ui/console.rb +17 -3
- data/lib/ronin/ui/output/helpers.rb +18 -0
- data/lib/ronin/ui/output/output.rb +20 -1
- data/lib/ronin/ui/output/terminal/color.rb +10 -0
- data/lib/ronin/ui/output/terminal/raw.rb +10 -0
- data/lib/ronin/ui/shell.rb +2 -0
- data/lib/ronin/url.rb +47 -12
- data/lib/ronin/url_query_param.rb +4 -0
- data/lib/ronin/url_scheme.rb +3 -3
- data/lib/ronin/user_name.rb +2 -0
- data/lib/ronin/version.rb +1 -1
- data/lib/ronin/web_credential.rb +6 -3
- data/spec/arch_spec.rb +3 -3
- data/spec/classes/my_script.rb +21 -0
- data/spec/helpers/repos/{test1 → installed}/ronin.yml +1 -1
- data/spec/helpers/repos/{hello/cache → installed/scripts}/.keep +0 -0
- data/spec/helpers/repos/local/lib/init.rb +1 -0
- data/spec/helpers/repos/{hello → local}/lib/stuff/another_test.rb +0 -0
- data/spec/helpers/repos/{hello → local}/lib/stuff/test.rb +0 -0
- data/spec/helpers/repos/{random → local}/ronin.yml +1 -1
- data/spec/helpers/repos/{random/cache → local/scripts}/.keep +0 -0
- data/spec/helpers/repos/{hello → remote}/ronin.yml +1 -1
- data/spec/helpers/repos/remote/scripts/.keep +0 -0
- data/spec/helpers/repos/{test2 → scripts}/ronin.yml +0 -0
- data/spec/helpers/repos/scripts/scripts/cached/cached.rb +10 -0
- data/spec/helpers/repos/scripts/scripts/cached/missing.rb +10 -0
- data/spec/helpers/repos/scripts/scripts/cached/modified.rb +10 -0
- data/spec/helpers/repos/scripts/scripts/cached/unmodified.rb +10 -0
- data/spec/helpers/repos/scripts/scripts/failures/exceptions.rb +11 -0
- data/spec/helpers/repos/{test2/cache/cacheable_model → scripts/scripts/failures}/load_errors.rb +3 -1
- data/spec/helpers/repos/{test2/cache/cacheable_model → scripts/scripts/failures}/name_errors.rb +1 -0
- data/spec/helpers/repos/scripts/scripts/failures/no_method_errors.rb +10 -0
- data/spec/helpers/repos/scripts/scripts/failures/syntax_errors.rb +11 -0
- data/spec/helpers/repos/scripts/scripts/failures/validation_errors.rb +11 -0
- data/spec/helpers/repos/scripts/scripts/my_scripts/test.rb +16 -0
- data/spec/model/spec_helper.rb +0 -2
- data/spec/repository_spec.rb +61 -81
- data/spec/ronin_spec.rb +2 -2
- data/spec/{engine → script}/buildable_spec.rb +9 -9
- data/spec/script/classes/buildable_class.rb +15 -0
- data/spec/script/classes/deployable_class.rb +13 -0
- data/spec/{engine/classes/engine_class.rb → script/classes/script_class.rb} +3 -3
- data/spec/{engine/classes/verifiable_class.rb → script/classes/testable_class.rb} +5 -5
- data/spec/{engine → script}/deployable_spec.rb +10 -10
- data/spec/{cached_file_spec.rb → script/path_spec.rb} +33 -72
- data/spec/script/script_spec.rb +130 -0
- data/spec/script/testable_spec.rb +117 -0
- data/spec/spec_helper.rb +15 -13
- metadata +114 -139
- data/lib/ronin/cached_file.rb +0 -247
- data/lib/ronin/engine/class_methods.rb +0 -135
- data/lib/ronin/engine/instance_methods.rb +0 -97
- data/lib/ronin/model/cacheable.rb +0 -21
- data/lib/ronin/model/cacheable/cacheable.rb +0 -273
- data/lib/ronin/model/cacheable/class_methods.rb +0 -60
- data/lib/ronin/ui/cli/engine_command.rb +0 -106
- data/spec/engine/classes/buildable_class.rb +0 -15
- data/spec/engine/classes/deployable_class.rb +0 -13
- data/spec/engine/engine_spec.rb +0 -55
- data/spec/engine/verifiable_spec.rb +0 -117
- data/spec/helpers/repos/hello/lib/init.rb +0 -1
- data/spec/helpers/repos/test1/cache/cacheable_model/one.rb +0 -15
- data/spec/helpers/repos/test2/cache/cacheable_model/exceptions.rb +0 -7
- data/spec/helpers/repos/test2/cache/cacheable_model/no_method_errors.rb +0 -9
- data/spec/helpers/repos/test2/cache/cacheable_model/syntax_errors.rb +0 -7
- data/spec/helpers/repos/test2/cache/cacheable_model/two.rb +0 -15
- data/spec/helpers/repos/test2/cache/cacheable_model/validation_errors.rb +0 -9
- data/spec/model/cacheable_spec.rb +0 -96
- data/spec/model/models/cacheable_model.rb +0 -13
@@ -1,10 +1,10 @@
|
|
1
|
-
require 'ronin/
|
2
|
-
require 'ronin/
|
1
|
+
require 'ronin/script'
|
2
|
+
require 'ronin/script/testable'
|
3
3
|
|
4
|
-
class
|
4
|
+
class TestableClass
|
5
5
|
|
6
|
-
include Ronin::
|
7
|
-
include Ronin::
|
6
|
+
include Ronin::Script
|
7
|
+
include Ronin::Script::Testable
|
8
8
|
|
9
9
|
property :id, Serial
|
10
10
|
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require '
|
2
|
+
require 'script/classes/deployable_class'
|
3
3
|
|
4
|
-
describe
|
4
|
+
describe Script::Deployable do
|
5
5
|
subject do
|
6
6
|
obj = DeployableClass.new
|
7
7
|
obj.instance_eval do
|
8
|
-
|
8
|
+
test do
|
9
9
|
unless @var > 0
|
10
|
-
raise "
|
10
|
+
raise "script failed verification"
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
@@ -15,8 +15,8 @@ describe Engine::Deployable do
|
|
15
15
|
obj
|
16
16
|
end
|
17
17
|
|
18
|
-
it "should include
|
19
|
-
subject.class.included_modules.should include(
|
18
|
+
it "should include Testable" do
|
19
|
+
subject.class.included_modules.should include(Script::Testable)
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should not be deployed by default" do
|
@@ -24,7 +24,7 @@ describe Engine::Deployable do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
describe "#deploy!" do
|
27
|
-
it "should
|
27
|
+
it "should test! the script before deploying it" do
|
28
28
|
subject.var = -1
|
29
29
|
|
30
30
|
lambda {
|
@@ -32,13 +32,13 @@ describe Engine::Deployable do
|
|
32
32
|
}.should raise_error
|
33
33
|
end
|
34
34
|
|
35
|
-
it "should mark the
|
35
|
+
it "should mark the script deployed" do
|
36
36
|
subject.deploy!
|
37
37
|
|
38
38
|
subject.should be_deployed
|
39
39
|
end
|
40
40
|
|
41
|
-
it "should not mark the
|
41
|
+
it "should not mark the script as evacuated" do
|
42
42
|
subject.deploy!
|
43
43
|
|
44
44
|
subject.should_not be_evacuated
|
@@ -46,7 +46,7 @@ describe Engine::Deployable do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
describe "#evacuate!" do
|
49
|
-
it "should mark the
|
49
|
+
it "should mark the script as evacuated" do
|
50
50
|
subject.evacuate!
|
51
51
|
|
52
52
|
subject.should be_evacuated
|
@@ -1,24 +1,19 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'helpers/repositories'
|
3
|
-
require '
|
3
|
+
require 'classes/my_script'
|
4
4
|
|
5
|
-
require 'ronin/
|
5
|
+
require 'ronin/script/path'
|
6
6
|
|
7
|
-
describe
|
7
|
+
describe Script::Path do
|
8
8
|
include Helpers::Repositories
|
9
9
|
|
10
|
-
let(:
|
11
|
-
let(:
|
10
|
+
let(:repo) { repository('scripts') }
|
11
|
+
let(:script_class) { MyScript }
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
before(:all) do
|
16
|
-
test1.cache_files!
|
17
|
-
test2.cache_files!
|
18
|
-
end
|
13
|
+
before(:all) { repo.cache_scripts! }
|
19
14
|
|
20
15
|
describe "cached file" do
|
21
|
-
subject {
|
16
|
+
subject { repo.find_script('cached/cached.rb') }
|
22
17
|
|
23
18
|
it "should be saved" do
|
24
19
|
subject.should be_saved
|
@@ -45,82 +40,53 @@ describe CachedFile do
|
|
45
40
|
end
|
46
41
|
|
47
42
|
it "should have the model name of the cached object" do
|
48
|
-
subject.
|
43
|
+
subject.class_name.should == script_class.name
|
49
44
|
end
|
50
45
|
|
51
46
|
it "should have the model path of the cached object" do
|
52
|
-
subject.
|
47
|
+
subject.class_path.should == 'my_script'
|
53
48
|
end
|
54
49
|
|
55
50
|
it "should be able to load the Model of the cached object" do
|
56
|
-
subject.
|
51
|
+
subject.script_class.should == script_class
|
57
52
|
end
|
58
53
|
|
59
54
|
it "should be able to load a fresh model from the cached file" do
|
60
|
-
obj = subject.
|
55
|
+
obj = subject.load_script
|
61
56
|
|
62
57
|
obj.should_not be_nil
|
63
|
-
obj.class.should ==
|
58
|
+
obj.class.should == script_class
|
64
59
|
end
|
65
60
|
|
66
61
|
it "should cache the loaded object along with the cached file" do
|
67
|
-
obj =
|
62
|
+
obj = script_class.first(:script_path => subject)
|
68
63
|
|
69
64
|
obj.should_not be_nil
|
70
65
|
end
|
71
66
|
|
72
67
|
it "should be able to load the cached object" do
|
73
|
-
subject.
|
74
|
-
subject.
|
68
|
+
subject.cached_script.should_not be_nil
|
69
|
+
subject.cached_script.class.should == script_class
|
75
70
|
end
|
76
71
|
|
77
72
|
it "should call the cache method before saving the new object" do
|
78
|
-
subject.
|
73
|
+
subject.cached_script.name.should == 'cached'
|
79
74
|
end
|
80
75
|
|
81
76
|
it "should delete the cached object along with the cached file" do
|
82
77
|
subject.destroy
|
83
78
|
|
84
|
-
|
79
|
+
script_class.first(:script_path => subject).should be_nil
|
85
80
|
end
|
86
81
|
end
|
87
82
|
|
88
83
|
describe "failed cached files" do
|
89
|
-
let(:syntax_error)
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
let(:load_error) do
|
96
|
-
test2.cached_files.find do |cached_file|
|
97
|
-
cached_file.path.basename == Pathname.new('load_errors.rb')
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
let(:name_error) do
|
102
|
-
test2.cached_files.find do |cached_file|
|
103
|
-
cached_file.path.basename == Pathname.new('name_errors.rb')
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
let(:no_method_error) do
|
108
|
-
test2.cached_files.find do |cached_file|
|
109
|
-
cached_file.path.basename == Pathname.new('no_method_errors.rb')
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
let(:exception) do
|
114
|
-
test2.cached_files.find do |cached_file|
|
115
|
-
cached_file.path.basename == Pathname.new('exceptions.rb')
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
let(:validation_error) do
|
120
|
-
test2.cached_files.find do |cached_file|
|
121
|
-
cached_file.path.basename == Pathname.new('validation_errors.rb')
|
122
|
-
end
|
123
|
-
end
|
84
|
+
let(:syntax_error) { repo.find_script('failures/syntax_errors.rb') }
|
85
|
+
let(:load_error) { repo.find_script('failures/load_errors.rb') }
|
86
|
+
let(:name_error) { repo.find_script('failures/name_errors.rb') }
|
87
|
+
let(:no_method_error) { repo.find_script('failures/no_method_errors.rb') }
|
88
|
+
let(:exception) { repo.find_script('failures/exceptions.rb') }
|
89
|
+
let(:validation_error) { repo.find_script('failures/validation_errors.rb') }
|
124
90
|
|
125
91
|
it "should not save new cached files that raised exceptions" do
|
126
92
|
syntax_error.should_not be_saved
|
@@ -162,7 +128,7 @@ describe CachedFile do
|
|
162
128
|
end
|
163
129
|
|
164
130
|
describe "unmodified cached file" do
|
165
|
-
subject {
|
131
|
+
subject { repo.find_script('cached/unmodified.rb') }
|
166
132
|
|
167
133
|
it "should not have updated code" do
|
168
134
|
should_not be_updated
|
@@ -178,13 +144,10 @@ describe CachedFile do
|
|
178
144
|
end
|
179
145
|
|
180
146
|
describe "modified cached file" do
|
181
|
-
subject
|
182
|
-
test1.reload
|
183
|
-
|
184
|
-
cached_file = test1.cached_files.first
|
185
|
-
cached_file.update(:timestamp => (cached_file.timestamp - 10))
|
147
|
+
subject { repo.find_script('cached/modified.rb') }
|
186
148
|
|
187
|
-
|
149
|
+
before(:all) do
|
150
|
+
subject.update(:timestamp => (subject.timestamp - 10))
|
188
151
|
end
|
189
152
|
|
190
153
|
it "should not have updated code" do
|
@@ -201,22 +164,20 @@ describe CachedFile do
|
|
201
164
|
end
|
202
165
|
|
203
166
|
describe "missing cached file" do
|
204
|
-
subject
|
205
|
-
test1.reload
|
167
|
+
subject { repo.find_script('cached/missing.rb') }
|
206
168
|
|
207
|
-
|
208
|
-
|
209
|
-
cached_file.sync
|
169
|
+
before(:all) do
|
170
|
+
subject.update(:path => File.join('','missing','file.rb'))
|
210
171
|
|
211
|
-
|
172
|
+
subject.sync
|
212
173
|
end
|
213
174
|
|
214
175
|
it "should delete the cached files" do
|
215
|
-
|
176
|
+
described_class.count(:id => subject.id).should == 0
|
216
177
|
end
|
217
178
|
|
218
179
|
it "should delete cached objects for missing files" do
|
219
|
-
|
180
|
+
script_class.count(:script_path => subject).should == 0
|
220
181
|
end
|
221
182
|
end
|
222
183
|
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'classes/my_script'
|
3
|
+
require 'helpers/repositories'
|
4
|
+
|
5
|
+
require 'ronin/script'
|
6
|
+
|
7
|
+
describe Script do
|
8
|
+
include Helpers::Repositories
|
9
|
+
|
10
|
+
subject { MyScript }
|
11
|
+
|
12
|
+
let(:repo) { repository('scripts') }
|
13
|
+
|
14
|
+
before(:all) { repo.cache_scripts! }
|
15
|
+
|
16
|
+
it "should be a Model" do
|
17
|
+
subject.included_modules.should include(Model)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should have a name" do
|
21
|
+
subject.included_modules.should include(Model::HasName)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should have a description" do
|
25
|
+
subject.included_modules.should include(Model::HasDescription)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should have a version" do
|
29
|
+
subject.included_modules.should include(Model::HasVersion)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should include ObjectLoader" do
|
33
|
+
subject.included_modules.should include(ObjectLoader)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should include DataPaths::Finders" do
|
37
|
+
subject.included_modules.should include(DataPaths::Finders)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should include Parameters" do
|
41
|
+
subject.included_modules.should include(Parameters)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should include UI::Output::Helpers" do
|
45
|
+
subject.included_modules.should include(UI::Output::Helpers)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should add the type property to the model" do
|
49
|
+
subject.properties.should be_named(:type)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should add a relation between Script::Path and the script" do
|
53
|
+
subject.relationships.should be_named(:script_path)
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "#initialize" do
|
57
|
+
it "should initialize attributes" do
|
58
|
+
resource = subject.new(:name => 'test')
|
59
|
+
|
60
|
+
resource.name.should == 'test'
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should initialize parameters" do
|
64
|
+
resource = subject.new(:x => 5)
|
65
|
+
|
66
|
+
resource.x.should == 5
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should allow custom initialize methods" do
|
70
|
+
resource = subject.new
|
71
|
+
|
72
|
+
resource.var.should == 2
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should have an script-type" do
|
77
|
+
resource = subject.new
|
78
|
+
|
79
|
+
resource.script_type.should == 'MyScript'
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "load_from" do
|
83
|
+
let(:path) { repo.find_script('my_scripts/test.rb').path }
|
84
|
+
|
85
|
+
subject { Script.load_from(path) }
|
86
|
+
|
87
|
+
it "should have a script_path resource" do
|
88
|
+
subject.script_path.should_not be_nil
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should prepare the object to be cached" do
|
92
|
+
subject.content.should == 'this is a test'
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should preserve instance variables" do
|
96
|
+
subject.var.should == 2
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should preserve instance methods" do
|
100
|
+
subject.greeting.should == 'hello'
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should load the script source" do
|
104
|
+
subject.should be_script_loaded
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context "when previously cached" do
|
109
|
+
subject { MyScript.first(:name => 'test') }
|
110
|
+
|
111
|
+
it "should have a cached_file resource" do
|
112
|
+
subject.script_path.should_not be_nil
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should be able to load the script source" do
|
116
|
+
subject.load_script!
|
117
|
+
|
118
|
+
subject.greeting.should == 'hello'
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should only load the script source once" do
|
122
|
+
subject.load_script!
|
123
|
+
|
124
|
+
subject.var = false
|
125
|
+
subject.load_script!
|
126
|
+
|
127
|
+
subject.var.should == false
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ronin/script/testable'
|
3
|
+
require 'script/classes/testable_class'
|
4
|
+
|
5
|
+
describe Script::Testable do
|
6
|
+
subject { TestableClass }
|
7
|
+
|
8
|
+
it "should allow for custom verifications" do
|
9
|
+
obj = subject.new do
|
10
|
+
test do
|
11
|
+
flunk('var must be greater than 2') unless self.var > 2
|
12
|
+
end
|
13
|
+
|
14
|
+
test do
|
15
|
+
flunk('var must be less than 10') unless self.var < 10
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
obj.var = 20
|
20
|
+
lambda { obj.test! }.should raise_error(Script::TestFailed)
|
21
|
+
|
22
|
+
obj.var = 4
|
23
|
+
obj.test!.should == true
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should test an expression is true" do
|
27
|
+
obj = subject.new do
|
28
|
+
test? 'var + 2 must equal 4' do
|
29
|
+
(self.var + 2) == 4
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
obj.var = 1
|
34
|
+
lambda { obj.test! }.should raise_error(Script::TestFailed)
|
35
|
+
|
36
|
+
obj.var = 2
|
37
|
+
obj.test!.should == true
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should test a method returns an expected value" do
|
41
|
+
obj = subject.new { test_equal :var, 5 }
|
42
|
+
|
43
|
+
lambda { obj.test! }.should raise_error(Script::TestFailed)
|
44
|
+
|
45
|
+
obj.var = 5
|
46
|
+
obj.test!.should == true
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should test a method does not return an expected value" do
|
50
|
+
obj = subject.new { test_not_equal :var, 5 }
|
51
|
+
|
52
|
+
obj.var = 5
|
53
|
+
lambda { obj.test! }.should raise_error(Script::TestFailed)
|
54
|
+
|
55
|
+
obj.var = 2
|
56
|
+
obj.test!.should == true
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should test a method returns a non-nil value" do
|
60
|
+
obj = subject.new { test_set :var }
|
61
|
+
|
62
|
+
lambda { obj.test! }.should raise_error(Script::TestFailed)
|
63
|
+
|
64
|
+
obj.var = 2
|
65
|
+
obj.test!.should == true
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should test a method returns a non-empty value" do
|
69
|
+
obj = subject.new { test_set :var }
|
70
|
+
|
71
|
+
obj.var = ''
|
72
|
+
lambda { obj.test! }.should raise_error(Script::TestFailed)
|
73
|
+
|
74
|
+
obj.var = 'hello'
|
75
|
+
obj.test!.should == true
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should test a method matches a pattern" do
|
79
|
+
obj = subject.new { test_match :var, /lo/ }
|
80
|
+
|
81
|
+
obj.var = 'goodbye'
|
82
|
+
lambda { obj.test! }.should raise_error(Script::TestFailed)
|
83
|
+
|
84
|
+
obj.var = 'hello'
|
85
|
+
obj.test!.should == true
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should test a method does not match a pattern" do
|
89
|
+
obj = subject.new { test_no_match :var, /lo/ }
|
90
|
+
|
91
|
+
obj.var = 'hello'
|
92
|
+
lambda { obj.test! }.should raise_error(Script::TestFailed)
|
93
|
+
|
94
|
+
obj.var = 'goodbye'
|
95
|
+
obj.test!.should == true
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should test a method returns a value in a set of values" do
|
99
|
+
obj = subject.new { test_in :var, [0, 2, 4, 8] }
|
100
|
+
|
101
|
+
obj.var = 3
|
102
|
+
lambda { obj.test! }.should raise_error(Script::TestFailed)
|
103
|
+
|
104
|
+
obj.var = 2
|
105
|
+
obj.test!.should == true
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should test a method returns a value not in a set of values" do
|
109
|
+
obj = subject.new { test_not_in :var, [0, 2, 4, 8] }
|
110
|
+
|
111
|
+
obj.var = 2
|
112
|
+
lambda { obj.test! }.should raise_error(Script::TestFailed)
|
113
|
+
|
114
|
+
obj.var = 3
|
115
|
+
obj.test!.should == true
|
116
|
+
end
|
117
|
+
end
|