use of org.junit.jupiter.api.condition.DisabledOnOs in project neo4j by neo4j.
the class ConfigTest method testForbiddenFilePermissionsShouldBeInvalidWhenCombinedWithPermittedPermissions.
@DisabledOnOs({ OS.WINDOWS })
@ParameterizedTest(name = "{0}")
@MethodSource("forbiddenFilePermissions")
void testForbiddenFilePermissionsShouldBeInvalidWhenCombinedWithPermittedPermissions(Set<PosixFilePermission> forbidden) throws IOException {
// Given
Set<PosixFilePermission> permittedPermissions = permittedFilePermissionsForCommandExpansion;
Path confFile = testDirectory.file("test.conf");
Files.createFile(confFile);
Files.write(confFile, List.of(format("%s=$(expr 3 + 3)", TestSettings.intSetting.name())));
setPosixFilePermissions(confFile, Sets.union(permittedPermissions, forbidden));
Config.Builder builder = Config.newBuilder().allowCommandExpansion().addSettingsClass(TestSettings.class).fromFile(confFile);
// when
String errorMessage = assertThrows(IllegalArgumentException.class, builder::build).getMessage();
// then
assertThat(errorMessage).contains("does not have the correct file permissions to evaluate commands");
}
use of org.junit.jupiter.api.condition.DisabledOnOs in project neo4j by neo4j.
the class ConfigTest method testForbiddenFilePermissionsShouldBeInvalidOnTheirOwnForK8sConfDir.
@DisabledOnOs({ OS.WINDOWS })
@ParameterizedTest(name = "{0}")
@MethodSource("forbiddenFilePermissions")
void testForbiddenFilePermissionsShouldBeInvalidOnTheirOwnForK8sConfDir(Set<PosixFilePermission> forbidden) throws IOException {
// Given
// required otherwise the test will fail because we cannot read the file at all
Set<PosixFilePermission> readable = Set.of(OWNER_READ);
Path confDir = createK8sStyleConfigDir(Sets.union(readable, forbidden));
Config.Builder builder = Config.newBuilder().allowCommandExpansion().addSettingsClass(TestSettings.class).fromFile(confDir);
// when
String errorMessage = assertThrows(IllegalArgumentException.class, builder::build).getMessage();
// then
assertThat(errorMessage).contains("does not have the correct file permissions to evaluate commands");
}
use of org.junit.jupiter.api.condition.DisabledOnOs in project neo4j by neo4j.
the class ConfigTest method shouldHandleQuotesCorrectlyInCommandExpansion.
@Test
@DisabledOnOs(OS.WINDOWS)
void shouldHandleQuotesCorrectlyInCommandExpansion() throws IOException {
Path confFile = testDirectory.file("test.conf");
Files.createFile(confFile);
Files.write(confFile, List.of(format("%s=$(bash -c \"echo '1'\")", TestSettings.stringSetting.name())));
setPosixFilePermissions(confFile, permittedFilePermissionsForCommandExpansion);
// Given
Config config = Config.newBuilder().allowCommandExpansion().addSettingsClass(TestSettings.class).fromFile(confFile).build();
// Then
assertEquals("1", config.get(TestSettings.stringSetting));
}
use of org.junit.jupiter.api.condition.DisabledOnOs in project neo4j by neo4j.
the class ConfigTest method testThatFilesPosixFilePermissionsDoWork.
@Test
@DisabledOnOs(OS.WINDOWS)
void testThatFilesPosixFilePermissionsDoWork() throws IOException {
// Given
Path confFile = testDirectory.file("test.conf");
Set<PosixFilePermission> permissions = PosixFilePermissions.fromString("rw---x-w-");
// When
Files.createFile(confFile);
Files.setPosixFilePermissions(confFile, permissions);
// Then
assertThat(Files.getPosixFilePermissions(confFile)).containsExactlyInAnyOrderElementsOf(permissions);
}
use of org.junit.jupiter.api.condition.DisabledOnOs in project neo4j by neo4j.
the class ConfigTest method testForbiddenFilePermissionsShouldBeInvalidOnTheirOwn.
@DisabledOnOs({ OS.WINDOWS })
@ParameterizedTest(name = "{0}")
@MethodSource("forbiddenFilePermissions")
void testForbiddenFilePermissionsShouldBeInvalidOnTheirOwn(Set<PosixFilePermission> forbidden) throws IOException {
// Given
// required otherwise the test will fail because we cannot read the file at all
Set<PosixFilePermission> readable = Set.of(OWNER_READ);
Path confFile = testDirectory.file("test.conf");
Files.createFile(confFile);
Files.write(confFile, List.of(format("%s=$(expr 3 + 3)", TestSettings.intSetting.name())));
setPosixFilePermissions(confFile, Sets.union(readable, forbidden));
Config.Builder builder = Config.newBuilder().allowCommandExpansion().addSettingsClass(TestSettings.class).fromFile(confFile);
// when
String errorMessage = assertThrows(IllegalArgumentException.class, builder::build).getMessage();
// then
assertThat(errorMessage).contains("does not have the correct file permissions to evaluate commands");
}
Aggregations