Skip to content

Commit d9b3528

Browse files
authored
Merge pull request rapid7#19554 from smashery/new-junction-test
Added new tests for Windows junction points
2 parents 1634cdc + a854689 commit d9b3528

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

test/modules/post/test/file.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,27 @@ def test_dir
117117
ret
118118
end
119119
end
120+
121+
if (session.platform == 'windows')
122+
it 'should delete a junction target' do
123+
mkdir(datastore['BaseDirectoryName'])
124+
ret = directory?(datastore['BaseDirectoryName'])
125+
link = "#{datastore['BaseDirectoryName']}.junc"
126+
ret &&= write_file([datastore['BaseDirectoryName'], 'file'].join(fs_sep), '')
127+
make_junction(datastore['BaseDirectoryName'], link)
128+
unless exists?(link)
129+
print_error('failed to create the symbolic link')
130+
end
131+
rm_rf(link)
132+
# the link should have been deleted
133+
ret &&= !exists?(link)
134+
# but the target directory and its contents should still be intact
135+
ret &&= exists?("#{[datastore['BaseDirectoryName'], 'file'].join(fs_sep)}")
136+
rm_rf(datastore['BaseDirectoryName'])
137+
ret
138+
end
139+
end
140+
120141
end
121142

122143
def test_file
@@ -289,6 +310,10 @@ def test_path_expansion_nix
289310
end
290311
end
291312

313+
def make_junction(target, symlink)
314+
cmd_exec("cmd.exe", "/c mklink #{directory?(target) ? '/J ' : ''}#{symlink} #{target}")
315+
end
316+
292317
def make_symlink(target, symlink)
293318
if session.platform == 'windows'
294319
cmd_exec("cmd.exe", "/c mklink #{directory?(target) ? '/D ' : ''}#{symlink} #{target}")

0 commit comments

Comments
 (0)