Skip to content

JUnit tests require admin permissions on Windows #1648

@hohwille

Description

@hohwille

Actual behavior

17:33:16.922 [main] - DEBUG - c.d.tools.ide.log.IdeSubLoggerSlf4j - Creating absolute symbolic link at C:\Users\devyasin\AppData\Local\Temp\junit-14574512735759234414\junction pointing to C:\Users\devyasin\AppData\Local\Temp\junit-14574512735759234414\source
17:33:16.923 [main] - INFO  - c.d.tools.ide.log.IdeSubLoggerSlf4j - Due to lack of permissions, Microsoft's mklink with junction had to be used to create a Symlink. See
https://github.com/devonfw/IDEasy/blob/main/documentation/symlink.adoc for further details. Error was: C:\Users\devyasin\AppData\Local\Temp\junit-14574512735759234414\junction: A required privilege is not held by the client
17:33:16.925 [main] - DEBUG - c.d.tools.ide.log.IdeSubLoggerSlf4j - Running command 'C:\WINDOWS\system32\cmd.exe' with arguments '/c' 'mklink' '/d' '/j' 'C:\Users\devyasin\AppData\Local\Temp\junit-14574512735759234414\junction' 'C:\Users\devyasin\AppData\Local\Temp\junit-14574512735759234414\source' ...
[ERROR] Tests run: 22, Failures: 0, Errors: 2, Skipped: 2, Time elapsed: 10.68 s <<< FAILURE! -- in com.devonfw.tools.ide.io.FileAccessImplTest
[ERROR] com.devonfw.tools.ide.io.FileAccessImplTest.testSymlinkWindowsJunctionsCanNotPointToFiles(Path) -- Time elapsed: 0.068 s <<< ERROR!
java.lang.IllegalStateException:
Running command 'C:\WINDOWS\system32\cmd.exe' with arguments '/c' 'mklink' '/d' 'C:\Users\devyasin\AppData\Local\Temp\junit-13997646278386072421\linkToFile' 'file'
failed with exit code 1!
        at com.devonfw.tools.ide.process.ProcessContextImpl.performLogging(ProcessContextImpl.java:366)
        at com.devonfw.tools.ide.process.ProcessContextImpl.run(ProcessContextImpl.java:207)
        at com.devonfw.tools.ide.io.FileAccessImpl.mklinkOnWindows(FileAccessImpl.java:489)
        at com.devonfw.tools.ide.io.FileAccessImpl.link(FileAccessImpl.java:519)
        at com.devonfw.tools.ide.io.FileAccess.symlink(FileAccess.java:111)
        at com.devonfw.tools.ide.io.FileAccess.symlink(FileAccess.java:97)
        at com.devonfw.tools.ide.io.FileAccessImplTest.testSymlinkWindowsJunctionsCanNotPointToFiles(FileAccessImplTest.java:197)
        at java.base/java.lang.reflect.Method.invoke(Method.java:565)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1604)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1604)

[ERROR] com.devonfw.tools.ide.io.FileAccessImplTest.testUntarWithGzipCompressionWithSymbolicLink(Path) -- Time elapsed: 0.075 s <<< ERROR!
java.lang.IllegalStateException: Failed to extract src\test\resources\com\devonfw\tools\ide\io\link.tar.gz to C:\Users\devyasin\AppData\Local\Temp\junit-7276324211940625225
        at com.devonfw.tools.ide.io.FileAccessImpl.extractArchive(FileAccessImpl.java:773)
        at com.devonfw.tools.ide.io.FileAccessImpl.extractTar(FileAccessImpl.java:693)
        at com.devonfw.tools.ide.io.FileAccessImplTest.testUntarWithGzipCompressionWithSymbolicLink(FileAccessImplTest.java:548)
        at java.base/java.lang.reflect.Method.invoke(Method.java:565)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1604)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1604)
