PageRenderTime 48ms CodeModel.GetById 15ms app.highlight 28ms RepoModel.GetById 1ms app.codeStats 0ms

/spec/lib/rex/file_utils_spec.rb

https://github.com/debbiemezyene/metasploit-framework
Ruby | 60 lines | 57 code | 3 blank | 0 comment | 0 complexity | c32635c2cedac4ff31b89ee03686aec3 MD5 | raw file
 1require 'rex/file'
 2
 3describe 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 relative path" do
16        described_class.normalize_win_path('/', 'test', 'me').should eq("\\test\\me")
17        described_class.normalize_win_path('\\temp').should eq("\\temp")
18        described_class.normalize_win_path('temp').should eq("temp")
19      end
20
21      it "should keep the trailing slash if exists" do
22        described_class.normalize_win_path('/', 'test', 'me\\').should eq("\\test\\me\\")
23        described_class.normalize_win_path('\\temp\\').should eq("\\temp\\")
24      end
25
26      it "should convert a path without reserved characters" do
27        described_class.normalize_win_path('C:\\', 'Windows:').should eq("C:\\Windows")
28        described_class.normalize_win_path('C:\\Windows???\\test').should eq("C:\\Windows\\test")
29      end
30
31      it "should convert a path without double slashes" do
32        described_class.normalize_win_path('C:\\\\\\', 'Windows').should eq("C:\\Windows")
33        described_class.normalize_win_path('C:\\\\\\Hello World\\\\whatever.txt').should eq("C:\\Hello World\\whatever.txt")
34        described_class.normalize_win_path('C:\\\\').should eq("C:\\")
35        described_class.normalize_win_path('\\test\\\\test\\\\').should eq("\\test\\test\\")
36      end
37    end
38
39    context ".normalize_unix_path" do
40      it "should convert an absolute path as an array into Unix format" do
41        described_class.normalize_unix_path('/etc', '/passwd').should eq("/etc/passwd")
42      end
43
44      it "should convert an absolute path as a string into Unix format" do
45        described_class.normalize_unix_path('/etc/passwd').should eq('/etc/passwd')
46      end
47
48      it "should still give me a trailing slash if I have it" do
49        described_class.normalize_unix_path('/etc/folder/').should eq("/etc/folder/")
50      end
51
52      it "should convert a path without double slashes" do
53        described_class.normalize_unix_path('//etc////passwd').should eq("/etc/passwd")
54        described_class.normalize_unix_path('/etc////', 'passwd').should eq('/etc/passwd')
55      end
56    end
57
58  end
59end
60