use of org.syncany.plugins.transfer.TransferSettings in project syncany by syncany.
the class SingleFileNoConflictsScenarioTest method testSingleClientLocalBackupAndRestoreNoConflicts.
@Test
public void testSingleClientLocalBackupAndRestoreNoConflicts() throws Exception {
// Setup
TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
TestClient clientA1 = new TestClient("A", testConnection);
// same client!
TestClient clientA2 = new TestClient("A", testConnection);
// Create files and upload
clientA1.createNewFiles();
clientA1.up();
// Download and reconstruct
clientA2.down();
assertFileListEquals(clientA1.getLocalFilesExcludeLockedAndNoRead(), clientA2.getLocalFilesExcludeLockedAndNoRead());
// Cleanup
clientA1.deleteTestData();
clientA2.deleteTestData();
}
use of org.syncany.plugins.transfer.TransferSettings in project syncany by syncany.
the class SymlinkSyncScenarioTest method testSymlinkMultipleUpsAndDowns.
@Test
public void testSymlinkMultipleUpsAndDowns() throws Exception {
if (!EnvironmentUtil.symlinksSupported()) {
// Skip test for Windows, no symlinks there!
return;
}
// Setup
TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
// Run
clientA.createNewFile("symlink-target");
File symlinkFile = clientA.getLocalFile("symlink-name");
// << relative target
FileUtil.createSymlink("symlink-target", symlinkFile);
assertTrue("Symlink should exist at " + symlinkFile, symlinkFile.exists());
clientA.up();
// B down
clientB.down();
assertEquals("Local folder should contain two files (symlink and target!)", 2, clientB.getLocalFilesExcludeLockedAndNoRead().size());
File localSymlinkFile = clientB.getLocalFile("symlink-name");
assertTrue("Local symlink file should exist.", Files.exists(Paths.get(localSymlinkFile.getAbsolutePath()), LinkOption.NOFOLLOW_LINKS));
assertTrue("Local symlink file should be a SYMLINK.", FileUtil.isSymlink(localSymlinkFile));
assertEquals("Local symlink file should point to actual target.", "symlink-target", FileUtil.readSymlinkTarget(localSymlinkFile));
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
}
use of org.syncany.plugins.transfer.TransferSettings in project syncany by syncany.
the class SymlinkSyncScenarioTest method testSymlinkOneUpOneDown.
@Test
public void testSymlinkOneUpOneDown() throws Exception {
if (!EnvironmentUtil.symlinksSupported()) {
// Skip test for Windows, no symlinks there!
return;
}
// Setup
TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
// Run
File symlinkFile = clientA.getLocalFile("symlink-name");
FileUtil.createSymlink("/etc/hosts", symlinkFile);
assertTrue("Symlink should exist at " + symlinkFile, symlinkFile.exists());
UpOperationResult upResult = clientA.up();
StatusOperationResult statusResult = upResult.getStatusResult();
// Test 1: Check result sets for inconsistencies
assertTrue("Status should return changes.", statusResult.getChangeSet().hasChanges());
assertTrue("File should be uploaded.", upResult.getChangeSet().hasChanges());
// Test 2: Check database for inconsistencies
SqlDatabase database = clientA.loadLocalDatabase();
assertEquals("File should be uploaded.", 1, database.getFileList("symlink-name", null, false, false, false, null).size());
assertNotNull("There should be a new database version, because file should not have been added.", database.getLastDatabaseVersionHeader());
// Test 3: Check file system for inconsistencies
File repoPath = new File(((LocalTransferSettings) testConnection).getPath() + "/databases");
String[] repoFileList = repoPath.list(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.startsWith("database-");
}
});
assertEquals("Repository should contain only ONE database file, not multichunks.", 1, repoFileList.length);
// B down
clientB.down();
assertEquals("Local folder should contain one file (link!)", 1, clientB.getLocalFilesExcludeLockedAndNoRead().size());
File localSymlinkFile = clientB.getLocalFile("symlink-name");
assertTrue("Local symlink file should exist.", localSymlinkFile.exists());
assertTrue("Local symlink file should be a SYMLINK.", FileUtil.isSymlink(localSymlinkFile));
assertEquals("Local symlink file should point to actual target.", "/etc/hosts", FileUtil.readSymlinkTarget(localSymlinkFile));
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
}
use of org.syncany.plugins.transfer.TransferSettings in project syncany by syncany.
the class SymlinkSyncScenarioTest method testSymlinkSyncToNonExistingFolder.
@Test
public void testSymlinkSyncToNonExistingFolder() throws Exception {
if (!EnvironmentUtil.symlinksSupported()) {
// Skip test for Windows, no symlinks there!
return;
}
// Setup
TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
TestClient clientB = new TestClient("B", testConnection);
// A
clientA.createNewFolder("folder1");
clientA.up();
// B
clientB.down();
assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
// A
File symlinkFile = clientA.getLocalFile("folder1/symlink-name");
FileUtil.createSymlink("/does/not/exist", symlinkFile);
clientA.up();
// B
clientB.deleteFile("folder1");
clientB.down();
assertTrue(FileUtil.exists(clientB.getLocalFile("folder1/symlink-name")));
assertFileListEquals(clientA.getLocalFilesExcludeLockedAndNoRead(), clientB.getLocalFilesExcludeLockedAndNoRead());
// Tear down
clientA.deleteTestData();
clientB.deleteTestData();
}
use of org.syncany.plugins.transfer.TransferSettings in project syncany by syncany.
the class ConnectOperation method createConfigTOFromLink.
private ConfigTO createConfigTOFromLink(ConfigTO configTO, String link, String masterPassword) throws StorageException, CipherException {
logger.log(Level.INFO, "Creating config TO from link: " + link + " ...");
ApplicationLink applicationLink = new ApplicationLink(link);
try {
if (applicationLink.isEncrypted()) {
// Non-interactive mode
if (masterPassword != null) {
logger.log(Level.INFO, " - Link is encrypted. Password available.");
SaltedSecretKey masterKey = createMasterKeyFromPassword(masterPassword, applicationLink.getMasterKeySalt());
TransferSettings transferSettings = applicationLink.createTransferSettings(masterKey);
configTO.setMasterKey(masterKey);
configTO.setTransferSettings(transferSettings);
} else {
logger.log(Level.INFO, " - Link is encrypted. Asking for password.");
boolean retryPassword = true;
while (retryPassword) {
// Ask password
masterPassword = getOrAskPassword();
// Generate master key
SaltedSecretKey masterKey = createMasterKeyFromPassword(masterPassword, applicationLink.getMasterKeySalt());
// Decrypt config
try {
TransferSettings transferSettings = applicationLink.createTransferSettings(masterKey);
configTO.setMasterKey(masterKey);
configTO.setTransferSettings(transferSettings);
retryPassword = false;
} catch (CipherException e) {
retryPassword = askRetryPassword();
}
}
}
if (configTO.getTransferSettings() == null) {
throw new CipherException("Unable to decrypt link.");
}
} else {
logger.log(Level.INFO, " - Link is NOT encrypted. No password needed.");
TransferSettings transferSettings = applicationLink.createTransferSettings();
configTO.setTransferSettings(transferSettings);
}
} catch (Exception e) {
throw new StorageException("Unable to extract connection settings: " + e.getMessage(), e);
}
return configTO;
}
Aggregations