/spec/lib/rex/file_utils_spec.rb

https://github.com/debbiemezyene/metasploit-framework · Ruby · 60 lines · 47 code · 13 blank · 0 comment · 2 complexity · c32635c2cedac4ff31b89ee03686aec3 MD5 · raw file

  1. require 'rex/file'
  2. describe Rex::FileUtils do
  3. context "Class methods" do
  4. context ".normalize_win_path" do
  5. it "should convert an absolute path as an array into Windows format" do
  6. described_class.normalize_win_path('C:\\', 'hello', 'world').should eq("C:\\hello\\world")
  7. end
  8. it "should convert an absolute path as a string into Windows format" do
  9. described_class.normalize_win_path('C:\\hello\\world').should eq("C:\\hello\\world")
  10. end
  11. it "should convert a relative path" do
  12. described_class.normalize_win_path('/', 'test', 'me').should eq("\\test\\me")
  13. described_class.normalize_win_path('\\temp').should eq("\\temp")
  14. described_class.normalize_win_path('temp').should eq("temp")
  15. end
  16. it "should keep the trailing slash if exists" do
  17. described_class.normalize_win_path('/', 'test', 'me\\').should eq("\\test\\me\\")
  18. described_class.normalize_win_path('\\temp\\').should eq("\\temp\\")
  19. end
  20. it "should convert a path without reserved characters" do
  21. described_class.normalize_win_path('C:\\', 'Windows:').should eq("C:\\Windows")
  22. described_class.normalize_win_path('C:\\Windows???\\test').should eq("C:\\Windows\\test")
  23. end
  24. it "should convert a path without double slashes" do
  25. described_class.normalize_win_path('C:\\\\\\', 'Windows').should eq("C:\\Windows")
  26. described_class.normalize_win_path('C:\\\\\\Hello World\\\\whatever.txt').should eq("C:\\Hello World\\whatever.txt")
  27. described_class.normalize_win_path('C:\\\\').should eq("C:\\")
  28. described_class.normalize_win_path('\\test\\\\test\\\\').should eq("\\test\\test\\")
  29. end
  30. end
  31. context ".normalize_unix_path" do
  32. it "should convert an absolute path as an array into Unix format" do
  33. described_class.normalize_unix_path('/etc', '/passwd').should eq("/etc/passwd")
  34. end
  35. it "should convert an absolute path as a string into Unix format" do
  36. described_class.normalize_unix_path('/etc/passwd').should eq('/etc/passwd')
  37. end
  38. it "should still give me a trailing slash if I have it" do
  39. described_class.normalize_unix_path('/etc/folder/').should eq("/etc/folder/")
  40. end
  41. it "should convert a path without double slashes" do
  42. described_class.normalize_unix_path('//etc////passwd').should eq("/etc/passwd")
  43. described_class.normalize_unix_path('/etc////', 'passwd').should eq('/etc/passwd')
  44. end
  45. end
  46. end
  47. end