Merge branch 'develop' into feature/custom-shortening-threshold

This commit is contained in:
Jan-Peter Klein
2023-07-05 11:55:51 +02:00
6 changed files with 58 additions and 16 deletions
@@ -18,7 +18,6 @@ import java.util.stream.StreamSupport;
public class Environment {
private static final Logger LOG = LoggerFactory.getLogger(Environment.class);
private static final char PATH_LIST_SEP = ':';
private static final int DEFAULT_MIN_PW_LENGTH = 8;
private static final String SETTINGS_PATH_PROP_NAME = "cryptomator.settingsPath";
private static final String IPC_SOCKET_PATH_PROP_NAME = "cryptomator.ipcSocketPath";
@@ -131,7 +130,7 @@ public class Environment {
// visible for testing
Stream<Path> getPaths(String propertyName) {
Stream<String> rawSettingsPaths = getRawList(propertyName, PATH_LIST_SEP);
Stream<String> rawSettingsPaths = getRawList(propertyName, System.getProperty("path.separator").charAt(0));
return rawSettingsPaths.filter(Predicate.not(Strings::isNullOrEmpty)).map(Path::of);
}
@@ -7,6 +7,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIf;
import org.mockito.Mockito;
import java.nio.file.Path;
@@ -24,6 +25,7 @@ public class EnvironmentTest {
public void init() {
env = Mockito.spy(Environment.getInstance());
}
@Test
@DisplayName("cryptomator.logDir=/foo/bar")
public void testAbsoluteLogDir() {
@@ -58,8 +60,9 @@ public class EnvironmentTest {
}
@Test
@EnabledIf("isColonPathSeperator")
@DisplayName("test.path.property=/foo/bar/test:/bar/nez/tost")
public void testTwoPaths() {
public void testTwoPathsColon() {
System.setProperty("test.path.property", "/foo/bar/test:bar/nez/tost");
List<Path> result = env.getPaths("test.path.property").toList();
@@ -67,6 +70,25 @@ public class EnvironmentTest {
MatcherAssert.assertThat(result, Matchers.hasItems(Path.of("/foo/bar/test"), Path.of("bar/nez/tost")));
}
@Test
@EnabledIf("isSemiColonPathSeperator")
@DisplayName("test.path.property=/foo/bar/test;/bar/nez/tost")
public void testTwoPathsSemiColon() {
System.setProperty("test.path.property", "/foo/bar/test;bar/nez/tost");
List<Path> result = env.getPaths("test.path.property").toList();
MatcherAssert.assertThat(result, Matchers.hasSize(2));
MatcherAssert.assertThat(result, Matchers.hasItems(Path.of("/foo/bar/test"), Path.of("bar/nez/tost")));
}
boolean isColonPathSeperator() {
return System.getProperty("path.separator").equals(":");
}
boolean isSemiColonPathSeperator() {
return System.getProperty("path.separator").equals(";");
}
}
@Nested
@@ -78,18 +100,21 @@ public class EnvironmentTest {
env.getSettingsPath();
Mockito.verify(env).getPaths("cryptomator.settingsPath");
}
@Test
public void testP12Path() {
Mockito.doReturn(Stream.of()).when(env).getPaths(Mockito.anyString());
env.getP12Path();
Mockito.verify(env).getPaths("cryptomator.p12Path");
}
@Test
public void testIpcSocketPath() {
Mockito.doReturn(Stream.of()).when(env).getPaths(Mockito.anyString());
env.getIpcSocketPath();
Mockito.verify(env).getPaths("cryptomator.ipcSocketPath");
}
@Test
public void testKeychainPath() {
Mockito.doReturn(Stream.of()).when(env).getPaths(Mockito.anyString());