Caused by: java.lang.IllegalStateException: Running command 'C:\WINDOWS\system32\cmd.exe' with arguments '/c' 'mklink' '/d' 'C:\Users\devyasin\AppData\Local\Temp\junit-7276324211940625225\link' 'file'
failed with exit code 1!
        at com.devonfw.tools.ide.process.ProcessContextImpl.performLogging(ProcessContextImpl.java:366)
        at com.devonfw.tools.ide.process.ProcessContextImpl.run(ProcessContextImpl.java:207)
        at com.devonfw.tools.ide.io.FileAccessImpl.mklinkOnWindows(FileAccessImpl.java:489)
        at com.devonfw.tools.ide.io.FileAccessImpl.link(FileAccessImpl.java:519)
        at com.devonfw.tools.ide.io.FileAccess.link(FileAccess.java:141)
        at com.devonfw.tools.ide.io.FileAccessImpl.extractArchive(FileAccessImpl.java:770)
        ... 5 more
...
[ERROR] Errors:
[ERROR]   FileAccessImplTest.testSymlinkWindowsJunctionsCanNotPointToFiles:197 » IllegalState Running command 'C:\WINDOWS\system32\cmd.exe' with arguments '/c' 'mklink' '/d' 'C:\Users\devyasin\AppData\Local\Temp\junit-13997646278386072421\linkToFile' 'file'
failed with exit code 1!
[ERROR]   FileAccessImplTest.testUntarWithGzipCompressionWithSymbolicLink:548 » IllegalState Failed to extract src\test\resources\com\devonfw\tools\ide\io\link.tar.gz to C:\Users\devyasin\AppData\Local\Temp\junit-7276324211940625225
[INFO]
[ERROR] Tests run: 566, Failures: 0, Errors: 2, Skipped: 8

Reproduce

  1. clone IDEasy
  2. cd cli
  3. mvn clean test

Expected behavior

Tests should succeed.

IDEasy status

IDE_ROOT is set to D:/projects
IDE_HOME is set to D:/projects/project
You are online.
Found bash executable at: C:/Program Files/Git/usr/bin/bash.exe
Found git executable at: C:/Program Files/Git/mingw64/bin/git.exe
Your settings are up-to-date.
Your version of IDEasy is SNAPSHOT.
You are using a SNAPSHOT version of IDEasy. For stability consider switching to a stable release via 'ide upgrade --mode=stable'
Your are using the latest version of IDEasy and no update is available.
Your operating system is windows(10.0)@x64 [Windows 11@amd64]

Related/Dependent issues

No response

Comments/Hints

@Test
@EnabledOnOs(OS.WINDOWS)
public void testSymlinkWindowsJunctionsCanNotPointToFiles(@TempDir Path tempDir) throws IOException {
// arrange
IdeContext context = IdeTestContextMock.get();
FileAccess fileAccess = context.getFileAccess();
Path file = tempDir.resolve("file");
Files.createFile(file);
Path linkToFile = tempDir.resolve("linkToFile");
// act
fileAccess.symlink(file, linkToFile);
// assert
assertThat(linkToFile.toRealPath()).isEqualTo(file.toRealPath());
}

@Test
public void testUntarWithGzipCompressionWithSymbolicLink(@TempDir Path tempDir) {
// arrange
IdeContext context = IdeTestContextMock.get();
Path linkTarGz = Path.of("src/test/resources/com/devonfw/tools/ide/io/link.tar.gz");
FileAccess fileAccess = context.getFileAccess();
// act
fileAccess.extractTar(linkTarGz, tempDir, TarCompression.GZ);
// assert
Path link = tempDir.resolve("link");
assertThat(link).hasContent("hi");
assertThat(fileAccess.toRealPath(link)).isEqualTo(tempDir.resolve("file"));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    linksymlinks and windows junctionstestrelated to testing and QAwindowsspecific for Microsoft Windows OS

    Type

    Projects

    Status

    🆕 New

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions