Skip to content

Commit 510e347

Browse files
author
Brent Cook
committed
Land rapid7#8015, prevent tests from fighting each other
2 parents 09c9e9b + 49fbd31 commit 510e347

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

test/modules/post/test/meterpreter.rb

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def initialize(info={})
2121
))
2222
register_options(
2323
[
24+
OptBool.new("AddEntropy" , [false, "Add entropy token to file and directory names.", false]),
2425
OptString.new("BaseFileName" , [true, "File/dir base name", "meterpreter-test"])
2526
], self.class)
2627
end
@@ -132,7 +133,12 @@ def test_net_config
132133

133134
def test_fs
134135
vprint_status("Starting filesystem tests")
135-
136+
if datastore["AddEntropy"]
137+
entropy_value = '-' + ('a'..'z').to_a.shuffle[0,8].join
138+
else
139+
entropy_value = ""
140+
end
141+
136142
it "should return the proper directory separator" do
137143
sysinfo = session.sys.config.sysinfo
138144
if sysinfo["OS"] =~ /windows/i
@@ -167,7 +173,8 @@ def test_fs
167173
end
168174

169175
it "should create and remove a dir" do
170-
dir_name = "#{datastore["BaseFileName"]}-dir"
176+
dir_name = "#{datastore["BaseFileName"]}-dir#{entropy_value}"
177+
vprint_status("Directory Name: #{dir_name}")
171178
session.fs.dir.rmdir(dir_name) rescue nil
172179
res = create_directory(dir_name)
173180
if (res)
@@ -180,7 +187,8 @@ def test_fs
180187
end
181188

182189
it "should change directories" do
183-
dir_name = "#{datastore["BaseFileName"]}-dir"
190+
dir_name = "#{datastore["BaseFileName"]}-dir#{entropy_value}"
191+
vprint_status("Directory Name: #{dir_name}")
184192
session.fs.dir.rmdir(dir_name) rescue nil
185193
res = create_directory(dir_name)
186194

@@ -208,7 +216,8 @@ def test_fs
208216

209217
it "should create and remove files" do
210218
res = true
211-
file_name = datastore["BaseFileName"]
219+
file_name = "#{datastore["BaseFileName"]}#{entropy_value}"
220+
vprint_status("File Name: #{file_name}")
212221
res &&= session.fs.file.open(file_name, "wb") { |fd|
213222
fd.write("test")
214223
}
@@ -228,7 +237,8 @@ def test_fs
228237

229238
it "should upload a file" do
230239
res = true
231-
remote = "#{datastore["BaseFileName"]}-file.txt"
240+
remote = "#{datastore["BaseFileName"]}-file#{entropy_value}.txt"
241+
vprint_status("Remote File Name: #{remote}")
232242
local = __FILE__
233243
vprint_status("uploading")
234244
session.fs.file.upload_file(remote, local)
@@ -254,8 +264,10 @@ def test_fs
254264

255265
it "should move files" do
256266
res = true
257-
src_name = datastore["BaseFileName"]
258-
dst_name = "#{datastore["BaseFileName"]}-moved"
267+
src_name = "#{datastore["BaseFileName"]}#{entropy_value}"
268+
vprint_status("Source File Name: #{src_name}")
269+
dst_name = "#{src_name}-moved"
270+
vprint_status("Destination File Name: #{dst_name}")
259271

260272
# Make sure we don't have leftovers from a previous run
261273
session.fs.file.rm(src_name) rescue nil
@@ -279,8 +291,10 @@ def test_fs
279291

280292
it "should copy files" do
281293
res = true
282-
src_name = datastore["BaseFileName"]
283-
dst_name = "#{datastore["BaseFileName"]}-copied"
294+
src_name = "#{datastore["BaseFileName"]}#{entropy_value}"
295+
vprint_status("Source File Name: #{src_name}")
296+
dst_name = "#{src_name}-copied"
297+
vprint_status("Destination File Name: #{dst_name}")
284298

285299
# Make sure we don't have leftovers from a previous run
286300
session.fs.file.rm(src_name) rescue nil
@@ -304,7 +318,8 @@ def test_fs
304318

305319
it "should do md5 and sha1 of files" do
306320
res = true
307-
remote = "#{datastore["BaseFileName"]}-file.txt"
321+
remote = "#{datastore["BaseFileName"]}-file#{entropy_value}.txt"
322+
vprint_status("Remote File Name: #{remote}")
308323
local = __FILE__
309324
vprint_status("uploading")
310325
session.fs.file.upload_file(remote, local)

0 commit comments

Comments
 (0)