Search in sources :

Example 61 with NullSession

use of ch.cyberduck.core.NullSession in project cyberduck by iterate-ch.

the class CryptoBulkFeatureTest method testPreDirectoryId.

@Test
public void testPreDirectoryId() throws Exception {
    final Path vault = new Path("/vault", EnumSet.of(Path.Type.directory));
    final NullSession session = new NullSession(new Host(new TestProtocol())) {

        @Override
        @SuppressWarnings("unchecked")
        public <T> T _getFeature(final Class<T> type) {
            if (type == Directory.class) {
                return (T) new Directory() {

                    @Override
                    public Path mkdir(final Path folder, final TransferStatus status) {
                        return folder;
                    }

                    @Override
                    public Directory withWriter(final Write writer) {
                        return this;
                    }
                };
            }
            return super._getFeature(type);
        }
    };
    final CryptoVault cryptomator = new CryptoVault(vault);
    cryptomator.create(session, null, new VaultCredentials("test"), new DisabledPasswordStore());
    final CryptoBulkFeature<Map<TransferItem, TransferStatus>> bulk = new CryptoBulkFeature<Map<TransferItem, TransferStatus>>(session, new Bulk<Map<TransferItem, TransferStatus>>() {

        @Override
        public Map<TransferItem, TransferStatus> pre(final Transfer.Type type, final Map<TransferItem, TransferStatus> files, final ConnectionCallback callback) {
            return files;
        }

        @Override
        public void post(final Transfer.Type type, final Map<TransferItem, TransferStatus> files, final ConnectionCallback callback) {
        // 
        }

        @Override
        public Bulk<Map<TransferItem, TransferStatus>> withDelete(final Delete delete) {
            return this;
        }
    }, new Delete() {

        @Override
        public void delete(final Map<Path, TransferStatus> files, final PasswordCallback prompt, final Callback callback) {
            throw new UnsupportedOperationException();
        }

        @Override
        public boolean isRecursive() {
            throw new UnsupportedOperationException();
        }
    }, cryptomator);
    final HashMap<TransferItem, TransferStatus> files = new HashMap<>();
    final Path directory = new Path("/vault/directory", EnumSet.of(Path.Type.directory));
    files.put(new TransferItem(directory, new Local("/tmp/vault/directory")), new TransferStatus().exists(false));
    files.put(new TransferItem(new Path(directory, "file1", EnumSet.of(Path.Type.file)), new Local("/tmp/vault/directory/file1")), new TransferStatus().exists(false));
    files.put(new TransferItem(new Path(directory, "file2", EnumSet.of(Path.Type.file)), new Local("/tmp/vault/directory/file2")), new TransferStatus().exists(false));
    final Map<TransferItem, TransferStatus> pre = bulk.pre(Transfer.Type.upload, files, new DisabledConnectionCallback());
    assertEquals(3, pre.size());
    final Path encryptedDirectory = pre.keySet().stream().filter(new Predicate<TransferItem>() {

        @Override
        public boolean test(final TransferItem item) {
            return item.remote.isDirectory();
        }
    }).findFirst().get().remote;
    final String directoryId = encryptedDirectory.attributes().getDirectoryId();
    assertNotNull(directoryId);
    for (TransferItem file : pre.keySet().stream().filter(new Predicate<TransferItem>() {

        @Override
        public boolean test(final TransferItem item) {
            return item.remote.isFile();
        }
    }).collect(Collectors.toSet())) {
        assertEquals(encryptedDirectory, file.remote.getParent());
        assertEquals(directoryId, file.remote.getParent().attributes().getDirectoryId());
    }
}
Also used : Write(ch.cyberduck.core.features.Write) CryptoVault(ch.cyberduck.core.cryptomator.CryptoVault) Delete(ch.cyberduck.core.features.Delete) TestProtocol(ch.cyberduck.core.TestProtocol) HashMap(java.util.HashMap) NullSession(ch.cyberduck.core.NullSession) Predicate(java.util.function.Predicate) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) PasswordCallback(ch.cyberduck.core.PasswordCallback) Directory(ch.cyberduck.core.features.Directory) Path(ch.cyberduck.core.Path) VaultCredentials(ch.cyberduck.core.vault.VaultCredentials) Local(ch.cyberduck.core.Local) Host(ch.cyberduck.core.Host) Bulk(ch.cyberduck.core.features.Bulk) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) PasswordCallback(ch.cyberduck.core.PasswordCallback) ConnectionCallback(ch.cyberduck.core.ConnectionCallback) Transfer(ch.cyberduck.core.transfer.Transfer) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) ConnectionCallback(ch.cyberduck.core.ConnectionCallback) DisabledPasswordStore(ch.cyberduck.core.DisabledPasswordStore) HashMap(java.util.HashMap) Map(java.util.Map) TransferItem(ch.cyberduck.core.transfer.TransferItem) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) Test(org.junit.Test)

