Search in sources :

Example 1 with S3AccessControlListFeature

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());
}
Also used : Delete(ch.cyberduck.core.features.Delete) S3AttributesFinderFeature(ch.cyberduck.core.s3.S3AttributesFinderFeature) S3TouchFeature(ch.cyberduck.core.s3.S3TouchFeature) CryptoWriteFeature(ch.cyberduck.core.cryptomator.features.CryptoWriteFeature) AttributesFinder(ch.cyberduck.core.features.AttributesFinder) RotatingNonceGenerator(ch.cyberduck.core.cryptomator.random.RotatingNonceGenerator) DefaultVaultRegistry(ch.cyberduck.core.vault.DefaultVaultRegistry) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) FileHeader(org.cryptomator.cryptolib.api.FileHeader) Path(ch.cyberduck.core.Path) S3FindFeature(ch.cyberduck.core.s3.S3FindFeature) VaultCredentials(ch.cyberduck.core.vault.VaultCredentials) StorageObject(org.jets3t.service.model.StorageObject) CryptoVersioningFeature(ch.cyberduck.core.cryptomator.features.CryptoVersioningFeature) S3DefaultDeleteFeature(ch.cyberduck.core.s3.S3DefaultDeleteFeature) PathAttributes(ch.cyberduck.core.PathAttributes) S3VersioningFeature(ch.cyberduck.core.s3.S3VersioningFeature) S3AccessControlListFeature(ch.cyberduck.core.s3.S3AccessControlListFeature) CryptoAttributesFeature(ch.cyberduck.core.cryptomator.features.CryptoAttributesFeature) CryptoFindFeature(ch.cyberduck.core.cryptomator.features.CryptoFindFeature) ByteArrayInputStream(java.io.ByteArrayInputStream) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) S3MultipartWriteFeature(ch.cyberduck.core.s3.S3MultipartWriteFeature) S3WriteFeature(ch.cyberduck.core.s3.S3WriteFeature) DisabledPasswordStore(ch.cyberduck.core.DisabledPasswordStore) DisabledPasswordCallback(ch.cyberduck.core.DisabledPasswordCallback) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) StreamCopier(ch.cyberduck.core.io.StreamCopier) AbstractS3Test(ch.cyberduck.core.s3.AbstractS3Test) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 2 with S3AccessControlListFeature

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();
}
Also used : Path(ch.cyberduck.core.Path) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) S3FindFeature(ch.cyberduck.core.s3.S3FindFeature) SessionPool(ch.cyberduck.core.pool.SessionPool) S3TouchFeature(ch.cyberduck.core.s3.S3TouchFeature) Acl(ch.cyberduck.core.Acl) S3MetadataFeature(ch.cyberduck.core.s3.S3MetadataFeature) S3AccessControlListFeature(ch.cyberduck.core.s3.S3AccessControlListFeature) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) AbstractS3Test(ch.cyberduck.core.s3.AbstractS3Test) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Aggregations

AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)2 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)2 Path (ch.cyberduck.core.Path)2 AbstractS3Test (ch.cyberduck.core.s3.AbstractS3Test)2 S3AccessControlListFeature (ch.cyberduck.core.s3.S3AccessControlListFeature)2 S3FindFeature (ch.cyberduck.core.s3.S3FindFeature)2 S3TouchFeature (ch.cyberduck.core.s3.S3TouchFeature)2 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)2 IntegrationTest (ch.cyberduck.test.IntegrationTest)2 Test (org.junit.Test)2 Acl (ch.cyberduck.core.Acl)1 DisabledConnectionCallback (ch.cyberduck.core.DisabledConnectionCallback)1 DisabledPasswordCallback (ch.cyberduck.core.DisabledPasswordCallback)1 DisabledPasswordStore (ch.cyberduck.core.DisabledPasswordStore)1 DisabledProgressListener (ch.cyberduck.core.DisabledProgressListener)1 PathAttributes (ch.cyberduck.core.PathAttributes)1 CryptoAttributesFeature (ch.cyberduck.core.cryptomator.features.CryptoAttributesFeature)1 CryptoFindFeature (ch.cyberduck.core.cryptomator.features.CryptoFindFeature)1 CryptoVersioningFeature (ch.cyberduck.core.cryptomator.features.CryptoVersioningFeature)1 CryptoWriteFeature (ch.cyberduck.core.cryptomator.features.CryptoWriteFeature)1