use of org.syncany.operations.init.InitOperationOptions in project syncany by syncany.
the class ConnectOperationTest method testConnectOperationWithLink.
@Test
public void testConnectOperationWithLink() throws Exception {
// A.init()
InitOperationOptions initOperationOptionsA = TestConfigUtil.createTestInitOperationOptions("A");
InitOperation initOperationA = new InitOperation(initOperationOptionsA, null);
InitOperationResult initOperationResultA = initOperationA.execute();
String connectLinkA = initOperationResultA.getGenLinkResult().getShareLink();
assertNotNull(connectLinkA);
// B.connect()
File localDirB = TestFileUtil.createTempDirectoryInSystemTemp(TestConfigUtil.createUniqueName("clientB", initOperationOptionsA));
File localConnectDirB = new File(localDirB, Config.DIR_APPLICATION);
ConfigTO connectionConfigToB = initOperationOptionsA.getConfigTO();
connectionConfigToB.setMachineName("clientB" + Math.abs(new Random().nextInt()));
connectionConfigToB.setMasterKey(null);
ConnectOperationOptions connectOperationOptionsB = new ConnectOperationOptions();
connectOperationOptionsB.setStrategy(ConnectOptionsStrategy.CONNECTION_LINK);
connectOperationOptionsB.setConnectLink(connectLinkA);
connectOperationOptionsB.setConfigTO(connectionConfigToB);
connectOperationOptionsB.setPassword(initOperationOptionsA.getPassword());
connectOperationOptionsB.setLocalDir(localDirB);
ConnectOperation connectOperationB = new ConnectOperation(connectOperationOptionsB, null);
ConnectOperationResult connectOperationResultB = connectOperationB.execute();
assertEquals(ConnectResultCode.OK, connectOperationResultB.getResultCode());
assertTrue(new File(localConnectDirB, Config.DIR_DATABASE).exists());
assertTrue(new File(localConnectDirB, Config.DIR_CACHE).exists());
assertTrue(new File(localConnectDirB, Config.FILE_CONFIG).exists());
assertTrue(new File(localConnectDirB, Config.DIR_LOG).exists());
assertTrue(new File(localConnectDirB, Config.FILE_REPO).exists());
assertEquals(new File(localConnectDirB, Config.FILE_MASTER).exists(), TestConfigUtil.getCrypto());
File repoDir = ((LocalTransferSettings) initOperationOptionsA.getConfigTO().getTransferSettings()).getPath();
// Tear down
TestFileUtil.deleteDirectory(repoDir);
TestFileUtil.deleteDirectory(localConnectDirB);
TestFileUtil.deleteDirectory(initOperationOptionsA.getLocalDir());
TestFileUtil.deleteDirectory(connectOperationOptionsB.getLocalDir());
}
use of org.syncany.operations.init.InitOperationOptions in project syncany by syncany.
the class ConnectOperationTest method testConnectOperationSuccess.
@Test
public void testConnectOperationSuccess() throws Exception {
// A.init()
InitOperationOptions initOperationOptionsA = TestConfigUtil.createTestInitOperationOptions("A");
InitOperation initOperationA = new InitOperation(initOperationOptionsA, null);
InitOperationResult initOperationResultA = initOperationA.execute();
String connectLinkA = initOperationResultA.getGenLinkResult().getShareLink();
assertNotNull(connectLinkA);
// B.connect()
File localDirB = TestFileUtil.createTempDirectoryInSystemTemp(TestConfigUtil.createUniqueName("clientB", initOperationOptionsA));
File localConnectDirB = new File(localDirB, Config.DIR_APPLICATION);
ConfigTO connectionConfigToB = initOperationOptionsA.getConfigTO();
connectionConfigToB.setMachineName("clientB" + Math.abs(new Random().nextInt()));
connectionConfigToB.setMasterKey(null);
ConnectOperationOptions connectOperationOptionsB = new ConnectOperationOptions();
connectOperationOptionsB.setStrategy(ConnectOptionsStrategy.CONNECTION_TO);
connectOperationOptionsB.setConfigTO(connectionConfigToB);
connectOperationOptionsB.setPassword(initOperationOptionsA.getPassword());
connectOperationOptionsB.setLocalDir(localDirB);
ConnectOperation connectOperationB = new ConnectOperation(connectOperationOptionsB, null);
ConnectOperationResult connectOperationResultB = connectOperationB.execute();
assertEquals(ConnectResultCode.OK, connectOperationResultB.getResultCode());
assertTrue(new File(localConnectDirB, Config.DIR_DATABASE).exists());
assertTrue(new File(localConnectDirB, Config.DIR_CACHE).exists());
assertTrue(new File(localConnectDirB, Config.FILE_CONFIG).exists());
assertTrue(new File(localConnectDirB, Config.DIR_LOG).exists());
assertTrue(new File(localConnectDirB, Config.FILE_REPO).exists());
assertEquals(new File(localConnectDirB, Config.FILE_MASTER).exists(), TestConfigUtil.getCrypto());
File repoDir = ((LocalTransferSettings) initOperationOptionsA.getConfigTO().getTransferSettings()).getPath();
// Tear down
TestFileUtil.deleteDirectory(repoDir);
TestFileUtil.deleteDirectory(localConnectDirB);
TestFileUtil.deleteDirectory(initOperationOptionsA.getLocalDir());
TestFileUtil.deleteDirectory(connectOperationOptionsB.getLocalDir());
}
use of org.syncany.operations.init.InitOperationOptions 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;
}
use of org.syncany.operations.init.InitOperationOptions in project syncany by syncany.
the class InitCommand method parseOptions.
@Override
public InitOperationOptions parseOptions(String[] operationArguments) throws Exception {
InitOperationOptions operationOptions = new InitOperationOptions();
OptionParser parser = new OptionParser();
OptionSpec<Void> optionNoCreateTarget = parser.acceptsAll(asList("T", "no-create-target"));
OptionSpec<Void> optionAdvanced = parser.acceptsAll(asList("a", "advanced"));
OptionSpec<Void> optionNoCompression = parser.acceptsAll(asList("G", "no-compression"));
OptionSpec<Void> optionNoEncryption = parser.acceptsAll(asList("E", "no-encryption"));
OptionSpec<String> optionPlugin = parser.acceptsAll(asList("P", "plugin")).withRequiredArg();
OptionSpec<String> optionPluginOpts = parser.acceptsAll(asList("o", "plugin-option")).withRequiredArg();
OptionSpec<Void> optionAddDaemon = parser.acceptsAll(asList("n", "add-daemon"));
OptionSpec<Void> optionShortUrl = parser.acceptsAll(asList("s", "short"));
OptionSpec<Void> optionHeadlessMode = parser.acceptsAll(asList("l", "headless"));
OptionSpec<String> optionPassword = parser.acceptsAll(asList("password")).withRequiredArg();
OptionSet options = parser.parse(operationArguments);
// Set interactivity mode
isInteractive = !options.has(optionPlugin);
// Set headless mode
isHeadless = options.has(optionHeadlessMode);
// Ask or set transfer settings
TransferSettings transferSettings = createTransferSettingsFromOptions(options, optionPlugin, optionPluginOpts);
// Some misc settings
boolean createTargetPath = !options.has(optionNoCreateTarget);
boolean advancedModeEnabled = options.has(optionAdvanced);
boolean encryptionEnabled = !options.has(optionNoEncryption);
boolean compressionEnabled = !options.has(optionNoCompression);
// Cipher specs: --no-encryption, --advanced
List<CipherSpec> cipherSpecs = getCipherSpecs(encryptionEnabled, advancedModeEnabled);
// Compression: --no-compression
// DefaultRepoTOFactory also creates default chunkers
RepoTOFactory repoTOFactory = new DefaultRepoTOFactory(compressionEnabled, cipherSpecs);
// Genlink options: --short
GenlinkOperationOptions genlinkOptions = new GenlinkOperationOptions();
genlinkOptions.setShortUrl(options.has(optionShortUrl));
// Set repo password
String password = validateAndGetPassword(options, optionNoEncryption, optionPassword);
operationOptions.setPassword(password);
// Create configTO and repoTO
ConfigTO configTO = createConfigTO(transferSettings);
RepoTO repoTO = repoTOFactory.createRepoTO();
operationOptions.setLocalDir(localDir);
operationOptions.setConfigTO(configTO);
operationOptions.setRepoTO(repoTO);
operationOptions.setCreateTarget(createTargetPath);
operationOptions.setEncryptionEnabled(encryptionEnabled);
operationOptions.setCipherSpecs(cipherSpecs);
operationOptions.setDaemon(options.has(optionAddDaemon));
operationOptions.setGenlinkOptions(genlinkOptions);
return operationOptions;
}
use of org.syncany.operations.init.InitOperationOptions in project syncany by syncany.
the class TransferSettingsTest method testRestore.
@Test
public void testRestore() throws Exception {
final String fooTest = "foo-test";
final String bazTest = "baz";
final int numberTest = 1234;
final DummyTransferSettings ts = new DummyTransferSettings();
final LocalTransferSettings lts = new LocalTransferSettings();
final InitOperationOptions initOperationOptions = TestConfigUtil.createTestInitOperationOptions("syncanytest");
final ConfigTO conf = initOperationOptions.getConfigTO();
File repoDir = ((LocalTransferSettings) initOperationOptions.getConfigTO().getTransferSettings()).getPath();
File localDir = initOperationOptions.getLocalDir();
conf.setTransferSettings(ts);
ts.foo = fooTest;
ts.baz = bazTest;
ts.number = numberTest;
lts.setPath(File.createTempFile("aaa", "bbb"));
ts.subsettings = lts;
assertTrue(ts.isValid());
Serializer serializer = new Persister();
serializer.write(conf, tmpFile);
System.out.println(new String(Files.readAllBytes(Paths.get(tmpFile.toURI()))));
ConfigTO confRestored = ConfigTO.load(tmpFile);
TransferPlugin plugin = Plugins.get(confRestored.getTransferSettings().getType(), TransferPlugin.class);
assertNotNull(plugin);
TransferSettings tsRestored = confRestored.getTransferSettings();
assertNotNull(tsRestored);
DummyTransferManager transferManager = plugin.createTransferManager(tsRestored, config);
assertNotNull(transferManager);
// Tear down
FileUtils.deleteDirectory(localDir);
FileUtils.deleteDirectory(repoDir);
}
Aggregations