Skip to content

Commit

Permalink
Revert "fix node id file permission checks (#4428)"
Browse files Browse the repository at this point in the history
This reverts commit b0b7b9b.
  • Loading branch information
bernd committed Dec 20, 2017
1 parent a35c9a9 commit 93191df
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 67 deletions.
9 changes: 3 additions & 6 deletions graylog2-server/src/main/java/org/graylog2/Configuration.java
Expand Up @@ -353,20 +353,17 @@ public void validate(String name, String path) throws ValidationException {
if (!file.isFile()) {
b.append("a file");
}
final boolean readable = file.canRead();
final boolean writable = file.canWrite();
if (!readable) {
if (!file.canRead()) {
if (b.length() > 0) {
b.append(", ");
}
b.append("readable");
}
final boolean empty = file.length() == 0;
if (!writable && readable && empty) {
if (!file.canWrite()) {
if (b.length() > 0) {
b.append(", ");
}
b.append("writable, but it is empty");
b.append("writable");
}
if (b.length() == 0) {
// all good
Expand Down
61 changes: 0 additions & 61 deletions graylog2-server/src/test/java/org/graylog2/ConfigurationTest.java
Expand Up @@ -26,19 +26,11 @@
import org.junit.Test;
import org.junit.rules.ExpectedException;

import java.io.IOException;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.PosixFilePermissions;
import java.util.HashMap;
import java.util.Map;

import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING;
import static java.nio.file.StandardOpenOption.WRITE;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.util.Files.newTemporaryFile;

public class ConfigurationTest {
@Rule
Expand Down Expand Up @@ -228,57 +220,4 @@ public void testWebInterfaceListeningOnWildcardOnSamePortAsRestApi() throws Vali
Configuration configuration = new Configuration();
new JadConfig(new InMemoryRepository(validProperties), configuration).process();
}

public void testNodeIdFilePermissions() throws IOException, ValidationException {
final Path nonEmptyNodeIdPath = newTemporaryFile().toPath();
final Path emptyNodeIdPath = newTemporaryFile().toPath();
try {
// create a node-id file and write some id
Files.write(nonEmptyNodeIdPath, "test-node-id".getBytes(StandardCharsets.UTF_8), WRITE, TRUNCATE_EXISTING);
assertThat(nonEmptyNodeIdPath.toFile().length()).isGreaterThan(0);

// make sure this file isn't accidentally present
final Path missingNodeIdPath = newTemporaryFile().toPath();
assertThat(missingNodeIdPath.toFile().delete()).isTrue();

// read/write permissions should make the validation pass
assertThat(validateWithPermissions(nonEmptyNodeIdPath, "rw-------")).isTrue();
assertThat(validateWithPermissions(emptyNodeIdPath, "rw-------")).isTrue();

// existing, but not writable is ok if the file is not empty
assertThat(validateWithPermissions(nonEmptyNodeIdPath, "r--------")).isTrue();

// existing, but not writable is not ok if the file is empty
assertThat(validateWithPermissions(emptyNodeIdPath, "r--------")).isFalse();

// existing, but not readable is not ok
assertThat(validateWithPermissions(nonEmptyNodeIdPath, "-w-------")).isFalse();

// missing, but not writable is not ok
assertThat(validateWithPermissions(missingNodeIdPath, "r--------")).isFalse();
} finally {
Files.delete(nonEmptyNodeIdPath);
Files.delete(emptyNodeIdPath);
}
}

/**
* Run the NodeIDFileValidator on a file with the given permissions.
* @param nodeFilePath the path to the node id file, can be missing
* @param permissions the posix permission to set the file to, if it exists, before running the validator
* @return true if the validation was successful, false otherwise
* @throws IOException if any file related problem occurred
*/
private static boolean validateWithPermissions(Path nodeFilePath, String permissions) throws IOException {
try {
final Configuration.NodeIdFileValidator validator = new Configuration.NodeIdFileValidator();
if (nodeFilePath.toFile().exists()) {
Files.setPosixFilePermissions(nodeFilePath, PosixFilePermissions.fromString(permissions));
}
validator.validate("node-id", nodeFilePath.toString());
} catch (ValidationException ve) {
return false;
}
return true;
}
}

0 comments on commit 93191df

Please sign in to comment.