Search in sources :

Example 21 with RepoTO

use of org.syncany.config.to.RepoTO in project syncany by syncany.

the class TestConfigUtil method createTestInitOperationOptions.

public static InitOperationOptions createTestInitOperationOptions(String machineName) throws Exception {
    File tempLocalDir = TestFileUtil.createTempDirectoryInSystemTemp(createUniqueName("client-" + machineName, machineName));
    File tempRepoDir = TestFileUtil.createTempDirectoryInSystemTemp(createUniqueName("repo", machineName));
    tempLocalDir.mkdirs();
    tempRepoDir.mkdirs();
    RepoTO repoTO = createRepoTO();
    // Create config TO
    ConfigTO configTO = new ConfigTO();
    configTO.setMachineName(machineName + Math.abs(new Random().nextInt()));
    // Get Masterkey
    SaltedSecretKey masterKey = getMasterKey();
    configTO.setMasterKey(masterKey);
    // Generic connection settings wont work anymore, because they are plugin dependent now.
    LocalTransferSettings transferSettings = Plugins.get("local", TransferPlugin.class).createEmptySettings();
    transferSettings.setPath(tempRepoDir);
    configTO.setTransferSettings(transferSettings);
    InitOperationOptions operationOptions = new InitOperationOptions();
    operationOptions.setLocalDir(tempLocalDir);
    operationOptions.setConfigTO(configTO);
    operationOptions.setRepoTO(repoTO);
    operationOptions.setEncryptionEnabled(cryptoEnabled);
    operationOptions.setCipherSpecs(CipherSpecs.getDefaultCipherSpecs());
    operationOptions.setPassword(cryptoEnabled ? "some password" : null);
    return operationOptions;
}
Also used : SaltedSecretKey(org.syncany.crypto.SaltedSecretKey) TransferPlugin(org.syncany.plugins.transfer.TransferPlugin) UnreliableLocalTransferPlugin(org.syncany.plugins.unreliable_local.UnreliableLocalTransferPlugin) Random(java.util.Random) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) UnreliableLocalTransferSettings(org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings) InitOperationOptions(org.syncany.operations.init.InitOperationOptions) ConfigTO(org.syncany.config.to.ConfigTO) RepoTO(org.syncany.config.to.RepoTO) File(java.io.File)

Example 22 with RepoTO

use of org.syncany.config.to.RepoTO in project syncany by syncany.

the class ConfigTest method testConfigCipherTransformersCipherFound.

@Test
@SuppressWarnings("serial")
public void testConfigCipherTransformersCipherFound() throws Exception {
    // Setup
    File localDir = new File("/some/folder");
    ConfigTO configTO = new ConfigTO();
    RepoTO repoTO = new RepoTO();
    // <<< valid
    configTO.setMachineName("somevalidmachinename");
    // <<< valid
    repoTO.setChunkerTO(TestConfigUtil.createFixedChunkerTO());
    // <<< valid
    repoTO.setMultiChunker(TestConfigUtil.createZipMultiChunkerTO());
    // <<< valid
    repoTO.setRepoId(new byte[] { 0x01, 0x02 });
    // <<< valid
    configTO.setMasterKey(createDummyMasterKey());
    // Set invalid transformer
    TransformerTO invalidTransformerTO = new TransformerTO();
    invalidTransformerTO.setType("cipher");
    invalidTransformerTO.setSettings(new HashMap<String, String>() {

        {
            put("cipherspecs", "1,2");
        }
    });
    List<TransformerTO> transformers = new ArrayList<TransformerTO>();
    transformers.add(invalidTransformerTO);
    // <<< valid
    repoTO.setTransformers(transformers);
    // Run!
    Config config = new Config(localDir, configTO, repoTO);
    // Test
    assertNotNull(config.getChunker());
    assertNotNull(config.getMultiChunker());
    assertNotNull(config.getTransformer());
    assertEquals("CipherTransformer", config.getTransformer().getClass().getSimpleName());
}
Also used : TransformerTO(org.syncany.config.to.RepoTO.TransformerTO) ArrayList(java.util.ArrayList) ConfigTO(org.syncany.config.to.ConfigTO) RepoTO(org.syncany.config.to.RepoTO) File(java.io.File) Test(org.junit.Test)

Example 23 with RepoTO

use of org.syncany.config.to.RepoTO in project syncany by syncany.

the class ConfigTest method testConfigChunkerNull.

