use of java.nio.file.attribute.PosixFilePermission in project elasticsearch by elastic.
the class InstallPluginCommandTests method testPlatformBinPermissions.
public void testPlatformBinPermissions() throws Exception {
assumeTrue("posix filesystem", isPosix);
Tuple<Path, Environment> env = createEnv(fs, temp);
Path pluginDir = createPluginDir(temp);
Path platformDir = pluginDir.resolve("platform");
Path platformNameDir = platformDir.resolve("linux-x86_64");
Path platformBinDir = platformNameDir.resolve("bin");
Files.createDirectories(platformBinDir);
Path programFile = Files.createFile(platformBinDir.resolve("someprogram"));
// a file created with Files.createFile() should not have execute permissions
Set<PosixFilePermission> sourcePerms = Files.getPosixFilePermissions(programFile);
assertFalse(sourcePerms.contains(PosixFilePermission.OWNER_EXECUTE));
assertFalse(sourcePerms.contains(PosixFilePermission.GROUP_EXECUTE));
assertFalse(sourcePerms.contains(PosixFilePermission.OTHERS_EXECUTE));
String pluginZip = createPlugin("fake", pluginDir);
installPlugin(pluginZip, env.v1());
assertPlugin("fake", pluginDir, env.v2());
// check that the installed program has execute permissions, even though the one added to the plugin didn't
Path installedPlatformBinDir = env.v2().pluginsFile().resolve("fake").resolve("platform").resolve("linux-x86_64").resolve("bin");
assertTrue(Files.isDirectory(installedPlatformBinDir));
Path installedProgramFile = installedPlatformBinDir.resolve("someprogram");
assertTrue(Files.isRegularFile(installedProgramFile));
Set<PosixFilePermission> installedPerms = Files.getPosixFilePermissions(installedProgramFile);
assertTrue(installedPerms.contains(PosixFilePermission.OWNER_EXECUTE));
assertTrue(installedPerms.contains(PosixFilePermission.GROUP_EXECUTE));
assertTrue(installedPerms.contains(PosixFilePermission.OTHERS_EXECUTE));
}
use of java.nio.file.attribute.PosixFilePermission in project elasticsearch by elastic.
the class InstallPluginCommandTests method testBinPermissions.
public void testBinPermissions() throws Exception {
assumeTrue("posix filesystem", isPosix);
Tuple<Path, Environment> env = createEnv(fs, temp);
Path pluginDir = createPluginDir(temp);
Path binDir = pluginDir.resolve("bin");
Files.createDirectory(binDir);
Files.createFile(binDir.resolve("somescript"));
String pluginZip = createPlugin("fake", pluginDir);
try (PosixPermissionsResetter binAttrs = new PosixPermissionsResetter(env.v2().binFile())) {
Set<PosixFilePermission> perms = binAttrs.getCopyPermissions();
// make sure at least one execute perm is missing, so we know we forced it during installation
perms.remove(PosixFilePermission.GROUP_EXECUTE);
binAttrs.setPermissions(perms);
installPlugin(pluginZip, env.v1());
assertPlugin("fake", pluginDir, env.v2());
}
}
use of java.nio.file.attribute.PosixFilePermission in project elasticsearch by elastic.
the class SpawnerNoBootstrapTests method createControllerProgram.
private void createControllerProgram(Path outputFile) throws IOException {
Path outputDir = outputFile.getParent();
Files.createDirectories(outputDir);
Files.write(outputFile, CONTROLLER_SOURCE.getBytes(StandardCharsets.UTF_8));
Set<PosixFilePermission> perms = new HashSet<>();
perms.add(PosixFilePermission.OWNER_READ);
perms.add(PosixFilePermission.OWNER_WRITE);
perms.add(PosixFilePermission.OWNER_EXECUTE);
perms.add(PosixFilePermission.GROUP_READ);
perms.add(PosixFilePermission.GROUP_EXECUTE);
perms.add(PosixFilePermission.OTHERS_READ);
perms.add(PosixFilePermission.OTHERS_EXECUTE);
Files.setPosixFilePermissions(outputFile, perms);
}
use of java.nio.file.attribute.PosixFilePermission in project buck by facebook.
the class ProjectFilesystemTest method testCreateReadOnlyFileSetsPermissions.
@Test
public void testCreateReadOnlyFileSetsPermissions() throws IOException {
Assume.assumeTrue(FileSystems.getDefault().supportedFileAttributeViews().contains("posix"));
Path path = Paths.get("hello.txt");
ImmutableSet<PosixFilePermission> permissions = ImmutableSet.of(PosixFilePermission.OWNER_READ, PosixFilePermission.GROUP_READ, PosixFilePermission.OTHERS_READ);
filesystem.writeContentsToPath("hello world", path, PosixFilePermissions.asFileAttribute(permissions));
// The umask may restrict the actual permissions on the filesystem:
// https://fburl.com/26569549
// So the best we can do is to check that the actual permissions are a
// strict subset of the expected permissions.
PosixFileAttributes attrs = filesystem.readAttributes(path, PosixFileAttributes.class);
assertTrue(permissions.containsAll(attrs.permissions()));
}
use of java.nio.file.attribute.PosixFilePermission in project che by eclipse.
the class UnixSshScript method protectPrivateKeyFile.
@Override
protected void protectPrivateKeyFile(File sshKey) throws ServerException {
try {
//set permission to -rw-------
Set<PosixFilePermission> permissions = EnumSet.of(OWNER_READ, OWNER_WRITE);
Files.setPosixFilePermissions(sshKey.toPath(), permissions);
} catch (IOException e) {
throw new ServerException("Failed to set file permissions");
}
}
Aggregations