Example 62 with NullSession

use of ch.cyberduck.core.NullSession in project cyberduck by iterate-ch.

the class CryptoDirectoryV6ProviderTest method testToEncryptedInvalidPath.

@Test(expected = NotfoundException.class)
public void testToEncryptedInvalidPath() throws Exception {
    final Path home = new Path("/vault", EnumSet.of(Path.Type.directory));
    final CryptoVault vault = new CryptoVault(home);
    final CryptoDirectory provider = new CryptoDirectoryV6Provider(home, vault);
    provider.toEncrypted(new NullSession(new Host(new TestProtocol())), null, new Path("/", EnumSet.of(Path.Type.directory)));
}
Also used : Path(ch.cyberduck.core.Path) CryptoVault(ch.cyberduck.core.cryptomator.CryptoVault) TestProtocol(ch.cyberduck.core.TestProtocol) NullSession(ch.cyberduck.core.NullSession) Host(ch.cyberduck.core.Host) CryptoDirectory(ch.cyberduck.core.cryptomator.CryptoDirectory) Test(org.junit.Test)

Example 63 with NullSession

use of ch.cyberduck.core.NullSession in project cyberduck by iterate-ch.

the class CryptoDirectoryV6ProviderTest method testToEncryptedInvalidArgument.

@Test(expected = NotfoundException.class)
public void testToEncryptedInvalidArgument() throws Exception {
    final Path home = new Path("/vault", EnumSet.of(Path.Type.directory));
    final CryptoVault vault = new CryptoVault(home);
    final CryptoDirectory provider = new CryptoDirectoryV6Provider(home, vault);
    provider.toEncrypted(new NullSession(new Host(new TestProtocol())), null, new Path("/vault/f", EnumSet.of(Path.Type.file)));
}
Also used : Path(ch.cyberduck.core.Path) CryptoVault(ch.cyberduck.core.cryptomator.CryptoVault) TestProtocol(ch.cyberduck.core.TestProtocol) NullSession(ch.cyberduck.core.NullSession) Host(ch.cyberduck.core.Host) CryptoDirectory(ch.cyberduck.core.cryptomator.CryptoDirectory) Test(org.junit.Test)

Example 64 with NullSession

use of ch.cyberduck.core.NullSession in project cyberduck by iterate-ch.

the class CryptoDirectoryV7ProviderTest method testToEncryptedInvalidPath.

@Test(expected = NotfoundException.class)
public void testToEncryptedInvalidPath() throws Exception {
    final Path home = new Path("/vault", EnumSet.of(Path.Type.directory));
    final CryptoVault vault = new CryptoVault(home);
    final CryptoDirectory provider = new CryptoDirectoryV7Provider(home, vault);
    provider.toEncrypted(new NullSession(new Host(new TestProtocol())), null, new Path("/", EnumSet.of(Path.Type.directory)));
}
Also used : Path(ch.cyberduck.core.Path) CryptoVault(ch.cyberduck.core.cryptomator.CryptoVault) TestProtocol(ch.cyberduck.core.TestProtocol) NullSession(ch.cyberduck.core.NullSession) Host(ch.cyberduck.core.Host) CryptoDirectory(ch.cyberduck.core.cryptomator.CryptoDirectory) Test(org.junit.Test)

Example 65 with NullSession

use of ch.cyberduck.core.NullSession in project cyberduck by iterate-ch.

the class AbstractEditorTest method testOpen.

