Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Commit 02e8cbf

Browse files
committed
Merge branch 'hotfix/1.1.2'
2 parents f405e66 + b24073b commit 02e8cbf

File tree

5 files changed

+33
-12
lines changed

5 files changed

+33
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This project provides a first API implementation, little optimized, but "complet
1414
<dependency>
1515
<groupId>com.upplication</groupId>
1616
<artifactId>s3fs</artifactId>
17-
<version>1.1.1</version>
17+
<version>1.1.2</version>
1818
</dependency>
1919
```
2020

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>com.upplication</groupId>
55
<artifactId>s3fs</artifactId>
66
<packaging>jar</packaging>
7-
<version>1.1.1</version>
7+
<version>1.1.2</version>
88
<name>s3fs</name>
99
<description>S3 filesystem provider for Java 7</description>
1010
<url>https://github.com/Upplication/Amazon-S3-FileSystem-NIO2</url>

src/main/java/com/upplication/s3fs/S3FileSystemProvider.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.io.IOException;
2525
import java.io.InputStream;
2626
import java.net.URI;
27+
import java.net.URISyntaxException;
2728
import java.nio.channels.SeekableByteChannel;
2829
import java.nio.file.*;
2930
import java.nio.file.attribute.BasicFileAttributes;
@@ -35,6 +36,7 @@
3536
import java.util.concurrent.ConcurrentMap;
3637

3738
import com.amazonaws.services.s3.AmazonS3;
39+
import com.amazonaws.services.s3.internal.Constants;
3840
import com.amazonaws.services.s3.model.*;
3941
import com.google.common.base.Preconditions;
4042
import com.google.common.collect.ImmutableList;
@@ -130,12 +132,15 @@ private String getFileSystemKey(URI uri) {
130132

131133
/**
132134
* get the file system key represented by: the access key @ endpoint.
133-
* Example: [email protected]
135+
* Example: [email protected]
136+
* If uri host is empty then s3.amazonaws.com are used as host
134137
* @param uri URI with the endpoint
135138
* @param props with the access key property
136139
* @return String
137140
*/
138141
protected String getFileSystemKey(URI uri, Properties props) {
142+
// we don`t use uri.getUserInfo and uri.getHost because secret key and access key have special chars
143+
// and dont return the correct strings
139144
String uriString = uri.toString().replace("s3://", "");
140145
String authority = null;
141146
int authoritySeparator = uriString.indexOf("@");
@@ -150,12 +155,16 @@ protected String getFileSystemKey(URI uri, Properties props) {
150155
if (lastPath > 0){
151156
host = host.substring(0, lastPath);
152157
}
158+
else {
159+
host = Constants.S3_HOSTNAME;
160+
}
153161
return authority + "@" + host;
154162
}
155163
else {
156164
String accessKey = (String) props.get(ACCESS_KEY);
157165

158-
return (accessKey != null ? accessKey+"@" : "" ) + uri.getHost();
166+
return (accessKey != null ? accessKey+"@" : "" ) +
167+
(uri.getHost() != null ? uri.getHost() : Constants.S3_HOSTNAME);
159168
}
160169
}
161170

@@ -255,8 +264,7 @@ public S3FileSystem getFileSystem(URI uri) {
255264
return fileSystems.get(key);
256265
}
257266
else{
258-
throw new FileSystemNotFoundException(
259-
String.format("S3 filesystem not yet created. Use newFileSystem() instead"));
267+
throw new FileSystemNotFoundException("S3 filesystem not yet created. Use newFileSystem() instead");
260268
}
261269
}
262270

src/test/java/com/upplication/s3fs/S3FileSystemProviderTest.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.Set;
3131
import java.util.concurrent.TimeUnit;
3232

33+
import com.amazonaws.services.s3.internal.Constants;
3334
import com.upplication.s3fs.util.*;
3435
import org.junit.After;
3536
import org.junit.Before;
@@ -58,6 +59,18 @@ public void missconfigure() {
5859
s3fsProvider.createFileSystem(S3_GLOBAL_URI, props);
5960
}
6061

