Search in sources :

Example 1 with TransformerTO

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);
    }
}
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 2 with TransformerTO

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);
    }
}
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 3 with TransformerTO

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);
    }
}
Also used : TransformerTO(org.syncany.config.to.RepoTO.TransformerTO) HashMap(java.util.HashMap)

Example 4 with TransformerTO

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;
    }
}
Also used : NoTransformer(org.syncany.chunk.NoTransformer) CipherTransformer(org.syncany.chunk.CipherTransformer) Transformer(org.syncany.chunk.Transformer) NoTransformer(org.syncany.chunk.NoTransformer) TransformerTO(org.syncany.config.to.RepoTO.TransformerTO) CipherTransformer(org.syncany.chunk.CipherTransformer) ArrayList(java.util.ArrayList)

Example 5 with TransformerTO

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;
}
Also used : TransformerTO(org.syncany.config.to.RepoTO.TransformerTO)

Aggregations

TransformerTO (org.syncany.config.to.RepoTO.TransformerTO)9 ArrayList (java.util.ArrayList)5 RepoTO (org.syncany.config.to.RepoTO)4 File (java.io.File)3 Test (org.junit.Test)3 Config (org.syncany.config.Config)3 ConfigTO (org.syncany.config.to.ConfigTO)3 HashMap (java.util.HashMap)2 ConfigException (org.syncany.config.ConfigException)2 CipherTransformer (org.syncany.chunk.CipherTransformer)1 NoTransformer (org.syncany.chunk.NoTransformer)1 Transformer (org.syncany.chunk.Transformer)1 ChunkerTO (org.syncany.config.to.RepoTO.ChunkerTO)1 MultiChunkerTO (org.syncany.config.to.RepoTO.MultiChunkerTO)1 CipherSpec (org.syncany.crypto.CipherSpec)1