Search in sources :

Example 56 with TransferSettings

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();
}
Also used : TestClient(org.syncany.tests.util.TestClient) TransferSettings(org.syncany.plugins.transfer.TransferSettings) Test(org.junit.Test)

Example 57 with TransferSettings

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();
}
Also used : TestClient(org.syncany.tests.util.TestClient) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TransferSettings(org.syncany.plugins.transfer.TransferSettings) File(java.io.File) Test(org.junit.Test)

Example 58 with TransferSettings

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();
}
Also used : FilenameFilter(java.io.FilenameFilter) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TestClient(org.syncany.tests.util.TestClient) SqlDatabase(org.syncany.database.SqlDatabase) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TransferSettings(org.syncany.plugins.transfer.TransferSettings) File(java.io.File) UpOperationResult(org.syncany.operations.up.UpOperationResult) StatusOperationResult(org.syncany.operations.status.StatusOperationResult) Test(org.junit.Test)

Example 59 with TransferSettings

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();
}
Also used : TestClient(org.syncany.tests.util.TestClient) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TransferSettings(org.syncany.plugins.transfer.TransferSettings) File(java.io.File) Test(org.junit.Test)

Example 60 with TransferSettings

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;
}
Also used : SaltedSecretKey(org.syncany.crypto.SaltedSecretKey) CipherException(org.syncany.crypto.CipherException) TransferSettings(org.syncany.plugins.transfer.TransferSettings) StorageException(org.syncany.plugins.transfer.StorageException) StorageException(org.syncany.plugins.transfer.StorageException) CipherException(org.syncany.crypto.CipherException)

Aggregations

TransferSettings (org.syncany.plugins.transfer.TransferSettings)78 Test (org.junit.Test)67 TestClient (org.syncany.tests.util.TestClient)65 File (java.io.File)20 LocalTransferSettings (org.syncany.plugins.local.LocalTransferSettings)10 TransferPlugin (org.syncany.plugins.transfer.TransferPlugin)7 SqlDatabase (org.syncany.database.SqlDatabase)5 DownOperationResult (org.syncany.operations.down.DownOperationResult)4 StatusOperationResult (org.syncany.operations.status.StatusOperationResult)4 UpOperationOptions (org.syncany.operations.up.UpOperationOptions)4 UpOperationResult (org.syncany.operations.up.UpOperationResult)4 CreateFileTree (org.syncany.tests.integration.scenarios.framework.CreateFileTree)4 IOException (java.io.IOException)3 RandomAccessFile (java.io.RandomAccessFile)3 Path (java.nio.file.Path)3 PosixFilePermission (java.nio.file.attribute.PosixFilePermission)3 Config (org.syncany.config.Config)3 ConfigTO (org.syncany.config.to.ConfigTO)3 PartialFileHistory (org.syncany.database.PartialFileHistory)3 FileHistoryId (org.syncany.database.PartialFileHistory.FileHistoryId)3