Search in sources :

Example 6 with DisabledOnOs

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");
}
Also used : Path(java.nio.file.Path) PosixFilePermission(java.nio.file.attribute.PosixFilePermission) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 7 with DisabledOnOs

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");
}
Also used : Path(java.nio.file.Path) PosixFilePermission(java.nio.file.attribute.PosixFilePermission) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 8 with DisabledOnOs

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));
}
Also used : Path(java.nio.file.Path) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with DisabledOnOs

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);
}
Also used : Path(java.nio.file.Path) PosixFilePermission(java.nio.file.attribute.PosixFilePermission) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with DisabledOnOs

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");
}
Also used : Path(java.nio.file.Path) PosixFilePermission(java.nio.file.attribute.PosixFilePermission) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

DisabledOnOs (org.junit.jupiter.api.condition.DisabledOnOs)85 Test (org.junit.jupiter.api.Test)78 Path (java.nio.file.Path)38 File (java.io.File)24 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 PathsBaseTest (org.assertj.core.internal.PathsBaseTest)12 AssertionsUtil.expectAssertionError (org.assertj.core.util.AssertionsUtil.expectAssertionError)11 PosixFilePermission (java.nio.file.attribute.PosixFilePermission)6 PageSwapperFactory (org.neo4j.io.pagecache.PageSwapperFactory)6 PageSwapperTest (org.neo4j.io.pagecache.PageSwapperTest)6 CommandBuilder (com.thoughtworks.go.domain.builder.CommandBuilder)5 DelegatingStoreChannel (org.neo4j.io.fs.DelegatingStoreChannel)5 StoreChannel (org.neo4j.io.fs.StoreChannel)5 DisabledForRoot (org.neo4j.test.extension.DisabledForRoot)5 Closeable (java.io.Closeable)4 URI (java.net.URI)4 FileUtils.writeByteArrayToFile (org.apache.commons.io.FileUtils.writeByteArrayToFile)4 ShouldBeFile.shouldBeFile (org.assertj.core.error.ShouldBeFile.shouldBeFile)4 FilesBaseTest (org.assertj.core.internal.FilesBaseTest)4 Files.newFile (org.assertj.core.util.Files.newFile)4