Skip to content

Commit

Permalink
Merge pull request rapid7#19554 from smashery/new-junction-test
Browse files Browse the repository at this point in the history
Added new tests for Windows junction points
  • Loading branch information
smcintyre-r7 authored Nov 1, 2024
2 parents 1634cdc + a854689 commit d9b3528
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/modules/post/test/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,27 @@ def test_dir
ret
end
end

if (session.platform == 'windows')
it 'should delete a junction target' do
mkdir(datastore['BaseDirectoryName'])
ret = directory?(datastore['BaseDirectoryName'])
link = "#{datastore['BaseDirectoryName']}.junc"
ret &&= write_file([datastore['BaseDirectoryName'], 'file'].join(fs_sep), '')
make_junction(datastore['BaseDirectoryName'], link)
unless exists?(link)
print_error('failed to create the symbolic link')
end
rm_rf(link)
# the link should have been deleted
ret &&= !exists?(link)
# but the target directory and its contents should still be intact
ret &&= exists?("#{[datastore['BaseDirectoryName'], 'file'].join(fs_sep)}")
rm_rf(datastore['BaseDirectoryName'])
ret
end
end

end

def test_file
Expand Down Expand Up @@ -289,6 +310,10 @@ def test_path_expansion_nix
end
end

def make_junction(target, symlink)
cmd_exec("cmd.exe", "/c mklink #{directory?(target) ? '/J ' : ''}#{symlink} #{target}")
end

def make_symlink(target, symlink)
if session.platform == 'windows'
cmd_exec("cmd.exe", "/c mklink #{directory?(target) ? '/D ' : ''}#{symlink} #{target}")
Expand Down

0 comments on commit d9b3528

Please sign in to comment.