Skip to content

Commit f3e2269

Browse files
authored
Skip CopyArtifactTest#testSymlinks tests on Windows if no symlink support (#259)
Windows 10 and Windows 11 do not allow symbolic links to be created unless the permission is granted to the user in group policy and the Windows developer mode is enabled. https://gist.github.com/huenisys/1efb64e57c37cfab7054c65702588fce provides one description. https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-10/security/threat-protection/security-policy-settings/create-symbolic-links warns that it is a security risk to allow symbolic links in applications that are not designed to handle them.
1 parent 82c3313 commit f3e2269

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/test/java/hudson/plugins/copyartifact/CopyArtifactTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
import static org.junit.Assert.assertSame;
131131
import static org.junit.Assert.assertTrue;
132132
import static org.junit.Assert.fail;
133+
import static org.junit.Assume.assumeFalse;
133134
import static org.junit.Assume.assumeThat;
134135

135136
/**
@@ -1920,6 +1921,11 @@ public void testSymlinks() throws Exception {
19201921
FreeStyleBuild b = rule.buildAndAssertSuccess(p2);
19211922
FilePath ws = b.getWorkspace();
19221923
assertEquals("text", ws.child("plain").readToString());
1924+
// Windows 10 and 11 by default will not create symbolic links. Don't fail test
1925+
// Mark the test as skipped if running on Windows and both symlinks return null
1926+
assumeFalse(Functions.isWindows() &&
1927+
ws.child("link1").readLink() == null &&
1928+
ws.child("link2").readLink() == null);
19231929
assertEquals("plain", ws.child("link1").readLink());
19241930
assertEquals("nonexistent", ws.child("link2").readLink());
19251931
}
@@ -1943,6 +1949,10 @@ public void testSymlinksInDirectory() throws Exception {
19431949
FreeStyleBuild b = rule.buildAndAssertSuccess(p2);
19441950
FilePath ws = b.getWorkspace();
19451951
assertEquals("text", ws.child("plain").readToString());
1952+
// Windows 10 and 11 by default will not create symbolic links. Don't fail test
1953+
// Mark the test as skipped if running on Windows and symlink is null
1954+
assumeFalse(Functions.isWindows() &&
1955+
ws.child("dir/link1").readLink() == null);
19461956
assertEquals(
19471957
StringUtils.join(
19481958
new String[]{"..", "plain"},

0 commit comments

Comments
 (0)