@Test
@Assumption(methods = {"onUnix", "notLocal"})
public void shouldCopyFileToAndFromSudoUserHomeDirectoryOnUnix() throws IOException {
// get handle to file in home dir
final OverthereFile homeDir = connection.getFile(getUnixHomeDirPath());
final OverthereFile fileInHomeDir = homeDir.getFile("file" + System.currentTimeMillis() + ".dat");
assertThat(fileInHomeDir.exists(), equalTo(false));
// write random data to local file
File smallFile = temp.newFile("small.dat");
byte[] contentsWritten = writeRandomBytes(smallFile, 1024);
OverthereFile smallLocalFile = LocalFile.valueOf(smallFile);
// copy local file to file in home dir
smallLocalFile.copyTo(fileInHomeDir);
assertThat(fileInHomeDir.exists(), equalTo(true));
// restrict access to file in home dir
connection.execute(sysoutHandler(), syserrHandler(), CmdLine.build("chmod", "0600", fileInHomeDir.getPath()));
// copy file in home dir to local file
File smallFileReadBack = temp.newFile("small-read-back.dat");
OverthereFile smallLocalFileReadBack = LocalFile.valueOf(smallFileReadBack);
fileInHomeDir.copyTo(smallLocalFileReadBack);
// read new local file
byte[] contentsRead = readFile(smallLocalFileReadBack);
assertThat(contentsRead, equalTo(contentsWritten));