Merge pull request #64 in ITERATE/cyberduck from feature/windows/9074 to master
[cyberduck.git] / test / ch / cyberduck / core / s3 / S3AccessControlListFeatureTest.java
blobae62ef95a60eb8a4ca1c9c7ee046a9a22a71c089
1 package ch.cyberduck.core.s3;
3 /*
4 * Copyright (c) 2002-2013 David Kocher. All rights reserved.
5 * http://cyberduck.ch/
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.*;
41 /**
42 * @version $Id$
44 public class S3AccessControlListFeatureTest extends AbstractTestCase {
46 @Test
47 public void testReadContainer() throws Exception {
48 final S3Session session = new S3Session(
49 new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(),
50 new Credentials(
51 properties.getProperty("s3.key"), properties.getProperty("s3.secret")
52 )));
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)
60 ));
61 assertTrue(acl.get(new Acl.GroupUser("http://acs.amazonaws.com/groups/s3/LogDelivery")).contains(
62 new Acl.Role("READ_ACP")
63 ));
64 assertTrue(acl.containsKey(new Acl.CanonicalUser("80b9982b7b08045ee86680cc47f43c84bf439494a89ece22b5330f8a49477cf6")));
65 assertTrue(acl.get(new Acl.CanonicalUser("80b9982b7b08045ee86680cc47f43c84bf439494a89ece22b5330f8a49477cf6")).contains(
66 new Acl.Role(Acl.Role.FULL)
67 ));
68 session.close();
71 @Test
72 public void testReadKey() throws Exception {
73 final S3Session session = new S3Session(
74 new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(),
75 new Credentials(
76 properties.getProperty("s3.key"), properties.getProperty("s3.secret")
77 )));
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)
85 ));
86 assertTrue(acl.containsKey(new Acl.CanonicalUser("80b9982b7b08045ee86680cc47f43c84bf439494a89ece22b5330f8a49477cf6")));
87 assertTrue(acl.get(new Acl.CanonicalUser("80b9982b7b08045ee86680cc47f43c84bf439494a89ece22b5330f8a49477cf6")).contains(
88 new Acl.Role(Acl.Role.FULL)
89 ));
90 session.close();
93 @Test
94 public void testWrite() throws Exception {
95 final S3Session session = new S3Session(
96 new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(),
97 new Credentials(
98 properties.getProperty("s3.key"), properties.getProperty("s3.secret")
99 )));
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() {
121 @Override
122 public void delete(final Path file) {
125 session.close();
128 @Test
129 public void testReadWithDelimiter() throws Exception {
130 final S3Session session = new S3Session(
131 new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(),
132 new Credentials(
133 properties.getProperty("s3.key"), properties.getProperty("s3.secret")
134 )));
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() {
144 @Override
145 public void delete(final Path file) {
148 session.close();
151 @Test
152 public void testReadDirectoryPlaceholder() throws Exception {
153 final S3Session session = new S3Session(
154 new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(),
155 new Credentials(
156 properties.getProperty("s3.key"), properties.getProperty("s3.secret")
157 )));
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() {
166 @Override
167 public void delete(final Path file) {
170 session.close();
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(),
177 new Credentials(
178 properties.getProperty("s3.key"), properties.getProperty("s3.secret")
179 )));
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(),
192 new Credentials(
193 properties.getProperty("s3.key"), properties.getProperty("s3.secret")
194 )));
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);
203 @Test
204 public void testRoles() throws Exception {
205 final S3Session session = new S3Session(
206 new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(),
207 new Credentials(
208 properties.getProperty("s3.key"), properties.getProperty("s3.secret")
209 )));
210 final S3AccessControlListFeature f = new S3AccessControlListFeature(session);
211 assertTrue(f.getAvailableAclUsers().contains(new Acl.CanonicalUser()));
212 assertTrue(f.getAvailableAclUsers().contains(new Acl.EmailUser()));