@Test
@Ignore
public // TODO [low] ChunkerTO is not used yet; so no test for it.
void testConfigChunkerNull() throws Exception {
    // Setup
    File localDir = new File("/some/folder");
    ConfigTO configTO = new ConfigTO();
    RepoTO repoTO = new RepoTO();
    // <<< valid
    configTO.setMachineName("somevalidmachinename");
    // <<< valid
    repoTO.setMultiChunker(TestConfigUtil.createZipMultiChunkerTO());
    // <<< valid
    repoTO.setRepoId(new byte[] { 0x01, 0x02 });
    // <<< valid
    repoTO.setTransformers(null);
    // <<< INVALID !!
    repoTO.setChunkerTO(null);
    // Run!
    try {
        new Config(localDir, configTO, repoTO);
        fail("Config should not been have initialized.");
    } catch (ConfigException e) {
        TestAssertUtil.assertErrorStackTraceContains("No multichunker", e);
    }
}
Also used : ConfigTO(org.syncany.config.to.ConfigTO) RepoTO(org.syncany.config.to.RepoTO) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 24 with RepoTO

use of org.syncany.config.to.RepoTO in project syncany by syncany.

the class ConfigTest method testConfigCipherTransformersCipherNotFound.

@Test
@SuppressWarnings("serial")
public void testConfigCipherTransformersCipherNotFound() throws Exception {
    // Setup
    File localDir = new File("/some/folder");
    ConfigTO configTO = new ConfigTO();
    RepoTO repoTO = new RepoTO();
    // <<< valid
    configTO.setMachineName("somevalidmachinename");
    // <<< valid
    repoTO.setChunkerTO(TestConfigUtil.createFixedChunkerTO());
    // <<< valid
    repoTO.setMultiChunker(TestConfigUtil.createZipMultiChunkerTO());
    // <<< valid
    repoTO.setRepoId(new byte[] { 0x01, 0x02 });
    // <<< valid
    configTO.setMasterKey(createDummyMasterKey());
    // Set invalid transformer
    TransformerTO invalidTransformerTO = new TransformerTO();
    invalidTransformerTO.setType("cipher");
    invalidTransformerTO.setSettings(new HashMap<String, String>() {

        {
            // <<<< INVALID !
            put("cipherspecs", "1,INVALIDXXXX");
        }
    });
    List<TransformerTO> transformers = new ArrayList<TransformerTO>();
    transformers.add(invalidTransformerTO);
    repoTO.setTransformers(transformers);
    // Run!
    try {
        new Config(localDir, configTO, repoTO);
        fail("Transformer should NOT have been able to initialize.");
    } catch (ConfigException e) {
        TestAssertUtil.assertErrorStackTraceContains("INVALIDXXXX", e);
    }
}
Also used : TransformerTO(org.syncany.config.to.RepoTO.TransformerTO) ArrayList(java.util.ArrayList) ConfigTO(org.syncany.config.to.ConfigTO) RepoTO(org.syncany.config.to.RepoTO) File(java.io.File) Test(org.junit.Test)

Example 25 with RepoTO

use of org.syncany.config.to.RepoTO in project syncany by syncany.

the class ConfigTest method testConfigInitLocalDirNull.

@Test(expected = ConfigException.class)
public void testConfigInitLocalDirNull() throws Exception {
    File localDir = null;
    ConfigTO configTO = new ConfigTO();
    RepoTO repoTO = new RepoTO();
    new Config(localDir, configTO, repoTO);
}
Also used : ConfigTO(org.syncany.config.to.ConfigTO) RepoTO(org.syncany.config.to.RepoTO) File(java.io.File) Test(org.junit.Test)

Aggregations

RepoTO (org.syncany.config.to.RepoTO)30 ConfigTO (org.syncany.config.to.ConfigTO)29 File (java.io.File)26 Test (org.junit.Test)24 Config (org.syncany.config.Config)14 TransformerTO (org.syncany.config.to.RepoTO.TransformerTO)7 ArrayList (java.util.ArrayList)6 ConfigException (org.syncany.config.ConfigException)6 Ignore (org.junit.Ignore)2 UserConfig (org.syncany.config.UserConfig)2 SaltedSecretKey (org.syncany.crypto.SaltedSecretKey)2 InitOperationOptions (org.syncany.operations.init.InitOperationOptions)2 LocalTransferSettings (org.syncany.plugins.local.LocalTransferSettings)2 TransferPlugin (org.syncany.plugins.transfer.TransferPlugin)2 UnreliableLocalTransferSettings (org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings)2 HashMap (java.util.HashMap)1 Random (java.util.Random)1 OptionParser (joptsimple.OptionParser)1 OptionSet (joptsimple.OptionSet)1 Persister (org.simpleframework.xml.core.Persister)1