1 package ch
.cyberduck
.core
.s3
;
4 * Copyright (c) 2002-2013 David Kocher. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * Bug fixes, suggestions and comments should be sent to feedback@cyberduck.ch
20 import ch
.cyberduck
.core
.AbstractTestCase
;
21 import ch
.cyberduck
.core
.Acl
;
22 import ch
.cyberduck
.core
.Credentials
;
23 import ch
.cyberduck
.core
.DisabledCancelCallback
;
24 import ch
.cyberduck
.core
.DisabledHostKeyCallback
;
25 import ch
.cyberduck
.core
.DisabledLoginCallback
;
26 import ch
.cyberduck
.core
.DisabledPasswordStore
;
27 import ch
.cyberduck
.core
.DisabledTranscriptListener
;
28 import ch
.cyberduck
.core
.Host
;
29 import ch
.cyberduck
.core
.Path
;
30 import ch
.cyberduck
.core
.exception
.NotfoundException
;
31 import ch
.cyberduck
.core
.features
.Delete
;
33 import org
.junit
.Test
;
35 import java
.util
.Collections
;
36 import java
.util
.EnumSet
;
37 import java
.util
.UUID
;
39 import static org
.junit
.Assert
.*;
44 public class S3AccessControlListFeatureTest
extends AbstractTestCase
{
47 public void testReadContainer() throws Exception
{
48 final S3Session session
= new S3Session(
49 new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(),
51 properties
.getProperty("s3.key"), properties
.getProperty("s3.secret")
53 session
.open(new DisabledHostKeyCallback(), new DisabledTranscriptListener());
54 session
.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
55 final Path container
= new Path("test.cyberduck.ch", EnumSet
.of(Path
.Type
.directory
, Path
.Type
.volume
));
56 final Acl acl
= new S3AccessControlListFeature(session
).getPermission(container
);
57 assertTrue(acl
.containsKey(new Acl
.GroupUser("http://acs.amazonaws.com/groups/s3/LogDelivery")));
58 assertTrue(acl
.get(new Acl
.GroupUser("http://acs.amazonaws.com/groups/s3/LogDelivery")).contains(
59 new Acl
.Role(Acl
.Role
.WRITE
)
61 assertTrue(acl
.get(new Acl
.GroupUser("http://acs.amazonaws.com/groups/s3/LogDelivery")).contains(
62 new Acl
.Role("READ_ACP")
64 assertTrue(acl
.containsKey(new Acl
.CanonicalUser("80b9982b7b08045ee86680cc47f43c84bf439494a89ece22b5330f8a49477cf6")));
65 assertTrue(acl
.get(new Acl
.CanonicalUser("80b9982b7b08045ee86680cc47f43c84bf439494a89ece22b5330f8a49477cf6")).contains(
66 new Acl
.Role(Acl
.Role
.FULL
)
72 public void testReadKey() throws Exception
{
73 final S3Session session
= new S3Session(
74 new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(),
76 properties
.getProperty("s3.key"), properties
.getProperty("s3.secret")
78 session
.open(new DisabledHostKeyCallback(), new DisabledTranscriptListener());
79 session
.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
80 final Path container
= new Path("test.cyberduck.ch", EnumSet
.of(Path
.Type
.directory
, Path
.Type
.volume
));
81 final Acl acl
= new S3AccessControlListFeature(session
).getPermission(new Path(container
, "test.txt", EnumSet
.of(Path
.Type
.file
)));
82 assertTrue(acl
.containsKey(new Acl
.GroupUser("http://acs.amazonaws.com/groups/global/AllUsers")));
83 assertTrue(acl
.get(new Acl
.GroupUser("http://acs.amazonaws.com/groups/global/AllUsers")).contains(
84 new Acl
.Role(Acl
.Role
.READ
)
86 assertTrue(acl
.containsKey(new Acl
.CanonicalUser("80b9982b7b08045ee86680cc47f43c84bf439494a89ece22b5330f8a49477cf6")));
87 assertTrue(acl
.get(new Acl
.CanonicalUser("80b9982b7b08045ee86680cc47f43c84bf439494a89ece22b5330f8a49477cf6")).contains(
88 new Acl
.Role(Acl
.Role
.FULL
)
94 public void testWrite() throws Exception
{
95 final S3Session session
= new S3Session(
96 new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(),
98 properties
.getProperty("s3.key"), properties
.getProperty("s3.secret")
100 session
.open(new DisabledHostKeyCallback(), new DisabledTranscriptListener());
101 session
.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
102 final Path container
= new Path("test.cyberduck.ch", EnumSet
.of(Path
.Type
.directory
, Path
.Type
.volume
));
103 final Path test
= new Path(container
, UUID
.randomUUID().toString(), EnumSet
.of(Path
.Type
.file
));
104 new S3TouchFeature(session
).touch(test
);
105 final S3AccessControlListFeature f
= new S3AccessControlListFeature(session
);
107 final Acl acl
= new Acl();
108 acl
.addAll(new Acl
.GroupUser(Acl
.GroupUser
.EVERYONE
), new Acl
.Role(Acl
.Role
.READ
));
109 acl
.addAll(new Acl
.GroupUser(Acl
.GroupUser
.AUTHENTICATED
), new Acl
.Role(Acl
.Role
.READ
));
110 f
.setPermission(test
, acl
);
113 final Acl acl
= new Acl();
114 acl
.addAll(new Acl
.GroupUser("http://acs.amazonaws.com/groups/global/AllUsers"), new Acl
.Role(Acl
.Role
.READ
));
115 acl
.addAll(new Acl
.GroupUser("http://acs.amazonaws.com/groups/global/AuthenticatedUsers"), new Acl
.Role(Acl
.Role
.READ
));
116 // Check for owner added with full control
117 acl
.addAll(new Acl
.CanonicalUser("80b9982b7b08045ee86680cc47f43c84bf439494a89ece22b5330f8a49477cf6"), new Acl
.Role(Acl
.Role
.FULL
));
118 assertEquals(acl
, f
.getPermission(test
));
120 new S3DefaultDeleteFeature(session
).delete(Collections
.<Path
>singletonList(test
), new DisabledLoginCallback(), new Delete
.Callback() {
122 public void delete(final Path file
) {
129 public void testReadWithDelimiter() throws Exception
{
130 final S3Session session
= new S3Session(
131 new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(),
133 properties
.getProperty("s3.key"), properties
.getProperty("s3.secret")
135 session
.open(new DisabledHostKeyCallback(), new DisabledTranscriptListener());
136 session
.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
137 final Path container
= new Path("test.cyberduck.ch", EnumSet
.of(Path
.Type
.directory
, Path
.Type
.volume
));
138 final Path placeholder
= new Path(container
, UUID
.randomUUID().toString(), EnumSet
.of(Path
.Type
.directory
, Path
.Type
.placeholder
));
139 final Path test
= new Path(placeholder
, UUID
.randomUUID().toString(), EnumSet
.of(Path
.Type
.file
));
140 new S3TouchFeature(session
).touch(test
);
141 final S3AccessControlListFeature f
= new S3AccessControlListFeature(session
);
142 assertNotNull(f
.getPermission(test
));
143 new S3DefaultDeleteFeature(session
).delete(Collections
.<Path
>singletonList(test
), new DisabledLoginCallback(), new Delete
.Callback() {
145 public void delete(final Path file
) {
152 public void testReadDirectoryPlaceholder() throws Exception
{
153 final S3Session session
= new S3Session(
154 new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(),
156 properties
.getProperty("s3.key"), properties
.getProperty("s3.secret")
158 session
.open(new DisabledHostKeyCallback(), new DisabledTranscriptListener());
159 session
.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
160 final Path container
= new Path("test.cyberduck.ch", EnumSet
.of(Path
.Type
.directory
, Path
.Type
.volume
));
161 final Path placeholder
= new Path(container
, UUID
.randomUUID().toString(), EnumSet
.of(Path
.Type
.directory
, Path
.Type
.placeholder
));
162 new S3DirectoryFeature(session
).mkdir(placeholder
);
163 final S3AccessControlListFeature f
= new S3AccessControlListFeature(session
);
164 assertNotNull(f
.getPermission(placeholder
));
165 new S3DefaultDeleteFeature(session
).delete(Collections
.<Path
>singletonList(placeholder
), new DisabledLoginCallback(), new Delete
.Callback() {
167 public void delete(final Path file
) {
173 @Test(expected
= NotfoundException
.class)
174 public void testReadNotFound() throws Exception
{
175 final S3Session session
= new S3Session(
176 new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(),
178 properties
.getProperty("s3.key"), properties
.getProperty("s3.secret")
180 session
.open(new DisabledHostKeyCallback(), new DisabledTranscriptListener());
181 session
.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
182 final Path container
= new Path("test.cyberduck.ch", EnumSet
.of(Path
.Type
.directory
, Path
.Type
.volume
));
183 final Path test
= new Path(container
, UUID
.randomUUID().toString(), EnumSet
.of(Path
.Type
.file
));
184 final S3AccessControlListFeature f
= new S3AccessControlListFeature(session
);
185 f
.getPermission(test
);
188 @Test(expected
= NotfoundException
.class)
189 public void testWriteNotFound() throws Exception
{
190 final S3Session session
= new S3Session(
191 new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(),
193 properties
.getProperty("s3.key"), properties
.getProperty("s3.secret")
195 session
.open(new DisabledHostKeyCallback(), new DisabledTranscriptListener());
196 session
.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
197 final Path container
= new Path("test.cyberduck.ch", EnumSet
.of(Path
.Type
.directory
, Path
.Type
.volume
));
198 final Path test
= new Path(container
, UUID
.randomUUID().toString(), EnumSet
.of(Path
.Type
.file
));
199 final S3AccessControlListFeature f
= new S3AccessControlListFeature(session
);
200 f
.setPermission(test
, Acl
.EMPTY
);
204 public void testRoles() throws Exception
{
205 final S3Session session
= new S3Session(
206 new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(),
208 properties
.getProperty("s3.key"), properties
.getProperty("s3.secret")
210 final S3AccessControlListFeature f
= new S3AccessControlListFeature(session
);
211 assertTrue(f
.getAvailableAclUsers().contains(new Acl
.CanonicalUser()));
212 assertTrue(f
.getAvailableAclUsers().contains(new Acl
.EmailUser()));