mirror of https://github.com/apache/jclouds.git
Prefer Guava Files over FileInputStream
This ensures proper resource handling.
This commit is contained in:
parent
a85b91904f
commit
289197a560
|
@ -19,10 +19,8 @@ package org.jclouds.oauth.v2;
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
import org.jclouds.util.Strings2;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
@ -40,8 +38,8 @@ public class OAuthTestUtils {
|
||||||
try {
|
try {
|
||||||
properties = properties == null ? new Properties() : properties;
|
properties = properties == null ? new Properties() : properties;
|
||||||
properties.put("oauth.identity", "foo");
|
properties.put("oauth.identity", "foo");
|
||||||
properties.put("oauth.credential", Strings2.toStringAndClose(new FileInputStream("src/test/resources/testpk" +
|
properties.put("oauth.credential",
|
||||||
".pem")));
|
Files.asCharSource(new File("src/test/resources/testpk.pem"), Charsets.UTF_8).read());
|
||||||
properties.put("oauth.endpoint", "http://localhost:5000/o/oauth2/token");
|
properties.put("oauth.endpoint", "http://localhost:5000/o/oauth2/token");
|
||||||
properties.put(AUDIENCE, "https://accounts.google.com/o/oauth2/token");
|
properties.put(AUDIENCE, "https://accounts.google.com/o/oauth2/token");
|
||||||
return properties;
|
return properties;
|
||||||
|
|
|
@ -17,11 +17,10 @@
|
||||||
package org.jclouds.oauth.v2.functions;
|
package org.jclouds.oauth.v2.functions;
|
||||||
|
|
||||||
import static com.google.common.base.Suppliers.ofInstance;
|
import static com.google.common.base.Suppliers.ofInstance;
|
||||||
import static org.jclouds.util.Strings2.toStringAndClose;
|
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
import static org.testng.Assert.assertNotNull;
|
import static org.testng.Assert.assertNotNull;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.KeyStoreException;
|
import java.security.KeyStoreException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
@ -29,6 +28,9 @@ import java.security.UnrecoverableKeyException;
|
||||||
import java.security.cert.CertificateException;
|
import java.security.cert.CertificateException;
|
||||||
import java.security.spec.InvalidKeySpecException;
|
import java.security.spec.InvalidKeySpecException;
|
||||||
|
|
||||||
|
import com.google.common.base.Charsets;
|
||||||
|
import com.google.common.io.Files;
|
||||||
|
|
||||||
import org.jclouds.domain.Credentials;
|
import org.jclouds.domain.Credentials;
|
||||||
import org.jclouds.oauth.v2.domain.OAuthCredentials;
|
import org.jclouds.oauth.v2.domain.OAuthCredentials;
|
||||||
import org.jclouds.oauth.v2.functions.OAuthCredentialsSupplier.OAuthCredentialsForCredentials;
|
import org.jclouds.oauth.v2.functions.OAuthCredentialsSupplier.OAuthCredentialsForCredentials;
|
||||||
|
@ -43,7 +45,8 @@ public class OAuthCredentialsFromPKTest {
|
||||||
public static OAuthCredentials loadOAuthCredentials() throws IOException, NoSuchAlgorithmException,
|
public static OAuthCredentials loadOAuthCredentials() throws IOException, NoSuchAlgorithmException,
|
||||||
CertificateException, InvalidKeySpecException {
|
CertificateException, InvalidKeySpecException {
|
||||||
OAuthCredentialsSupplier loader = new OAuthCredentialsSupplier(ofInstance(new Credentials("foo",
|
OAuthCredentialsSupplier loader = new OAuthCredentialsSupplier(ofInstance(new Credentials("foo",
|
||||||
toStringAndClose(new FileInputStream("src/test/resources/testpk.pem")))), new OAuthCredentialsForCredentials("RS256"), "RS256");
|
Files.asCharSource(new File("src/test/resources/testpk.pem"), Charsets.UTF_8).read())),
|
||||||
|
new OAuthCredentialsForCredentials("RS256"), "RS256");
|
||||||
return loader.get();
|
return loader.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue