|
38 | 38 | import ch.cyberduck.test.TestcontainerTest; |
39 | 39 |
|
40 | 40 | import org.apache.commons.io.IOUtils; |
| 41 | +import org.apache.commons.lang3.RandomUtils; |
41 | 42 | import org.cryptomator.cryptolib.api.UVFMasterkey; |
42 | 43 | import org.jetbrains.annotations.NotNull; |
43 | 44 | import org.junit.AfterClass; |
@@ -157,29 +158,25 @@ public Credentials prompt(final Host bookmark, final String title, final String |
157 | 158 | final Path foo = new Path("/cyberduckbucket/foo.txt", EnumSet.of(AbstractPath.Type.file, AbstractPath.Type.decrypted)); |
158 | 159 | assertTrue(Arrays.toString(list.toArray()), list.contains(foo)); |
159 | 160 | assertTrue(Arrays.toString(list.toArray()), list.contains(new Path("/cyberduckbucket/subdir", EnumSet.of(AbstractPath.Type.directory, AbstractPath.Type.placeholder, AbstractPath.Type.decrypted)))); |
| 161 | + assertEquals("Hello Foo", readFile(storage, foo)); |
| 162 | + } |
| 163 | + { |
| 164 | + final byte[] expected = writeRandomFile(storage, new Path("/cyberduckbucket/alice.txt", EnumSet.of(AbstractPath.Type.file, AbstractPath.Type.decrypted)), 55); |
| 165 | + final AttributedList<Path> list = storage.getFeature(ListService.class).list(home, new DisabledListProgressListener()); |
| 166 | + assertEquals(3, list.size()); |
| 167 | + assertTrue(Arrays.toString(list.toArray()), list.contains(new Path("/cyberduckbucket/foo.txt", EnumSet.of(AbstractPath.Type.file, AbstractPath.Type.decrypted)))); |
| 168 | + assertTrue(Arrays.toString(list.toArray()), list.contains(new Path("/cyberduckbucket/alice.txt", EnumSet.of(AbstractPath.Type.file, AbstractPath.Type.decrypted)))); |
| 169 | + assertTrue(Arrays.toString(list.toArray()), list.contains(new Path("/cyberduckbucket/subdir", EnumSet.of(AbstractPath.Type.directory, AbstractPath.Type.placeholder, AbstractPath.Type.decrypted)))); |
160 | 170 |
|
161 | | - final byte[] buf = new byte[300]; |
162 | | - final TransferStatus status = new TransferStatus(); |
163 | | - try(final InputStream inputStream = storage.getFeature(Read.class).read(foo, status, new DisabledConnectionCallback())) { |
164 | | - int l = inputStream.read(buf); |
165 | | - assertEquals(9, l); |
166 | | - assertEquals("Hello Foo", new String(Arrays.copyOfRange(buf, 0, l))); |
167 | | - } |
| 171 | + assertEquals(new String(expected), readFile(storage, new Path("/cyberduckbucket/alice.txt", EnumSet.of(AbstractPath.Type.file, AbstractPath.Type.decrypted)))); |
168 | 172 | } |
169 | 173 | { |
170 | 174 | final PathAttributes subdir = storage.getFeature(AttributesFinder.class).find(new Path("/cyberduckbucket/subdir", EnumSet.of(AbstractPath.Type.directory, AbstractPath.Type.placeholder, AbstractPath.Type.decrypted))); |
171 | 175 | final AttributedList<Path> list = storage.getFeature(ListService.class).list(new Path("/cyberduckbucket/subdir", EnumSet.of(AbstractPath.Type.directory, AbstractPath.Type.placeholder, AbstractPath.Type.decrypted)).withAttributes(subdir), new DisabledListProgressListener()); |
172 | 176 | assertEquals(1, list.size()); |
173 | 177 | final Path bar = new Path("/cyberduckbucket/subdir/bar.txt", EnumSet.of(AbstractPath.Type.file, AbstractPath.Type.decrypted)); |
174 | 178 | assertTrue(Arrays.toString(list.toArray()), list.contains(bar)); |
175 | | - |
176 | | - final byte[] buf = new byte[300]; |
177 | | - final TransferStatus status = new TransferStatus(); |
178 | | - try(final InputStream inputStream = storage.getFeature(Read.class).read(bar, status, new DisabledConnectionCallback())) { |
179 | | - int l = inputStream.read(buf); |
180 | | - assertEquals(9, l); |
181 | | - assertEquals("Hello Bar", new String(Arrays.copyOfRange(buf, 0, l))); |
182 | | - } |
| 179 | + assertEquals("Hello Bar", readFile(storage, bar)); |
183 | 180 | } |
184 | 181 | } |
185 | 182 | finally { |
@@ -217,4 +214,24 @@ public Credentials prompt(final Host bookmark, final String username, final Stri |
217 | 214 | new DisabledCancelCallback()); |
218 | 215 | return storage; |
219 | 216 | } |
| 217 | + |
| 218 | + private static byte @NotNull [] writeRandomFile(final Session<?> session, final Path file, int size) throws BackgroundException, IOException { |
| 219 | + final byte[] content = RandomUtils.nextBytes(size); |
| 220 | + final TransferStatus transferStatus = new TransferStatus().withLength(content.length); |
| 221 | + transferStatus.setChecksum(session.getFeature(Write.class).checksum(file, transferStatus).compute(new ByteArrayInputStream(content), transferStatus)); |
| 222 | + session.getFeature(Bulk.class).pre(Transfer.Type.upload, Collections.singletonMap(new TransferItem(file), transferStatus), new DisabledConnectionCallback()); |
| 223 | + final StatusOutputStream<?> out = session.getFeature(Write.class).write(file, transferStatus, new DisabledConnectionCallback()); |
| 224 | + IOUtils.copyLarge(new ByteArrayInputStream(content), out); |
| 225 | + out.close(); |
| 226 | + return content; |
| 227 | + } |
| 228 | + |
| 229 | + private static String readFile(final S3Session storage, final Path foo) throws IOException, BackgroundException { |
| 230 | + final byte[] buf = new byte[300]; |
| 231 | + final TransferStatus status = new TransferStatus(); |
| 232 | + try(final InputStream inputStream = storage.getFeature(Read.class).read(foo, status, new DisabledConnectionCallback())) { |
| 233 | + int l = inputStream.read(buf); |
| 234 | + return new String(Arrays.copyOfRange(buf, 0, l)); |
| 235 | + } |
| 236 | + } |
220 | 237 | } |
0 commit comments