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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations