Search in sources :

Example 1 with DisabledForRoot

use of org.neo4j.test.extension.DisabledForRoot in project neo4j by neo4j.

the class ConfigTest method shouldLogIfConfigFileCouldNotBeRead.

@Test
@DisabledForRoot
void shouldLogIfConfigFileCouldNotBeRead() throws IOException {
    AssertableLogProvider logProvider = new AssertableLogProvider(true);
    Log log = logProvider.getLog(Config.class);
    Path confFile = testDirectory.file("test.conf");
    assertTrue(confFile.toFile().createNewFile());
    assumeTrue(confFile.toFile().setReadable(false));
    Config config = Config.emptyBuilder().fromFileNoThrow(confFile).build();
    config.setLogger(log);
    assertThat(logProvider).containsMessages("Unable to load config file [%s]");
}
Also used : Path(java.nio.file.Path) Log(org.neo4j.logging.Log) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DisabledForRoot(org.neo4j.test.extension.DisabledForRoot)

Example 2 with DisabledForRoot

use of org.neo4j.test.extension.DisabledForRoot in project neo4j by neo4j.

the class DumperTest method shouldGiveAClearErrorMessageIfTheArchivesParentDirectoryIsNotWritable.

@Test
@DisabledOnOs(OS.WINDOWS)
@DisabledForRoot
void shouldGiveAClearErrorMessageIfTheArchivesParentDirectoryIsNotWritable() throws IOException {
    Path directory = testDirectory.directory("a-directory");
    Path archive = testDirectory.file("subdir").resolve("the-archive.dump");
    Files.createDirectories(archive.getParent());
    try (Closeable ignored = TestUtils.withPermissions(archive.getParent(), emptySet())) {
        AccessDeniedException exception = assertThrows(AccessDeniedException.class, () -> new Dumper().dump(directory, directory, archive, GZIP, Predicates.alwaysFalse()));
        assertEquals(archive.getParent().toString(), exception.getMessage());
    }
}
Also used : Path(java.nio.file.Path) AccessDeniedException(java.nio.file.AccessDeniedException) Closeable(java.io.Closeable) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) Test(org.junit.jupiter.api.Test) DisabledForRoot(org.neo4j.test.extension.DisabledForRoot)

Example 3 with DisabledForRoot

use of org.neo4j.test.extension.DisabledForRoot in project neo4j by neo4j.

the class DumpCommandIT method shouldReportAHelpfulErrorIfWeDontHaveWritePermissionsForLock.

@Test
@DisabledOnOs(OS.WINDOWS)
@DisabledForRoot
void shouldReportAHelpfulErrorIfWeDontHaveWritePermissionsForLock() throws Exception {
    DatabaseLayout databaseLayout = DatabaseLayout.ofFlat(databaseDirectory);
    try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction()) {
        Path file = databaseLayout.databaseLockFile();
        try (Closeable ignored = withPermissions(file, emptySet())) {
            CommandFailedException commandFailed = assertThrows(CommandFailedException.class, () -> execute("foo"));
            assertEquals("You do not have permission to dump the database.", commandFailed.getMessage());
        }
    }
}
Also used : Path(java.nio.file.Path) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) Closeable(java.io.Closeable) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) CommandFailedException(org.neo4j.cli.CommandFailedException) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) Test(org.junit.jupiter.api.Test) DisabledForRoot(org.neo4j.test.extension.DisabledForRoot)

Example 4 with DisabledForRoot

use of org.neo4j.test.extension.DisabledForRoot in project neo4j by neo4j.

the class LoaderTest method shouldGiveAClearErrorMessageIfTheTxLogsParentDirectoryIsNotWritable.

@Test
@DisabledOnOs(OS.WINDOWS)
@DisabledForRoot
void shouldGiveAClearErrorMessageIfTheTxLogsParentDirectoryIsNotWritable() throws IOException {
    Path archive = testDirectory.file("the-archive.dump");
    Path txLogsDirectory = testDirectory.directory("subdir", "txLogs");
    Config config = Config.newBuilder().set(neo4j_home, testDirectory.homePath()).set(transaction_logs_root_path, txLogsDirectory.toAbsolutePath()).set(default_database, "destination").build();
    DatabaseLayout databaseLayout = DatabaseLayout.of(config);
    Path txLogsRoot = databaseLayout.getTransactionLogsDirectory().getParent();
    try (Closeable ignored = withPermissions(txLogsRoot, emptySet())) {
        AccessDeniedException exception = assertThrows(AccessDeniedException.class, () -> new Loader().load(archive, databaseLayout));
        assertEquals(txLogsRoot.toString(), exception.getMessage());
    }
}
Also used : Path(java.nio.file.Path) AccessDeniedException(java.nio.file.AccessDeniedException) Config(org.neo4j.configuration.Config) Closeable(java.io.Closeable) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) Test(org.junit.jupiter.api.Test) DisabledForRoot(org.neo4j.test.extension.DisabledForRoot)

Example 5 with DisabledForRoot

use of org.neo4j.test.extension.DisabledForRoot in project neo4j by neo4j.

the class DefaultFileSystemAbstractionTest method shouldFailGracefullyWhenPathCannotBeCreated.

@Test
// Windows doesn't seem to be able to set a directory read only without complex ACLs
@DisabledOnOs(OS.WINDOWS)
@DisabledForRoot
void shouldFailGracefullyWhenPathCannotBeCreated() throws Exception {
    Files.createDirectories(path);
    assertTrue(fsa.fileExists(path));
    Files.setPosixFilePermissions(path, EnumSet.of(PosixFilePermission.OWNER_READ, PosixFilePermission.GROUP_READ, PosixFilePermission.OTHERS_READ));
    path = path.resolve("some_file");
    IOException exception = assertThrows(IOException.class, () -> fsa.mkdirs(path));
    assertFalse(fsa.isDirectory(path));
    String expectedMessage = format(UNABLE_TO_CREATE_DIRECTORY_FORMAT, path);
    assertThat(exception.getMessage()).isEqualTo(expectedMessage);
    Throwable cause = exception.getCause();
    assertThat(cause).isInstanceOf(AccessDeniedException.class);
}
Also used : IOException(java.io.IOException) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) Test(org.junit.jupiter.api.Test) DisabledForRoot(org.neo4j.test.extension.DisabledForRoot)

Aggregations

Test (org.junit.jupiter.api.Test)8 DisabledForRoot (org.neo4j.test.extension.DisabledForRoot)8 Path (java.nio.file.Path)7 DisabledOnOs (org.junit.jupiter.api.condition.DisabledOnOs)5 Closeable (java.io.Closeable)4 AccessDeniedException (java.nio.file.AccessDeniedException)3 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 Config (org.neo4j.configuration.Config)2 IOException (java.io.IOException)1 OpenOption (java.nio.file.OpenOption)1 CommandFailedException (org.neo4j.cli.CommandFailedException)1 DefaultIdGeneratorFactory (org.neo4j.internal.id.DefaultIdGeneratorFactory)1 IdGeneratorFactory (org.neo4j.internal.id.IdGeneratorFactory)1 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)1 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)1 RecordFormats (org.neo4j.kernel.impl.store.format.RecordFormats)1 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)1 Log (org.neo4j.logging.Log)1 LogProvider (org.neo4j.logging.LogProvider)1