-
-
Notifications
You must be signed in to change notification settings - Fork 278
/
S3CopyFeatureTest.java
118 lines (107 loc) · 8.31 KB
/
S3CopyFeatureTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package ch.cyberduck.core.s3;
/*
* Copyright (c) 2002-2013 David Kocher. All rights reserved.
* http://cyberduck.ch/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* Bug fixes, suggestions and comments should be sent to feedback@cyberduck.ch
*/
import ch.cyberduck.core.AsciiRandomStringService;
import ch.cyberduck.core.DisabledConnectionCallback;
import ch.cyberduck.core.DisabledLoginCallback;
import ch.cyberduck.core.Path;
import ch.cyberduck.core.features.Delete;
import ch.cyberduck.core.io.DisabledStreamListener;
import ch.cyberduck.core.transfer.TransferStatus;
import ch.cyberduck.test.IntegrationTest;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import java.util.Collections;
import java.util.EnumSet;
import static org.junit.Assert.*;
@Category(IntegrationTest.class)
public class S3CopyFeatureTest extends AbstractS3Test {
@Test
public void testCopyFileZeroLength() throws Exception {
final Path container = new Path("test-eu-central-1-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
final Path test = new Path(container, new AsciiRandomStringService().random(), EnumSet.of(Path.Type.file));
test.attributes().setSize(0L);
new S3TouchFeature(session, new S3AccessControlListFeature(session)).touch(test, new TransferStatus());
final Path copy = new Path(container, new AsciiRandomStringService().random(), EnumSet.of(Path.Type.file));
new S3CopyFeature(session, new S3AccessControlListFeature(session)).copy(test, copy, new TransferStatus(), new DisabledConnectionCallback(), new DisabledStreamListener());
assertTrue(new S3FindFeature(session, new S3AccessControlListFeature(session)).find(test));
assertNull(copy.attributes().getVersionId());
new S3DefaultDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
assertTrue(new S3FindFeature(session, new S3AccessControlListFeature(session)).find(copy));
;
new S3DefaultDeleteFeature(session).delete(Collections.singletonList(copy), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
@Test
public void testCopyFile() throws Exception {
final Path container = new Path("test-eu-central-1-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
final TransferStatus status = new TransferStatus();
status.setMetadata(Collections.singletonMap("cyberduck", "m"));
final Path test = new S3TouchFeature(session, new S3AccessControlListFeature(session)).touch(new Path(container, new AsciiRandomStringService().random(), EnumSet.of(Path.Type.file)), status);
final Path copy = new S3CopyFeature(session, new S3AccessControlListFeature(session)).copy(test,
new Path(container, new AsciiRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus(), new DisabledConnectionCallback(), new DisabledStreamListener());
assertTrue(new S3FindFeature(session, new S3AccessControlListFeature(session)).find(test));
assertNull(copy.attributes().getVersionId());
assertEquals("m", new S3MetadataFeature(session, new S3AccessControlListFeature(session)).getMetadata(copy).get("cyberduck"));
new S3DefaultDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
assertTrue(new S3FindFeature(session, new S3AccessControlListFeature(session)).find(copy));
new S3DefaultDeleteFeature(session).delete(Collections.singletonList(copy), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
@Test
public void testCopyFileToBucketWithOwnerEnforced() throws Exception {
final Path bucket = new Path("test-eu-central-1-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
final TransferStatus status = new TransferStatus();
final Path test = new S3TouchFeature(session, new S3AccessControlListFeature(session)).touch(new Path(bucket, new AsciiRandomStringService().random(), EnumSet.of(Path.Type.file)), status);
final Path copy = new S3CopyFeature(session, new S3AccessControlListFeature(session)).copy(test,
new Path(new Path("test-eu-central-1-cyberduck-ownerenforced", EnumSet.of(Path.Type.directory, Path.Type.volume)), new AsciiRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus(), new DisabledConnectionCallback(), new DisabledStreamListener());
assertTrue(new S3FindFeature(session, new S3AccessControlListFeature(session)).find(test));
new S3DefaultDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
assertTrue(new S3FindFeature(session, new S3AccessControlListFeature(session)).find(copy));
new S3DefaultDeleteFeature(session).delete(Collections.singletonList(copy), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
@Test
public void testCopyFileVersionedBucket() throws Exception {
final Path container = new Path("versioning-test-eu-central-1-cyberduck", EnumSet.of(Path.Type.volume, Path.Type.directory));
final TransferStatus status = new TransferStatus();
status.setMetadata(Collections.singletonMap("cyberduck", "m"));
final Path test = new S3TouchFeature(session, new S3AccessControlListFeature(session)).touch(new Path(container, new AsciiRandomStringService().random(), EnumSet.of(Path.Type.file)), status);
assertNotNull(test.attributes().getVersionId());
final Path copy = new S3CopyFeature(session, new S3AccessControlListFeature(session)).copy(test,
new Path(container, new AsciiRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus(), new DisabledConnectionCallback(), new DisabledStreamListener());
assertTrue(new S3FindFeature(session, new S3AccessControlListFeature(session)).find(test));
assertNotNull(copy.attributes().getVersionId());
assertNotEquals("", copy.attributes().getVersionId());
assertNotEquals(test.attributes().getVersionId(), copy.attributes().getVersionId());
assertEquals("m", new S3MetadataFeature(session, new S3AccessControlListFeature(session)).getMetadata(copy).get("cyberduck"));
new S3DefaultDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
assertTrue(new S3FindFeature(session, new S3AccessControlListFeature(session)).find(copy));
new S3DefaultDeleteFeature(session).delete(Collections.singletonList(copy), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
@Test
public void testCopyFileVirtualHostBucket() throws Exception {
final TransferStatus status = new TransferStatus();
status.setMetadata(Collections.singletonMap("cyberduck", "m"));
final S3AccessControlListFeature acl = new S3AccessControlListFeature(virtualhost);
final Path test = new S3TouchFeature(virtualhost, acl).touch(new Path(new AsciiRandomStringService().random(), EnumSet.of(Path.Type.file)), status);
final Path copy = new S3CopyFeature(virtualhost, acl).copy(test,
new Path(new AsciiRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus(), new DisabledConnectionCallback(), new DisabledStreamListener());
assertTrue(new S3FindFeature(virtualhost, acl).find(test));
assertEquals("m", new S3MetadataFeature(virtualhost, acl).getMetadata(copy).get("cyberduck"));
new S3DefaultDeleteFeature(virtualhost).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
assertTrue(new S3FindFeature(virtualhost, acl).find(copy));
new S3DefaultDeleteFeature(virtualhost).delete(Collections.singletonList(copy), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
}