From 68945e96db8d4021672460d2ecfd1225ac413d0d Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Tue, 18 Dec 2018 22:46:02 +0530 Subject: [PATCH] Backport c368fec to 3.7-stable Create symlink only if target is accessible (#7429) --- test/helper.rb | 9 +++++++++ test/test_layout_reader.rb | 9 +++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/test/helper.rb b/test/helper.rb index aa94be13e..aa274a3d4 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -195,6 +195,15 @@ class JekyllUnitTest < Minitest::Test skip msg.to_s.magenta end end + + def symlink_if_allowed(target, sym_file) + FileUtils.ln_sf(target, sym_file) + rescue Errno::EACCES + skip "Permission denied for creating a symlink to #{target.inspect} " \ + "on this machine".magenta + rescue NotImplementedError => error + skip error.to_s.magenta + end end class FakeLogger diff --git a/test/test_layout_reader.rb b/test/test_layout_reader.rb index cade8d44f..373622161 100644 --- a/test/test_layout_reader.rb +++ b/test/test_layout_reader.rb @@ -34,7 +34,8 @@ class TestLayoutReader < JekyllUnitTest context "when a layout is a symlink" do setup do - FileUtils.ln_sf("/etc/passwd", source_dir("_layouts", "symlink.html")) + symlink_if_allowed("/etc/passwd", source_dir("_layouts", "symlink.html")) + @site = fixture_site({ "safe" => true, "include" => ["symlink.html"], @@ -42,7 +43,7 @@ class TestLayoutReader < JekyllUnitTest end teardown do - FileUtils.rm(source_dir("_layouts", "symlink.html")) + FileUtils.rm_f(source_dir("_layouts", "symlink.html")) end should "only read the layouts which are in the site" do @@ -56,7 +57,7 @@ class TestLayoutReader < JekyllUnitTest context "with a theme" do setup do - FileUtils.ln_sf("/etc/passwd", theme_dir("_layouts", "theme-symlink.html")) + symlink_if_allowed("/etc/passwd", theme_dir("_layouts", "theme-symlink.html")) @site = fixture_site({ "include" => ["theme-symlink.html"], "theme" => "test-theme", @@ -65,7 +66,7 @@ class TestLayoutReader < JekyllUnitTest end teardown do - FileUtils.rm(theme_dir("_layouts", "theme-symlink.html")) + FileUtils.rm_f(theme_dir("_layouts", "theme-symlink.html")) end should "not read a symlink'd theme" do