forked from IQSS/dataverse
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(settings): make ConfigCheckService use Files.exist IQSS#9662
With Files.notExist if some folder does not have the "execute" attribute, it cannot detect a folder does not exist. Inverting the Files.exists call solves the problem. Also adding tests for the business logic.
- Loading branch information
1 parent
431afed
commit ec131f8
Showing
2 changed files
with
93 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
src/test/java/edu/harvard/iq/dataverse/settings/ConfigCheckServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package edu.harvard.iq.dataverse.settings; | ||
|
||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Assumptions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.io.TempDir; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Set; | ||
|
||
import static java.nio.file.attribute.PosixFilePermission.GROUP_READ; | ||
import static java.nio.file.attribute.PosixFilePermission.OWNER_READ; | ||
|
||
class ConfigCheckServiceTest { | ||
|
||
@Nested | ||
class TestDirNotWritable { | ||
@TempDir | ||
Path testDir; | ||
|
||
private String oldUploadDirSetting; | ||
|
||
@BeforeEach | ||
void setUp() throws IOException { | ||
Files.setPosixFilePermissions(this.testDir, Set.of(OWNER_READ, GROUP_READ)); | ||
|
||
// TODO: This is a workaround until PR #9273 is merged, providing the ability to lookup values for | ||
// @JvmSetting from static methods. Should be deleted. | ||
this.oldUploadDirSetting = System.getProperty(JvmSettings.UPLOADS_DIRECTORY.getScopedKey()); | ||
System.setProperty(JvmSettings.UPLOADS_DIRECTORY.getScopedKey(), this.testDir.toString()); | ||
} | ||
|
||
@AfterEach | ||
void tearDown() { | ||
// TODO: This is a workaround until PR #9273 is merged, providing the ability to lookup values for | ||
// @JvmSetting from static methods. Should be deleted. | ||
if (this.oldUploadDirSetting != null) | ||
System.setProperty(JvmSettings.UPLOADS_DIRECTORY.getScopedKey(), this.oldUploadDirSetting); | ||
} | ||
|
||
@Test | ||
void writeCheckFails() { | ||
Assumptions.assumeTrue(Files.exists(this.testDir)); | ||
|
||
ConfigCheckService sut = new ConfigCheckService(); | ||
Assertions.assertFalse(sut.checkSystemDirectories()); | ||
} | ||
} | ||
|
||
@Nested | ||
class TestDirNotExistent { | ||
@TempDir | ||
Path testDir; | ||
String subFolder = "foobar"; | ||
|
||
String oldUploadDirSetting; | ||
|
||
@BeforeEach | ||
void setUp() throws IOException { | ||
// Make test dir not writeable, so the subfolder cannot be created | ||
Files.setPosixFilePermissions(this.testDir, Set.of(OWNER_READ, GROUP_READ)); | ||
|
||
// TODO: This is a workaround until PR #9273 is merged, providing the ability to lookup values for | ||
// @JvmSetting from static methods. Should be deleted. | ||
oldUploadDirSetting = System.getProperty(JvmSettings.UPLOADS_DIRECTORY.getScopedKey()); | ||
System.setProperty(JvmSettings.UPLOADS_DIRECTORY.getScopedKey(), this.testDir.resolve(this.subFolder).toString()); | ||
} | ||
|
||
@AfterEach | ||
void tearDown() { | ||
// TODO: This is a workaround until PR #9273 is merged, providing the ability to lookup values for | ||
// @JvmSetting from static methods. Should be deleted. | ||
if (this.oldUploadDirSetting != null) | ||
System.setProperty(JvmSettings.UPLOADS_DIRECTORY.getScopedKey(), this.oldUploadDirSetting); | ||
} | ||
|
||
@Test | ||
void mkdirFails() { | ||
Assumptions.assumeTrue(Files.exists(this.testDir)); | ||
Assumptions.assumeFalse(Files.exists(this.testDir.resolve(this.subFolder))); | ||
|
||
ConfigCheckService sut = new ConfigCheckService(); | ||
Assertions.assertFalse(sut.checkSystemDirectories()); | ||
} | ||
} | ||
|
||
} |