@Test
public void testOpen() throws Exception {
    final AtomicBoolean t = new AtomicBoolean();
    final Host host = new Host(new TestProtocol());
    final NullSession session = new NullTransferSession(host) {

        @Override
        @SuppressWarnings("unchecked")
        public <T> T _getFeature(final Class<T> type) {
            if (type.equals(Read.class)) {
                return (T) new Read() {

                    @Override
                    public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) {
                        t.set(true);
                        return IOUtils.toInputStream("content", Charset.defaultCharset());
                    }

                    @Override
                    public boolean offset(final Path file) {
                        assertEquals(new Path("/f", EnumSet.of(Path.Type.file)), file);
                        return false;
                    }
                };
            }
            return super._getFeature(type);
        }
    };
    final AtomicBoolean e = new AtomicBoolean();
    final Path file = new Path("/f", EnumSet.of(Path.Type.file));
    final Local temporary = new DefaultTemporaryFileService().create(host.getUuid(), file);
    file.attributes().setSize("content".getBytes().length);
    final AbstractEditor editor = new AbstractEditor(host, file, new DisabledProgressListener()) {

        @Override
        public void close() {
        // 
        }

        @Override
        protected void edit(final Application editor, final Path file, final Local temporary, final FileWatcherListener listener) {
            e.set(true);
        }

        @Override
        protected void watch(final Application application, final Local temporary, final FileWatcherListener listener, final ApplicationQuitCallback quit) {
        // 
        }
    };
    editor.open(new Application("com.editor"), new DisabledApplicationQuitCallback(), new DisabledFileWatcherListener()).run(session);
    assertTrue(t.get());
    assertTrue(e.get());
    assertTrue(temporary.exists());
}
Also used : Path(ch.cyberduck.core.Path) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) TestProtocol(ch.cyberduck.core.TestProtocol) DefaultTemporaryFileService(ch.cyberduck.core.local.DefaultTemporaryFileService) InputStream(java.io.InputStream) NullSession(ch.cyberduck.core.NullSession) Local(ch.cyberduck.core.Local) Host(ch.cyberduck.core.Host) NullTransferSession(ch.cyberduck.core.NullTransferSession) Read(ch.cyberduck.core.features.Read) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ApplicationQuitCallback(ch.cyberduck.core.local.ApplicationQuitCallback) DisabledApplicationQuitCallback(ch.cyberduck.core.local.DisabledApplicationQuitCallback) FileWatcherListener(ch.cyberduck.core.local.FileWatcherListener) DisabledFileWatcherListener(ch.cyberduck.core.local.DisabledFileWatcherListener) DisabledFileWatcherListener(ch.cyberduck.core.local.DisabledFileWatcherListener) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) ConnectionCallback(ch.cyberduck.core.ConnectionCallback) Application(ch.cyberduck.core.local.Application) DisabledApplicationQuitCallback(ch.cyberduck.core.local.DisabledApplicationQuitCallback) Test(org.junit.Test)

Aggregations

Host (ch.cyberduck.core.Host)128 NullSession (ch.cyberduck.core.NullSession)128 TestProtocol (ch.cyberduck.core.TestProtocol)128 Test (org.junit.Test)127 Path (ch.cyberduck.core.Path)118 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)81 DisabledProgressListener (ch.cyberduck.core.DisabledProgressListener)69 NullLocal (ch.cyberduck.core.NullLocal)59 ListProgressListener (ch.cyberduck.core.ListProgressListener)40 AttributedList (ch.cyberduck.core.AttributedList)32 DisabledUploadSymlinkResolver (ch.cyberduck.core.transfer.symlink.DisabledUploadSymlinkResolver)27 Local (ch.cyberduck.core.Local)24 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)24 ConnectionCallback (ch.cyberduck.core.ConnectionCallback)19 DisabledPasswordCallback (ch.cyberduck.core.DisabledPasswordCallback)18 DisabledPasswordStore (ch.cyberduck.core.DisabledPasswordStore)17 Session (ch.cyberduck.core.Session)17 VaultCredentials (ch.cyberduck.core.vault.VaultCredentials)17 HashMap (java.util.HashMap)14 LocalAttributes (ch.cyberduck.core.LocalAttributes)13