use of ch.cyberduck.core.s3.S3AccessControlListFeature in project cyberduck by iterate-ch.
the class S3VersioningFeatureTest method testRevert.
@Test
public void testRevert() throws Exception {
final Path bucket = new Path("versioning-test-us-east-1-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
final Path vault = new Path(bucket, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
final CryptoVault cryptomator = new CryptoVault(vault);
cryptomator.create(session, new VaultCredentials("test"), new DisabledPasswordStore(), vaultVersion);
session.withRegistry(new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
final AttributesFinder f = new CryptoAttributesFeature(session, new S3AttributesFinderFeature(session), cryptomator);
final Path test = new CryptoTouchFeature<>(session, new S3TouchFeature(session), new S3WriteFeature(session), cryptomator).touch(new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus());
final PathAttributes initialAttributes = new PathAttributes(test.attributes());
final String initialVersion = test.attributes().getVersionId();
final byte[] content = RandomUtils.nextBytes(32769);
final TransferStatus status = new TransferStatus();
final Write<StorageObject> writer = new CryptoWriteFeature<>(session, new S3MultipartWriteFeature(session), cryptomator);
final FileHeader header = cryptomator.getFileHeaderCryptor().create();
status.setHeader(cryptomator.getFileHeaderCryptor().encryptHeader(header));
status.setNonces(new RotatingNonceGenerator(cryptomator.numberOfChunks(content.length)));
status.setChecksum(writer.checksum(test, status).compute(new ByteArrayInputStream(content), status));
final StatusOutputStream<StorageObject> out = writer.write(test, status, new DisabledConnectionCallback());
assertNotNull(out);
new StreamCopier(status, status).transfer(new ByteArrayInputStream(content), out);
final PathAttributes updated = new CryptoAttributesFeature(session, new S3AttributesFinderFeature(session, true), cryptomator).find(new Path(test).withAttributes(PathAttributes.EMPTY));
assertNotEquals(initialVersion, updated.getVersionId());
assertFalse(updated.getVersions().isEmpty());
assertEquals(1, updated.getVersions().size());
assertEquals(new Path(test).withAttributes(initialAttributes), updated.getVersions().get(0));
assertTrue(new CryptoFindFeature(session, new S3FindFeature(session), cryptomator).find(updated.getVersions().get(0)));
assertEquals(initialVersion, new CryptoAttributesFeature(session, new S3AttributesFinderFeature(session), cryptomator).find(updated.getVersions().get(0)).getVersionId());
new CryptoVersioningFeature(session, new S3VersioningFeature(session, new S3AccessControlListFeature(session)), cryptomator).revert(new Path(test).withAttributes(initialAttributes));
final PathAttributes reverted = new CryptoAttributesFeature(session, new S3AttributesFinderFeature(session, true), cryptomator).find(new Path(test).withAttributes(PathAttributes.EMPTY));
assertNotEquals(initialVersion, reverted.getVersionId());
assertEquals(2, reverted.getVersions().size());
assertEquals(test.attributes().getSize(), reverted.getSize());
assertEquals(content.length, reverted.getVersions().get(0).attributes().getSize());
cryptomator.getFeature(session, Delete.class, new S3DefaultDeleteFeature(session)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.s3.S3AccessControlListFeature in project cyberduck by iterate-ch.
the class MoveWorkerTest method testMoveFile.
@Test
public void testMoveFile() throws Exception {
final Path home = new Path("test-eu-central-1-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
final Path source = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final Path target = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
new S3TouchFeature(session).touch(source, new TransferStatus().withMime("application/cyberduck"));
new S3AccessControlListFeature(session).setPermission(source, new Acl(new Acl.UserAndRole(new Acl.Owner("80b9982b7b08045ee86680cc47f43c84bf439494a89ece22b5330f8a49477cf6"), new Acl.Role(Acl.Role.FULL)), new Acl.UserAndRole(new Acl.GroupUser("http://acs.amazonaws.com/groups/global/AllUsers"), new Acl.Role(Acl.Role.READ))));
assertTrue(new S3FindFeature(session).find(source));
final MoveWorker worker = new MoveWorker(Collections.singletonMap(source, target), new SessionPool.SingleSessionPool(session), PathCache.empty(), new DisabledProgressListener(), new DisabledLoginCallback());
worker.run(session);
assertFalse(new S3FindFeature(session).find(source));
assertTrue(new S3FindFeature(session).find(target));
assertEquals("application/cyberduck", new S3MetadataFeature(session, new S3AccessControlListFeature(session)).getMetadata(target).get("Content-Type"));
assertTrue(new S3AccessControlListFeature(session).getPermission(target).asList().contains(new Acl.UserAndRole(new Acl.Owner("80b9982b7b08045ee86680cc47f43c84bf439494a89ece22b5330f8a49477cf6"), new Acl.Role(Acl.Role.FULL))));
assertTrue(new S3AccessControlListFeature(session).getPermission(target).asList().contains(new Acl.UserAndRole(new Acl.GroupUser(Acl.GroupUser.EVERYONE), new Acl.Role(Acl.Role.READ))));
new DeleteWorker(new DisabledLoginCallback(), Collections.singletonList(target), PathCache.empty(), new DisabledProgressListener()).run(session);
session.close();
}
Aggregations