Search in sources :

Example 1 with ConfigException

use of org.syncany.config.ConfigException in project syncany by syncany.

the class ConfigTO method save.

public void save(File file) throws ConfigException {
    try {
        Registry registry = new Registry();
        Strategy strategy = new RegistryStrategy(registry);
        registry.bind(SaltedSecretKey.class, new SaltedSecretKeyConverter());
        registry.bind(String.class, new EncryptedTransferSettingsConverter(transferSettings.getClass()));
        new Persister(strategy).write(this, file);
    } catch (Exception e) {
        throw new ConfigException("Cannot write config to file " + file, e);
    }
}
Also used : SaltedSecretKeyConverter(org.syncany.crypto.SaltedSecretKeyConverter) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) Strategy(org.simpleframework.xml.strategy.Strategy) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) ConfigException(org.syncany.config.ConfigException) Registry(org.simpleframework.xml.convert.Registry) Persister(org.simpleframework.xml.core.Persister) EncryptedTransferSettingsConverter(org.syncany.plugins.transfer.EncryptedTransferSettingsConverter) ConfigException(org.syncany.config.ConfigException)

Example 2 with ConfigException

use of org.syncany.config.ConfigException in project syncany by syncany.

the class RepoTO method save.

public void save(File file, List<CipherSpec> cipherSpecs, SaltedSecretKey masterKey) throws ConfigException {
    try {
        ByteArrayOutputStream plaintextRepoOutputStream = new ByteArrayOutputStream();
        Serializer serializer = new Persister();
        serializer.write(this, plaintextRepoOutputStream);
        CipherUtil.encrypt(new ByteArrayInputStream(plaintextRepoOutputStream.toByteArray()), new FileOutputStream(file), cipherSpecs, masterKey);
    } catch (Exception e) {
        throw new ConfigException("Cannot write repoTO (encrypted) to file " + file, e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FileOutputStream(java.io.FileOutputStream) ConfigException(org.syncany.config.ConfigException) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) Persister(org.simpleframework.xml.core.Persister) ConfigException(org.syncany.config.ConfigException) Serializer(org.simpleframework.xml.Serializer)

Example 3 with ConfigException

use of org.syncany.config.ConfigException in project syncany by syncany.

the class ConfigTest method testConfigCipherTransformersInvalidType.

@Test
public void testConfigCipherTransformersInvalidType() 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 });
    // Set invalid transformer
    TransformerTO invalidTransformerTO = new TransformerTO();
    invalidTransformerTO.setType("invalid-typeXXX");
    invalidTransformerTO.setSettings(new HashMap<String, String>());
    List<TransformerTO> transformers = new ArrayList<TransformerTO>();
    transformers.add(invalidTransformerTO);
    // <<< INVALID !
    repoTO.setTransformers(transformers);
    // Run!
    try {
        new Config(localDir, configTO, repoTO);
        fail("Transformer should NOT have been found.");
    } catch (ConfigException e) {
        TestAssertUtil.assertErrorStackTraceContains("invalid-typeXXX", e);
    }
}
Also used : TransformerTO(org.syncany.config.to.RepoTO.TransformerTO) Config(org.syncany.config.Config) ArrayList(java.util.ArrayList) ConfigException(org.syncany.config.ConfigException) ConfigTO(org.syncany.config.to.ConfigTO) RepoTO(org.syncany.config.to.RepoTO) File(java.io.File) Test(org.junit.Test)

Example 4 with ConfigException

use of org.syncany.config.ConfigException 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) Config(org.syncany.config.Config) ArrayList(java.util.ArrayList) ConfigException(org.syncany.config.ConfigException) ConfigTO(org.syncany.config.to.ConfigTO) RepoTO(org.syncany.config.to.RepoTO) File(java.io.File) Test(org.junit.Test)

Example 5 with ConfigException

use of org.syncany.config.ConfigException in project syncany by syncany.

the class ConfigTest method testConfigMachineNameInvalidNull.

@Test
public void testConfigMachineNameInvalidNull() throws Exception {
    File localDir = new File("/some/folder");
    ConfigTO configTO = new ConfigTO();
    RepoTO repoTO = new RepoTO();
    // <<< Invalid
    configTO.setMachineName(null);
    // Run!
    try {
        new Config(localDir, configTO, repoTO);
        fail("Machine name should not have been accepted.");
    } catch (ConfigException e) {
        TestAssertUtil.assertErrorStackTraceContains("Machine name", e);
    }
}
Also used : Config(org.syncany.config.Config) ConfigException(org.syncany.config.ConfigException) ConfigTO(org.syncany.config.to.ConfigTO) RepoTO(org.syncany.config.to.RepoTO) File(java.io.File) Test(org.junit.Test)

Aggregations

ConfigException (org.syncany.config.ConfigException)10 File (java.io.File)7 Config (org.syncany.config.Config)7 Test (org.junit.Test)6 ConfigTO (org.syncany.config.to.ConfigTO)6 RepoTO (org.syncany.config.to.RepoTO)6 Persister (org.simpleframework.xml.core.Persister)3 ArrayList (java.util.ArrayList)2 Registry (org.simpleframework.xml.convert.Registry)2 RegistryStrategy (org.simpleframework.xml.convert.RegistryStrategy)2 Strategy (org.simpleframework.xml.strategy.Strategy)2 TransformerTO (org.syncany.config.to.RepoTO.TransformerTO)2 SaltedSecretKeyConverter (org.syncany.crypto.SaltedSecretKeyConverter)2 EncryptedTransferSettingsConverter (org.syncany.plugins.transfer.EncryptedTransferSettingsConverter)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileOutputStream (java.io.FileOutputStream)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)1 Ignore (org.junit.Ignore)1