2013-07-23 00:26:04 +00:00
|
|
|
require 'rex/file'
|
|
|
|
|
2015-10-16 20:57:04 +00:00
|
|
|
RSpec.describe Rex::FileUtils do
|
2013-09-30 18:47:53 +00:00
|
|
|
context "Class methods" do
|
|
|
|
|
|
|
|
context ".normalize_win_path" do
|
|
|
|
it "should convert an absolute path as an array into Windows format" do
|
2015-10-20 19:37:18 +00:00
|
|
|
expect(described_class.normalize_win_path('C:\\', 'hello', 'world')).to eq("C:\\hello\\world")
|
2013-09-30 18:47:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should convert an absolute path as a string into Windows format" do
|
2015-10-20 19:37:18 +00:00
|
|
|
expect(described_class.normalize_win_path('C:\\hello\\world')).to eq("C:\\hello\\world")
|
2013-09-30 18:47:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should convert a relative path" do
|
2015-10-20 19:37:18 +00:00
|
|
|
expect(described_class.normalize_win_path('/', 'test', 'me')).to eq("\\test\\me")
|
|
|
|
expect(described_class.normalize_win_path('\\temp')).to eq("\\temp")
|
|
|
|
expect(described_class.normalize_win_path('temp')).to eq("temp")
|
2013-09-30 18:47:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should keep the trailing slash if exists" do
|
2015-10-20 19:37:18 +00:00
|
|
|
expect(described_class.normalize_win_path('/', 'test', 'me\\')).to eq("\\test\\me\\")
|
|
|
|
expect(described_class.normalize_win_path('\\temp\\')).to eq("\\temp\\")
|
2013-09-30 18:47:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should convert a path without reserved characters" do
|
2015-10-20 19:37:18 +00:00
|
|
|
expect(described_class.normalize_win_path('C:\\', 'Windows:')).to eq("C:\\Windows")
|
|
|
|
expect(described_class.normalize_win_path('C:\\Windows???\\test')).to eq("C:\\Windows\\test")
|
2013-09-30 18:47:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should convert a path without double slashes" do
|
2015-10-20 19:37:18 +00:00
|
|
|
expect(described_class.normalize_win_path('C:\\\\\\', 'Windows')).to eq("C:\\Windows")
|
|
|
|
expect(described_class.normalize_win_path('C:\\\\\\Hello World\\\\whatever.txt')).to eq("C:\\Hello World\\whatever.txt")
|
|
|
|
expect(described_class.normalize_win_path('C:\\\\')).to eq("C:\\")
|
|
|
|
expect(described_class.normalize_win_path('\\test\\\\test\\\\')).to eq("\\test\\test\\")
|
2013-09-30 18:47:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context ".normalize_unix_path" do
|
|
|
|
it "should convert an absolute path as an array into Unix format" do
|
2015-10-20 19:37:18 +00:00
|
|
|
expect(described_class.normalize_unix_path('/etc', '/passwd')).to eq("/etc/passwd")
|
2013-09-30 18:47:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should convert an absolute path as a string into Unix format" do
|
2015-10-20 19:37:18 +00:00
|
|
|
expect(described_class.normalize_unix_path('/etc/passwd')).to eq('/etc/passwd')
|
2013-09-30 18:47:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should still give me a trailing slash if I have it" do
|
2015-10-20 19:37:18 +00:00
|
|
|
expect(described_class.normalize_unix_path('/etc/folder/')).to eq("/etc/folder/")
|
2013-09-30 18:47:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should convert a path without double slashes" do
|
2015-10-20 19:37:18 +00:00
|
|
|
expect(described_class.normalize_unix_path('//etc////passwd')).to eq("/etc/passwd")
|
|
|
|
expect(described_class.normalize_unix_path('/etc////', 'passwd')).to eq('/etc/passwd')
|
2013-09-30 18:47:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2013-07-23 00:26:04 +00:00
|
|
|
end
|
|
|
|
|