|
| 1 | +require 'rex/file' |
| 2 | + |
| 3 | +describe Rex::FileUtils do |
| 4 | + context "Class methods" do |
| 5 | + |
| 6 | + context ".normalize_win_path" do |
| 7 | + it "should convert an absolute path as an array into Windows format" do |
| 8 | + described_class.normalize_win_path('C:\\', 'hello', 'world').should eq("C:\\hello\\world") |
| 9 | + end |
| 10 | + |
| 11 | + it "should convert an absolute path as a string into Windows format" do |
| 12 | + described_class.normalize_win_path('C:\\hello\\world').should eq("C:\\hello\\world") |
| 13 | + end |
| 14 | + |
| 15 | + it "should convert a path without reserved characters" do |
| 16 | + described_class.normalize_win_path('C:\\', 'Windows:').should eq("C:\\Windows") |
| 17 | + described_class.normalize_win_path('C:\\Windows???\\test').should eq("C:\\Windows\\test") |
| 18 | + end |
| 19 | + |
| 20 | + it "should convert a path without double slashes" do |
| 21 | + described_class.normalize_win_path('C:\\\\\\', 'Windows').should eq("C:\\Windows") |
| 22 | + described_class.normalize_win_path('C:\\\\\\Hello World\\\\whatever.txt').should eq("C:\\Hello World\\whatever.txt") |
| 23 | + described_class.normalize_win_path('C:\\\\').should eq("C:\\") |
| 24 | + end |
| 25 | + |
| 26 | + it "should parse UNC path format as an array" do |
| 27 | + described_class.normalize_win_path('\\\\127.0.0.1', 'C$').should eq("\\\\127.0.0.1\\C$") |
| 28 | + described_class.normalize_win_path('\\\\127.0.0.1\\C$').should eq("\\\\127.0.0.1\\C$") |
| 29 | + end |
| 30 | + |
| 31 | + it "should parse a relative path in Windows format" do |
| 32 | + described_class.normalize_win_path('\\\\127.0.0.1', 'C$').should eq("\\\\127.0.0.1\\C$") |
| 33 | + described_class.normalize_win_path('\\\\127.0.0.1\\C$').should eq("\\\\127.0.0.1\\C$") |
| 34 | + end |
| 35 | + end |
| 36 | + |
| 37 | + context ".normalize_unix_path" do |
| 38 | + it "should convert an absolute path as an array into Unix format" do |
| 39 | + described_class.normalize_unix_path('/etc', '/passwd').should eq("/etc/passwd") |
| 40 | + end |
| 41 | + |
| 42 | + it "should convert an absolute path as a string into Windows format" do |
| 43 | + described_class.normalize_unix_path('/etc/passwd').should eq('/etc/passwd') |
| 44 | + end |
| 45 | + |
| 46 | + it "should convert a path without double slashes" do |
| 47 | + described_class.normalize_unix_path('//etc////passwd').should eq("/etc/passwd") |
| 48 | + described_class.normalize_unix_path('/etc////', 'passwd').should eq('/etc/passwd') |
| 49 | + end |
| 50 | + end |
| 51 | + |
| 52 | + end |
| 53 | +end |
| 54 | + |
0 commit comments