use of org.syncany.config.to.RepoTO.TransformerTO 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.to.RepoTO.TransformerTO 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.to.RepoTO.TransformerTO in project syncany by syncany.
the class TestConfigUtil method createTransformerTOs.
public static List<TransformerTO> createTransformerTOs() {
if (!cryptoEnabled) {
return null;
} else {
TransformerTO gzipTransformerTO = new TransformerTO();
gzipTransformerTO.setType(GzipTransformer.TYPE);
Map<String, String> cipherTransformerSettings = new HashMap<String, String>();
cipherTransformerSettings.put(CipherTransformer.PROPERTY_CIPHER_SPECS, "1,2");
TransformerTO cipherTransformerTO = new TransformerTO();
cipherTransformerTO.setType(CipherTransformer.TYPE);
cipherTransformerTO.setSettings(cipherTransformerSettings);
return Lists.newArrayList(gzipTransformerTO, cipherTransformerTO);
}
}
use of org.syncany.config.to.RepoTO.TransformerTO in project syncany by syncany.
the class Config method initTransformers.
private void initTransformers(RepoTO repoTO) throws Exception {
if (repoTO.getTransformers() == null || repoTO.getTransformers().size() == 0) {
transformer = new NoTransformer();
} else {
List<TransformerTO> transformerTOs = new ArrayList<TransformerTO>(repoTO.getTransformers());
Transformer lastTransformer = null;
for (int i = transformerTOs.size() - 1; i >= 0; i--) {
TransformerTO transformerTO = transformerTOs.get(i);
Transformer transformer = Transformer.getInstance(transformerTO.getType());
if (transformer == null) {
throw new ConfigException("Cannot find transformer '" + transformerTO.getType() + "'");
}
if (transformer instanceof CipherTransformer) {
// Dirty workaround
transformerTO.getSettings().put(CipherTransformer.PROPERTY_MASTER_KEY, StringUtil.toHex(getMasterKey().getEncoded()));
transformerTO.getSettings().put(CipherTransformer.PROPERTY_MASTER_KEY_SALT, StringUtil.toHex(getMasterKey().getSalt()));
}
transformer.init(transformerTO.getSettings());
if (lastTransformer != null) {
transformer.setNextTransformer(lastTransformer);
}
lastTransformer = transformer;
}
transformer = lastTransformer;
}
}
use of org.syncany.config.to.RepoTO.TransformerTO in project syncany by syncany.
the class DefaultRepoTOFactory method getGzipTransformerTO.
protected TransformerTO getGzipTransformerTO() {
TransformerTO gzipTransformerTO = new TransformerTO();
gzipTransformerTO.setType(GzipTransformer.TYPE);
return gzipTransformerTO;
}
Aggregations