62+
@Test
63+
public void newS3FileSystemWithEmptyHostAndUserInfo() throws IOException {
64+
FileSystem s3fs = s3fsProvider.newFileSystem(URI.create("s3:///bucket/file"), ImmutableMap.<String, Object>of());
65+
assertEquals(Constants.S3_HOSTNAME, ((S3FileSystem) s3fs).getKey());
66+
}
67+
68+
@Test
69+
public void newS3FileSystemWithEmptyHost() throws IOException {
70+
FileSystem s3fs = s3fsProvider.newFileSystem(URI.create("s3://access-key:secret-key@/bucket/file"), ImmutableMap.<String, Object>of());
71+
assertEquals("access-key:secret-key@" + Constants.S3_HOSTNAME, ((S3FileSystem) s3fs).getKey());
72+
}
73+
6174
@Test
6275
public void createsAuthenticatedByEnv() {
6376
Map<String, ?> env = buildFakeEnv();
@@ -105,12 +118,12 @@ public void createAuthenticatedBySystemEnvironment() {
105118
doReturn(secretKey).when(s3fsProvider).systemGetEnv(SECRET_KEY);
106119
doCallRealMethod().when(s3fsProvider).overloadPropertiesWithSystemEnv(any(Properties.class), anyString());
107120

108-
s3fsProvider.newFileSystem(S3_GLOBAL_URI, ImmutableMap.<String, Object> of());
121+
s3fsProvider.newFileSystem(S3_GLOBAL_URI, ImmutableMap.<String, Object>of());
109122

110123
verify(s3fsProvider).createFileSystem(eq(S3_GLOBAL_URI), argThat(new ArgumentMatcher<Properties>() {
111124
@Override
112125
public boolean matches(Object argument) {
113-
Properties called = (Properties)argument;
126+
Properties called = (Properties) argument;
114127
assertEquals(accessKey, called.getProperty(ACCESS_KEY));
115128
assertEquals(secretKey, called.getProperty(SECRET_KEY));
116129
return true;
@@ -146,7 +159,7 @@ public void createWithOnlyAccessKey() {
146159
Properties props = new Properties();
147160
props.setProperty(ACCESS_KEY, "better access key");
148161
doReturn(props).when(s3fsProvider).loadAmazonProperties();
149-
s3fsProvider.newFileSystem(S3_GLOBAL_URI, ImmutableMap.<String, Object> of());
162+
s3fsProvider.newFileSystem(S3_GLOBAL_URI, ImmutableMap.<String, Object>of());
150163
}
151164

152165
@Test(expected = IllegalArgumentException.class)
@@ -169,12 +182,12 @@ public void createWithWrongEnv() {
169182
Map<String, Object> env = ImmutableMap.<String, Object> builder().put(ACCESS_KEY, 1234).put(SECRET_KEY, "secret key").build();
170183
FileSystem fileSystem = s3fsProvider.newFileSystem(S3_GLOBAL_URI, env);
171184
assertNotNull(fileSystem);
172-
s3fsProvider.newFileSystem(S3_GLOBAL_URI, ImmutableMap.<String, Object> of());
185+
s3fsProvider.newFileSystem(S3_GLOBAL_URI, ImmutableMap.<String, Object>of());
173186
}
174187

175188
@Test
176189
public void getFileSystem() {
177-
FileSystem fileSystem = s3fsProvider.newFileSystem(S3_GLOBAL_URI, ImmutableMap.<String, Object> of());
190+
FileSystem fileSystem = s3fsProvider.newFileSystem(S3_GLOBAL_URI, ImmutableMap.<String, Object>of());
178191
assertNotNull(fileSystem);
179192
fileSystem = s3fsProvider.getFileSystem(S3_GLOBAL_URI, ImmutableMap.<String, Object> of());
180193
assertNotNull(fileSystem);

src/test/java/com/upplication/s3fs/S3FileSystemTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public void comparables() throws IOException {
219219
assertEquals(1483378423, s3fs1.hashCode());
220220
assertEquals(684416791, s3fs2.hashCode());
221221
assertEquals(182977201, s3fs3.hashCode());
222-
assertEquals(-615984431, s3fs4.hashCode());
222+
assertEquals(1163233038, s3fs4.hashCode());
223223
assertEquals(-498271993, s3fs6.hashCode());
224224
assertEquals(-82123487, s3fs7.hashCode());
225225

0 commit comments

Comments
 (0)