From c29631b8bfea22e5f0b448aab8ffff959ae4de66 Mon Sep 17 00:00:00 2001 From: "David A. Velasco" Date: Mon, 22 Sep 2014 12:23:30 +0200 Subject: [PATCH 01/22] Proxy settings read from System and loaded in host configuration --- .../android/lib/common/OwnCloudClient.java | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/com/owncloud/android/lib/common/OwnCloudClient.java b/src/com/owncloud/android/lib/common/OwnCloudClient.java index c4c4ee38..36282af7 100644 --- a/src/com/owncloud/android/lib/common/OwnCloudClient.java +++ b/src/com/owncloud/android/lib/common/OwnCloudClient.java @@ -30,6 +30,7 @@ import java.io.InputStream; import org.apache.commons.httpclient.Cookie; import org.apache.commons.httpclient.Header; +import org.apache.commons.httpclient.HostConfiguration; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpConnectionManager; import org.apache.commons.httpclient.HttpException; @@ -92,11 +93,33 @@ public class OwnCloudClient extends HttpClient { PARAM_SINGLE_COOKIE_HEADER, // to avoid problems with some web servers PARAM_SINGLE_COOKIE_HEADER_VALUE); + applyProxySettings(); + clearCredentials(); } - public void setCredentials(OwnCloudCredentials credentials) { + private void applyProxySettings() { + String proxyHost = System.getProperty("http.proxyHost"); + String proxyPortSt = System.getProperty("http.proxyPort"); + int proxyPort = 0; + try { + if (proxyPortSt != null && proxyPortSt.length() > 0) { + proxyPort = Integer.parseInt(proxyPortSt); + } + } catch (Exception e) { + // nothing to do here + } + + if (proxyHost != null && proxyHost.length() > 0) { + HostConfiguration hostCfg = getHostConfiguration(); + hostCfg.setProxy(proxyHost, proxyPort); + Log_OC.d(TAG, "Proxy settings: " + proxyHost + ":" + proxyPort); + } + } + + + public void setCredentials(OwnCloudCredentials credentials) { if (credentials != null) { mCredentials = credentials; mCredentials.applyTo(this); From 3d8162d6d71a5d0972cef508f9be9ca8459997c2 Mon Sep 17 00:00:00 2001 From: jabarros Date: Wed, 1 Oct 2014 12:44:02 +0200 Subject: [PATCH 02/22] Increase SYN_READ_TIMEOUT in ReadRemoteFileOperation until 40000 milliseconds --- .../android/lib/resources/files/ReadRemoteFileOperation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/owncloud/android/lib/resources/files/ReadRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/ReadRemoteFileOperation.java index 50a62596..3fb695a4 100644 --- a/src/com/owncloud/android/lib/resources/files/ReadRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/ReadRemoteFileOperation.java @@ -48,7 +48,7 @@ import com.owncloud.android.lib.common.utils.Log_OC; public class ReadRemoteFileOperation extends RemoteOperation { private static final String TAG = ReadRemoteFileOperation.class.getSimpleName(); - private static final int SYNC_READ_TIMEOUT = 10000; + private static final int SYNC_READ_TIMEOUT = 40000; private static final int SYNC_CONNECTION_TIMEOUT = 5000; private String mRemotePath; From 70bcb55f271e4cafbad5a097c9d03cc6c9046baf Mon Sep 17 00:00:00 2001 From: LukeOwncloud Date: Sun, 12 Oct 2014 21:30:39 +0200 Subject: [PATCH 03/22] Update pom.xml update android sdk 19 to revision 4 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2bf1e612..4690784f 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ 1.5.1-SNAPSHOT 1.6 - 4.4.2_r3 + 4.4.2_r4 19 From 6491ae18c3796bf96e39723206dda39f0d308033 Mon Sep 17 00:00:00 2001 From: LukeOwncloud Date: Sun, 12 Oct 2014 21:32:01 +0200 Subject: [PATCH 04/22] Update pom.xml update android sdk 19 to revision 4 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2bf1e612..4690784f 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ 1.5.1-SNAPSHOT 1.6 - 4.4.2_r3 + 4.4.2_r4 19 From 67c41d8ec3bdad77e65280bee9498413b53c8d5f Mon Sep 17 00:00:00 2001 From: jabarros Date: Mon, 20 Oct 2014 10:42:26 +0200 Subject: [PATCH 05/22] Check Travis update --- src/com/owncloud/android/lib/common/utils/Log_OC.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/com/owncloud/android/lib/common/utils/Log_OC.java b/src/com/owncloud/android/lib/common/utils/Log_OC.java index ed2fe6ee..8ed8c52c 100644 --- a/src/com/owncloud/android/lib/common/utils/Log_OC.java +++ b/src/com/owncloud/android/lib/common/utils/Log_OC.java @@ -175,5 +175,4 @@ public class Log_OC { public static String[] getLogFileNames() { return mLogFileNames; } - } From 8764ac8f63323b8739a645a701ed75fdc62339c3 Mon Sep 17 00:00:00 2001 From: jabarros Date: Mon, 20 Oct 2014 11:24:12 +0200 Subject: [PATCH 06/22] Update travis.yml file for building with new Android support in Travis --- .travis.yml | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2920d050..3619bd9d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,16 @@ -language: java +language: android +android: + components: + - build-tools-20.0.0 + - android-19 + - android-17 + - android-14 + - extra-android-support + licenses: + - 'android-sdk-license-5be876d5' + - 'android-sdk-license-598b93a6' jdk: oraclejdk7 before_install: -- sudo apt-get update -qq -- sudo apt-get install -qq libstdc++6:i386 lib32z1 expect -- export LICENSES="android-sdk-license-5be876d5|android-sdk-license-598b93a6" -- curl -3L https://raw.github.com/embarkmobile/android-sdk-installer/version-2/android-sdk-installer - | bash /dev/stdin --install=$COMPONENTS --accept=$LICENSES -- source ~/.android-sdk-installer/env - echo no | android create avd --force -n test -t $ANDROID_TARGET --abi $ANDROID_ABI -c 20M - emulator -avd test -no-skin -no-audio -no-window & - rm pom.xml @@ -25,4 +29,4 @@ env: - secure: aF4U20Xlu/rfrbxCmoJAiGh1doYTAZ10UEDmajuinT+ZGSJLivuqD7DDY/00sI6IXWg+J1vL+7jJm4JSYusHPg38UHZ4q92k6RmZycW2ATUzZnGT54O5FRnY67MfVwgVpIMK9UOL/6NEciBHEjlIOL0wbKQiJB++1YtBZOQLGL4= - secure: N+ECSwNg8v2GsAFJ2y/tCiffauHDpN76zuFI2pDqf0fjmCtJZHu4BH5ArXBHjyHKmgn20a/8eZXcwJaH1HsJ80bo7vDJ2miShjGIQ90hPcdmUiB2XVJcew4f04CtvMDH5o7DRt4ykWArlbPL2rhVag0jotlSidolHBwRFnbDhDY= matrix: - - COMPONENTS=build-tools-20.0.0,android-19,sys-img-armeabi-v7a-android-19 ANDROID_TARGET=android-19 ANDROID_ABI=armeabi-v7a + - ANDROID_TARGET=android-19 ANDROID_ABI=armeabi-v7a From a17dfaed4d35c7aa23af922d88c75931ed75d238 Mon Sep 17 00:00:00 2001 From: "David A. Velasco" Date: Tue, 28 Oct 2014 12:31:23 +0100 Subject: [PATCH 07/22] AdvancedSslSocketFactory needs to implement SecureProtocolSocketFactory so that the connection manager tunnel correctly through the proxy --- .../lib/common/network/AdvancedSslSocketFactory.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/com/owncloud/android/lib/common/network/AdvancedSslSocketFactory.java b/src/com/owncloud/android/lib/common/network/AdvancedSslSocketFactory.java index 7b41282b..9efc85a4 100644 --- a/src/com/owncloud/android/lib/common/network/AdvancedSslSocketFactory.java +++ b/src/com/owncloud/android/lib/common/network/AdvancedSslSocketFactory.java @@ -43,6 +43,7 @@ import javax.net.ssl.SSLSocket; import org.apache.commons.httpclient.ConnectTimeoutException; import org.apache.commons.httpclient.params.HttpConnectionParams; import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; +import org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory; import org.apache.http.conn.ssl.X509HostnameVerifier; import com.owncloud.android.lib.common.utils.Log_OC; @@ -56,7 +57,7 @@ import com.owncloud.android.lib.common.utils.Log_OC; * @author David A. Velasco */ -public class AdvancedSslSocketFactory implements ProtocolSocketFactory { +public class AdvancedSslSocketFactory implements SecureProtocolSocketFactory { private static final String TAG = AdvancedSslSocketFactory.class.getSimpleName(); @@ -287,5 +288,13 @@ public class AdvancedSslSocketFactory implements ProtocolSocketFactory { throw io; } } + + @Override + public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException, + UnknownHostException { + Socket sslSocket = mSslContext.getSocketFactory().createSocket(socket, host, port, autoClose); + verifyPeerIdentity(host, port, sslSocket); + return sslSocket; + } } From 2199a16064befb49adad929b13682dbadbf99a2b Mon Sep 17 00:00:00 2001 From: "David A. Velasco" Date: Tue, 28 Oct 2014 12:34:02 +0100 Subject: [PATCH 08/22] Line wrap at 120 characters --- .../network/AdvancedSslSocketFactory.java | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/com/owncloud/android/lib/common/network/AdvancedSslSocketFactory.java b/src/com/owncloud/android/lib/common/network/AdvancedSslSocketFactory.java index 9efc85a4..4cba5343 100644 --- a/src/com/owncloud/android/lib/common/network/AdvancedSslSocketFactory.java +++ b/src/com/owncloud/android/lib/common/network/AdvancedSslSocketFactory.java @@ -72,7 +72,10 @@ public class AdvancedSslSocketFactory implements SecureProtocolSocketFactory { /** * Constructor for AdvancedSSLProtocolSocketFactory. */ - public AdvancedSslSocketFactory(SSLContext sslContext, AdvancedX509TrustManager trustManager, X509HostnameVerifier hostnameVerifier) { + public AdvancedSslSocketFactory( + SSLContext sslContext, AdvancedX509TrustManager trustManager, X509HostnameVerifier hostnameVerifier + ) { + if (sslContext == null) throw new IllegalArgumentException("AdvancedSslSocketFactory can not be created with a null SSLContext"); if (trustManager == null) @@ -85,7 +88,9 @@ public class AdvancedSslSocketFactory implements SecureProtocolSocketFactory { /** * @see ProtocolSocketFactory#createSocket(java.lang.String,int,java.net.InetAddress,int) */ - public Socket createSocket(String host, int port, InetAddress clientHost, int clientPort) throws IOException, UnknownHostException { + public Socket createSocket(String host, int port, InetAddress clientHost, int clientPort) + throws IOException, UnknownHostException { + Socket socket = mSslContext.getSocketFactory().createSocket(host, port, clientHost, clientPort); verifyPeerIdentity(host, port, socket); return socket; @@ -151,7 +156,8 @@ public class AdvancedSslSocketFactory implements SecureProtocolSocketFactory { final InetAddress localAddress, final int localPort, final HttpConnectionParams params) throws IOException, UnknownHostException, ConnectTimeoutException { - Log_OC.d(TAG, "Creating SSL Socket with remote " + host + ":" + port + ", local " + localAddress + ":" + localPort + ", params: " + params); + Log_OC.d(TAG, "Creating SSL Socket with remote " + host + ":" + port + ", local " + localAddress + ":" + + localPort + ", params: " + params); if (params == null) { throw new IllegalArgumentException("Parameters may not be null"); } @@ -207,13 +213,15 @@ public class AdvancedSslSocketFactory implements SecureProtocolSocketFactory { * * The server certificate is verified first. * - * Then, the host name is compared with the content of the server certificate using the current host name verifier, if any. + * Then, the host name is compared with the content of the server certificate using the current host name verifier, + * if any. * @param socket */ private void verifyPeerIdentity(String host, int port, Socket socket) throws IOException { try { CertificateCombinedException failInHandshake = null; - /// 1. VERIFY THE SERVER CERTIFICATE through the registered TrustManager (that should be an instance of AdvancedX509TrustManager) + /// 1. VERIFY THE SERVER CERTIFICATE through the registered TrustManager + /// (that should be an instance of AdvancedX509TrustManager) try { SSLSocket sock = (SSLSocket) socket; // a new SSLSession instance is created as a "side effect" sock.startHandshake(); @@ -225,7 +233,9 @@ public class AdvancedSslSocketFactory implements SecureProtocolSocketFactory { } else { Throwable cause = e.getCause(); Throwable previousCause = null; - while (cause != null && cause != previousCause && !(cause instanceof CertificateCombinedException)) { + while ( cause != null && + cause != previousCause && + !(cause instanceof CertificateCombinedException)) { previousCause = cause; cause = cause.getCause(); } @@ -264,9 +274,13 @@ public class AdvancedSslSocketFactory implements SecureProtocolSocketFactory { /// 3. Combine the exceptions to throw, if any if (!verifiedHostname) { - SSLPeerUnverifiedException pue = new SSLPeerUnverifiedException("Names in the server certificate do not match to " + host + " in the URL"); + SSLPeerUnverifiedException pue = new SSLPeerUnverifiedException( + "Names in the server certificate do not match to " + host + " in the URL" + ); if (failInHandshake == null) { - failInHandshake = new CertificateCombinedException((X509Certificate) newSession.getPeerCertificates()[0]); + failInHandshake = new CertificateCombinedException( + (X509Certificate) newSession.getPeerCertificates()[0] + ); failInHandshake.setHostInUrl(host); } failInHandshake.setSslPeerUnverifiedException(pue); From 2289015b7744021e8050efd7e0f31af07c86e991 Mon Sep 17 00:00:00 2001 From: jabarros Date: Thu, 30 Oct 2014 14:08:08 +0100 Subject: [PATCH 09/22] Minor change in order to enforce Travis to be launched --- .../android/lib/common/network/AdvancedSslSocketFactory.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/com/owncloud/android/lib/common/network/AdvancedSslSocketFactory.java b/src/com/owncloud/android/lib/common/network/AdvancedSslSocketFactory.java index 4cba5343..b411c02d 100644 --- a/src/com/owncloud/android/lib/common/network/AdvancedSslSocketFactory.java +++ b/src/com/owncloud/android/lib/common/network/AdvancedSslSocketFactory.java @@ -310,5 +310,4 @@ public class AdvancedSslSocketFactory implements SecureProtocolSocketFactory { verifyPeerIdentity(host, port, sslSocket); return sslSocket; } - } From 539ea8f71ac16e087e8abfc034ed743f400d19bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20Kn=C3=B6ller?= Date: Thu, 30 Oct 2014 17:55:22 +0100 Subject: [PATCH 10/22] TLSv1.1 and TLSv1.2 fix --- .../android/lib/common/network/AdvancedSslSocketFactory.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/com/owncloud/android/lib/common/network/AdvancedSslSocketFactory.java b/src/com/owncloud/android/lib/common/network/AdvancedSslSocketFactory.java index 7b41282b..27c6693e 100644 --- a/src/com/owncloud/android/lib/common/network/AdvancedSslSocketFactory.java +++ b/src/com/owncloud/android/lib/common/network/AdvancedSslSocketFactory.java @@ -86,6 +86,7 @@ public class AdvancedSslSocketFactory implements ProtocolSocketFactory { */ public Socket createSocket(String host, int port, InetAddress clientHost, int clientPort) throws IOException, UnknownHostException { Socket socket = mSslContext.getSocketFactory().createSocket(host, port, clientHost, clientPort); + ((SSLSocket) socket).setEnabledProtocols(new String[]{"TLSv1", "TLSv1.1", "TLSv1.2"}); verifyPeerIdentity(host, port, socket); return socket; } @@ -161,6 +162,7 @@ public class AdvancedSslSocketFactory implements ProtocolSocketFactory { SocketFactory socketfactory = mSslContext.getSocketFactory(); Log_OC.d(TAG, " ... with connection timeout " + timeout + " and socket timeout " + params.getSoTimeout()); Socket socket = socketfactory.createSocket(); + ((SSLSocket) socket).setEnabledProtocols(new String[]{"TLSv1", "TLSv1.1", "TLSv1.2"}); SocketAddress localaddr = new InetSocketAddress(localAddress, localPort); SocketAddress remoteaddr = new InetSocketAddress(host, port); socket.setSoTimeout(params.getSoTimeout()); @@ -178,6 +180,7 @@ public class AdvancedSslSocketFactory implements ProtocolSocketFactory { UnknownHostException { Log_OC.d(TAG, "Creating SSL Socket with remote " + host + ":" + port); Socket socket = mSslContext.getSocketFactory().createSocket(host, port); + ((SSLSocket) socket).setEnabledProtocols(new String[]{"TLSv1", "TLSv1.1", "TLSv1.2"}); verifyPeerIdentity(host, port, socket); return socket; } From 5f11b3d998ffdb55c7e8a51d3ae0b51f13f9afdb Mon Sep 17 00:00:00 2001 From: "David A. Velasco" Date: Tue, 11 Nov 2014 13:37:30 +0100 Subject: [PATCH 11/22] Refactored test project to work correctly with AdvancedSslSocketFactory as base to create sockets --- .../network/AdvancedSslSocketFactory.java | 7 ++- .../SelfSignedConfidentSslSocketFactory.java | 47 ++++++------------- .../lib/test_project/TestActivity.java | 2 +- 3 files changed, 20 insertions(+), 36 deletions(-) diff --git a/src/com/owncloud/android/lib/common/network/AdvancedSslSocketFactory.java b/src/com/owncloud/android/lib/common/network/AdvancedSslSocketFactory.java index 0f9d11e4..de3d9cb5 100644 --- a/src/com/owncloud/android/lib/common/network/AdvancedSslSocketFactory.java +++ b/src/com/owncloud/android/lib/common/network/AdvancedSslSocketFactory.java @@ -78,8 +78,11 @@ public class AdvancedSslSocketFactory implements SecureProtocolSocketFactory { if (sslContext == null) throw new IllegalArgumentException("AdvancedSslSocketFactory can not be created with a null SSLContext"); - if (trustManager == null) - throw new IllegalArgumentException("AdvancedSslSocketFactory can not be created with a null Trust Manager"); + if (trustManager == null && mHostnameVerifier != null) + throw new IllegalArgumentException( + "AdvancedSslSocketFactory can not be created with a null Trust Manager and a " + + "not null Hostname Verifier" + ); mSslContext = sslContext; mTrustManager = trustManager; mHostnameVerifier = hostnameVerifier; diff --git a/test_client/src/com/owncloud/android/lib/test_project/SelfSignedConfidentSslSocketFactory.java b/test_client/src/com/owncloud/android/lib/test_project/SelfSignedConfidentSslSocketFactory.java index 3626e0b8..829cf39e 100644 --- a/test_client/src/com/owncloud/android/lib/test_project/SelfSignedConfidentSslSocketFactory.java +++ b/test_client/src/com/owncloud/android/lib/test_project/SelfSignedConfidentSslSocketFactory.java @@ -26,9 +26,7 @@ package com.owncloud.android.lib.test_project; import java.io.IOException; import java.net.InetAddress; -import java.net.InetSocketAddress; import java.net.Socket; -import java.net.SocketAddress; import java.net.UnknownHostException; import java.security.GeneralSecurityException; import java.security.KeyStore; @@ -38,9 +36,7 @@ import java.security.cert.CertStoreException; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; -import javax.net.SocketFactory; import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSocket; import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManagerFactory; import javax.net.ssl.X509TrustManager; @@ -49,7 +45,7 @@ import org.apache.commons.httpclient.ConnectTimeoutException; import org.apache.commons.httpclient.params.HttpConnectionParams; import org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory; -import com.owncloud.android.lib.common.network.ServerNameIndicator; +import com.owncloud.android.lib.common.network.AdvancedSslSocketFactory; /** @@ -64,7 +60,8 @@ import com.owncloud.android.lib.common.network.ServerNameIndicator; public class SelfSignedConfidentSslSocketFactory implements SecureProtocolSocketFactory { - private SSLContext mSslContext = null; + //private SSLContext mSslContext = null; + private AdvancedSslSocketFactory mWrappedSslSocketFactory = null; /** @@ -72,7 +69,13 @@ public class SelfSignedConfidentSslSocketFactory implements SecureProtocolSocket * @throws GeneralSecurityException */ public SelfSignedConfidentSslSocketFactory() throws GeneralSecurityException { - mSslContext = createSslContext(); + SSLContext sslContext = SSLContext.getInstance("TLS"); + sslContext.init( + null, + new TrustManager[] { new SelfSignedConfidentX509TrustManager() }, + null + ); + mWrappedSslSocketFactory = new AdvancedSslSocketFactory(sslContext, null, null); } @@ -81,7 +84,7 @@ public class SelfSignedConfidentSslSocketFactory implements SecureProtocolSocket */ @Override public Socket createSocket(String host, int port) throws IOException, UnknownHostException { - return mSslContext.getSocketFactory().createSocket(host, port); + return mWrappedSslSocketFactory.createSocket(host, port); } /** @@ -90,7 +93,7 @@ public class SelfSignedConfidentSslSocketFactory implements SecureProtocolSocket @Override public Socket createSocket(String host, int port, InetAddress clientHost, int clientPort) throws IOException, UnknownHostException { - return mSslContext.getSocketFactory().createSocket(host, port, clientHost, clientPort); + return mWrappedSslSocketFactory.createSocket(host, port, clientHost, clientPort); } /** @@ -112,19 +115,7 @@ public class SelfSignedConfidentSslSocketFactory implements SecureProtocolSocket HttpConnectionParams params) throws IOException, UnknownHostException, ConnectTimeoutException { - if (params == null) { - throw new IllegalArgumentException("Parameters may not be null"); - } - int timeout = params.getConnectionTimeout(); - SocketFactory socketfactory = mSslContext.getSocketFactory(); - Socket socket = socketfactory.createSocket(); - SocketAddress localaddr = new InetSocketAddress(localAddress, localPort); - SocketAddress remoteaddr = new InetSocketAddress(host, port); - socket.setSoTimeout(params.getSoTimeout()); - socket.bind(localaddr); - ServerNameIndicator.setServerNameIndication(host, (SSLSocket)socket); - socket.connect(remoteaddr, timeout); - return socket; + return mWrappedSslSocketFactory.createSocket(host, port, localAddress, localPort, params); } /** @@ -133,20 +124,10 @@ public class SelfSignedConfidentSslSocketFactory implements SecureProtocolSocket @Override public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException, UnknownHostException { - return mSslContext.getSocketFactory().createSocket(socket, host, port, autoClose); + return mWrappedSslSocketFactory.createSocket(socket, host, port, autoClose); } - - private static SSLContext createSslContext() throws GeneralSecurityException { - SSLContext context = SSLContext.getInstance("TLS"); - context.init( - null, - new TrustManager[] {new SelfSignedConfidentX509TrustManager()}, - null); - return context; - } - public static class SelfSignedConfidentX509TrustManager implements X509TrustManager { private X509TrustManager mStandardTrustManager = null; diff --git a/test_client/src/com/owncloud/android/lib/test_project/TestActivity.java b/test_client/src/com/owncloud/android/lib/test_project/TestActivity.java index 905fa511..b2a37ba1 100644 --- a/test_client/src/com/owncloud/android/lib/test_project/TestActivity.java +++ b/test_client/src/com/owncloud/android/lib/test_project/TestActivity.java @@ -188,7 +188,7 @@ public class TestActivity extends Activity { public RemoteOperationResult removeFile(String remotePath) { RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath); RemoteOperationResult result = removeOperation.execute(mClient); - return TestActivity.removeFile(remotePath, mClient); + return result; } /** From c1564e8c383d373072b9ef69fc95cb3514568731 Mon Sep 17 00:00:00 2001 From: "David A. Velasco" Date: Tue, 11 Nov 2014 14:19:37 +0100 Subject: [PATCH 12/22] Avoid remove in teardown of testUploadFileNotFound --- .../owncloud/android/lib/test_project/test/UploadFileTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/UploadFileTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/UploadFileTest.java index 5a69f0d2..89f5f12c 100644 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/UploadFileTest.java +++ b/test_client/tests/src/com/owncloud/android/lib/test_project/test/UploadFileTest.java @@ -115,7 +115,7 @@ public class UploadFileTest extends ActivityInstrumentationTestCase2 Date: Wed, 12 Nov 2014 14:18:22 +0100 Subject: [PATCH 13/22] Use Travis build number to avoid parallel tests interfere each other --- .../test_project/test/CreateFolderTest.java | 2 +- .../lib/test_project/test/CreateShareTest.java | 2 +- .../lib/test_project/test/DeleteFileTest.java | 4 ++-- .../test_project/test/DownloadFileTest.java | 6 +++--- .../lib/test_project/test/GetSharesTest.java | 2 +- .../lib/test_project/test/MoveFileTest.java | 4 ++-- .../lib/test_project/test/ReadFileTest.java | 2 +- .../lib/test_project/test/ReadFolderTest.java | 2 +- .../lib/test_project/test/RemoveShareTest.java | 2 +- .../lib/test_project/test/RenameFileTest.java | 10 ++++++---- .../lib/test_project/test/UploadFileTest.java | 6 +++--- .../android/lib/test_project/test/Utils.java | 18 +++++++++++++++++- 12 files changed, 39 insertions(+), 21 deletions(-) diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/CreateFolderTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/CreateFolderTest.java index 3b77f220..cbef8ff3 100644 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/CreateFolderTest.java +++ b/test_client/tests/src/com/owncloud/android/lib/test_project/test/CreateFolderTest.java @@ -46,7 +46,7 @@ public class CreateFolderTest extends ActivityInstrumentationTestCase2 /// Paths to files and folders in fixture - private static final String SRC_BASE_FOLDER = "/src/"; - private static final String TARGET_BASE_FOLDER = "/target/"; + private static final String SRC_BASE_FOLDER = "/src" + Utils.getBuildNumber() + "/"; + private static final String TARGET_BASE_FOLDER = "/target" + Utils.getBuildNumber() + "/"; private static final String NO_FILE = "nofile.txt"; private static final String FILE1 = "file1.txt"; private static final String FILE2 = "file2.txt"; diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/ReadFileTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/ReadFileTest.java index c8a39401..8255cb7a 100644 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/ReadFileTest.java +++ b/test_client/tests/src/com/owncloud/android/lib/test_project/test/ReadFileTest.java @@ -42,7 +42,7 @@ public class ReadFileTest extends ActivityInstrumentationTestCase2 Date: Wed, 12 Nov 2014 14:28:21 +0100 Subject: [PATCH 14/22] Ignore timeouts in setups() and teardowns() to work around response time of test server --- .../android/lib/test_project/test/CreateFolderTest.java | 2 +- .../android/lib/test_project/test/CreateShareTest.java | 3 ++- .../android/lib/test_project/test/DeleteFileTest.java | 3 ++- .../android/lib/test_project/test/DownloadFileTest.java | 2 +- .../android/lib/test_project/test/GetSharesTest.java | 5 +++-- .../owncloud/android/lib/test_project/test/MoveFileTest.java | 2 +- .../owncloud/android/lib/test_project/test/ReadFileTest.java | 3 ++- .../android/lib/test_project/test/ReadFolderTest.java | 3 ++- .../android/lib/test_project/test/RemoveShareTest.java | 3 ++- .../android/lib/test_project/test/RenameFileTest.java | 2 +- .../android/lib/test_project/test/UploadFileTest.java | 5 +++-- 11 files changed, 20 insertions(+), 13 deletions(-) diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/CreateFolderTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/CreateFolderTest.java index cbef8ff3..6c8871b3 100644 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/CreateFolderTest.java +++ b/test_client/tests/src/com/owncloud/android/lib/test_project/test/CreateFolderTest.java @@ -130,7 +130,7 @@ public class CreateFolderTest extends ActivityInstrumentationTestCase2 RemoteOperationResult result = null; for (String folderPath : FOLDERS_IN_FIXTURE) { result = TestActivity.createFolder(folderPath, true, mClient); - if (!result.isSuccess()) { + if (!result.isSuccess() && result.getCode() != ResultCode.TIMEOUT) { Utils.logAndThrow(LOG_TAG, result); } } diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/ReadFileTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/ReadFileTest.java index 8255cb7a..93dacd92 100644 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/ReadFileTest.java +++ b/test_client/tests/src/com/owncloud/android/lib/test_project/test/ReadFileTest.java @@ -26,6 +26,7 @@ package com.owncloud.android.lib.test_project.test; import java.io.File; import com.owncloud.android.lib.common.operations.RemoteOperationResult; +import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; import com.owncloud.android.lib.test_project.TestActivity; import android.test.ActivityInstrumentationTestCase2; @@ -78,7 +79,7 @@ public class ReadFileTest extends ActivityInstrumentationTestCase2 Date: Wed, 12 Nov 2014 18:18:04 +0100 Subject: [PATCH 15/22] REALLY use Travis build number to avoid parallel tests interfere each other --- test_client/tests/custom_rules.xml | 17 ++++ test_client/tests/res/values/setup.xml | 28 ++++++ .../test_project/test/CreateFolderTest.java | 37 ++++---- .../test_project/test/CreateShareTest.java | 23 ++--- .../lib/test_project/test/DeleteFileTest.java | 23 +++-- .../test_project/test/DownloadFileTest.java | 51 ++++++----- .../lib/test_project/test/GetSharesTest.java | 21 ++--- .../lib/test_project/test/MoveFileTest.java | 86 +++++++++---------- .../lib/test_project/test/ReadFileTest.java | 18 ++-- .../lib/test_project/test/ReadFolderTest.java | 20 ++--- .../lib/test_project/test/RemoteTest.java | 69 +++++++++++++++ .../test_project/test/RemoveShareTest.java | 20 ++--- .../lib/test_project/test/RenameFileTest.java | 75 ++++++++-------- .../lib/test_project/test/UploadFileTest.java | 29 +++---- .../android/lib/test_project/test/Utils.java | 8 +- 15 files changed, 306 insertions(+), 219 deletions(-) create mode 100644 test_client/tests/res/values/setup.xml create mode 100644 test_client/tests/src/com/owncloud/android/lib/test_project/test/RemoteTest.java diff --git a/test_client/tests/custom_rules.xml b/test_client/tests/custom_rules.xml index c771dcd6..9b2ff335 100644 --- a/test_client/tests/custom_rules.xml +++ b/test_client/tests/custom_rules.xml @@ -1,5 +1,22 @@ + + + + + + + + + + + + + diff --git a/test_client/tests/res/values/setup.xml b/test_client/tests/res/values/setup.xml new file mode 100644 index 00000000..08bb772b --- /dev/null +++ b/test_client/tests/res/values/setup.xml @@ -0,0 +1,28 @@ + + + + + + diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/CreateFolderTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/CreateFolderTest.java index 6c8871b3..a6c90b06 100644 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/CreateFolderTest.java +++ b/test_client/tests/src/com/owncloud/android/lib/test_project/test/CreateFolderTest.java @@ -23,9 +23,7 @@ */ package com.owncloud.android.lib.test_project.test; -import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Date; import java.util.Iterator; import java.util.List; @@ -33,52 +31,47 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; import com.owncloud.android.lib.test_project.TestActivity; -import android.test.ActivityInstrumentationTestCase2; - /** * Class to test Create Folder Operation * @author masensio * @author David A. Velasco * */ -public class CreateFolderTest extends ActivityInstrumentationTestCase2 { +public class CreateFolderTest extends RemoteTest { private static final String LOG_TAG = CreateFolderTest.class.getCanonicalName(); - private static final String FOLDER_PATH_BASE = "/testCreateFolder" + Utils.getBuildNumber(); + private static final String FOLDER_PATH_BASE = "/testCreateFolder"; private TestActivity mActivity; - private String mCurrentDate; private List mCreatedFolderPaths; + private String mFullPath2FolderBase; public CreateFolderTest() { - super(TestActivity.class); - - SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss"); - mCurrentDate = sdf.format(new Date()); + super(); mCreatedFolderPaths = new ArrayList(); } @Override protected void setUp() throws Exception { super.setUp(); - setActivityInitialTouchMode(false); mActivity = getActivity(); mCreatedFolderPaths.clear(); + mFullPath2FolderBase = mBaseFolderPath + FOLDER_PATH_BASE; } /** * Test Create Folder */ public void testCreateFolder() { - String remotePath = FOLDER_PATH_BASE + mCurrentDate; + String remotePath = mFullPath2FolderBase; mCreatedFolderPaths.add(remotePath); RemoteOperationResult result = mActivity.createFolder(remotePath, true); assertTrue(result.isSuccess() || result.getCode() == ResultCode.TIMEOUT); // Create Subfolder - remotePath = FOLDER_PATH_BASE + mCurrentDate + FOLDER_PATH_BASE + mCurrentDate; + remotePath = mFullPath2FolderBase + FOLDER_PATH_BASE; mCreatedFolderPaths.add(remotePath); result = mActivity.createFolder(remotePath, true); assertTrue(result.isSuccess() || result.getCode() == ResultCode.TIMEOUT); @@ -90,35 +83,35 @@ public class CreateFolderTest extends ActivityInstrumentationTestCase2" + mCurrentDate; + remotePath = mFullPath2FolderBase + "_>"; result = mActivity.createFolder(remotePath, true); assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); - remotePath = FOLDER_PATH_BASE + "_:" + mCurrentDate; + remotePath = mFullPath2FolderBase + "_:"; result = mActivity.createFolder(remotePath, true); assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); - remotePath = FOLDER_PATH_BASE + "_\"" + mCurrentDate; + remotePath = mFullPath2FolderBase + "_\""; result = mActivity.createFolder(remotePath, true); assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); - remotePath = FOLDER_PATH_BASE + "_|" + mCurrentDate; + remotePath = mFullPath2FolderBase + "_|"; result = mActivity.createFolder(remotePath, true); assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); - remotePath = FOLDER_PATH_BASE + "_?" + mCurrentDate; + remotePath = mFullPath2FolderBase + "_?"; result = mActivity.createFolder(remotePath, true); assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); - remotePath = FOLDER_PATH_BASE + "_*" + mCurrentDate; + remotePath = mFullPath2FolderBase + "_*"; result = mActivity.createFolder(remotePath, true); assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); } diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/CreateShareTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/CreateShareTest.java index 6e1ba11c..257e2ca5 100644 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/CreateShareTest.java +++ b/test_client/tests/src/com/owncloud/android/lib/test_project/test/CreateShareTest.java @@ -31,32 +31,27 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCo import com.owncloud.android.lib.resources.shares.ShareType; import com.owncloud.android.lib.test_project.TestActivity; -import android.test.ActivityInstrumentationTestCase2; - -public class CreateShareTest extends ActivityInstrumentationTestCase2 { +public class CreateShareTest extends RemoteTest { private static final String LOG_TAG = CreateShareTest.class.getCanonicalName(); /* File to share.*/ - private static final String FILE_TO_SHARE = "/fileToShare" + Utils.getBuildNumber() + ".txt"; + private static final String FILE_TO_SHARE = "/fileToShare.txt"; private TestActivity mActivity; - - public CreateShareTest() { - super(TestActivity.class); - - } - + private String mFullPath2FileToShare; + @Override protected void setUp() throws Exception { super.setUp(); setActivityInitialTouchMode(false); mActivity = getActivity(); - + mFullPath2FileToShare = mBaseFolderPath + FILE_TO_SHARE; + File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME); RemoteOperationResult result = mActivity.uploadFile( textFile.getAbsolutePath(), - FILE_TO_SHARE, + mFullPath2FileToShare, "txt/plain"); if (!result.isSuccess()) { Utils.logAndThrow(LOG_TAG, result); @@ -68,7 +63,7 @@ public class CreateShareTest extends ActivityInstrumentationTestCase2 { +public class DeleteFileTest extends RemoteTest { private static final String LOG_TAG = DeleteFileTest.class.getCanonicalName(); /* Folder data to delete. */ - private static final String FOLDER_PATH = "/folderToDelete" + Utils.getBuildNumber(); + private static final String FOLDER_PATH = "/folderToDelete"; /* File to delete. */ - private static final String FILE_PATH = "/fileToDelete" + Utils.getBuildNumber() + ".txt"; + private static final String FILE_PATH = "/fileToDelete.txt"; private static boolean mGlobalSetupDone = false; private TestActivity mActivity; - - public DeleteFileTest() { - super(TestActivity.class); - } + private String mFullPath2Folder; + private String mFullPath2File; @Override protected void setUp() throws Exception { super.setUp(); setActivityInitialTouchMode(false); mActivity = getActivity(); + mFullPath2Folder = mBaseFolderPath + FOLDER_PATH; + mFullPath2File = mBaseFolderPath + FILE_PATH; if (!mGlobalSetupDone) { Log.v(LOG_TAG, "Starting global set up"); - RemoteOperationResult result = mActivity.createFolder(FOLDER_PATH, true); + RemoteOperationResult result = mActivity.createFolder(mFullPath2Folder, true); if (!result.isSuccess() && result.getCode() != ResultCode.TIMEOUT) { Utils.logAndThrow(LOG_TAG, result); } @@ -74,7 +73,7 @@ public class DeleteFileTest extends ActivityInstrumentationTestCase2 { +public class DownloadFileTest extends RemoteTest { private static final String LOG_TAG = DownloadFileTest.class.getCanonicalName(); /* Files to download. These files must exist on the account */ - private static final String IMAGE_PATH = "/fileToDownload" + Utils.getBuildNumber() + ".png"; - private static final String IMAGE_PATH_WITH_SPECIAL_CHARS = "/@file@download" + Utils.getBuildNumber() + ".png"; - private static final String IMAGE_NOT_FOUND = "/fileNotFound" + Utils.getBuildNumber() + ".png"; - private static final String [] FILE_PATHS = { IMAGE_PATH, IMAGE_PATH_WITH_SPECIAL_CHARS }; + private static final String IMAGE_PATH = "/fileToDownload.png"; + private static final String IMAGE_PATH_WITH_SPECIAL_CHARS = "/@file@download.png"; + private static final String IMAGE_NOT_FOUND = "/fileNotFound.png"; private static boolean mGlobalSetupDone = false; + private String mFullPath2Image; + private String mFullPath2ImageWitSpecialChars; + private String mFullPath2ImageNotFound; private String mDownloadedFilePath; private TestActivity mActivity; - public DownloadFileTest() { - super(TestActivity.class); - } - @Override protected void setUp() throws Exception { super.setUp(); setActivityInitialTouchMode(false); mActivity = getActivity(); mDownloadedFilePath = null; + mFullPath2Image = mBaseFolderPath + IMAGE_PATH; + mFullPath2ImageWitSpecialChars = mBaseFolderPath + IMAGE_PATH_WITH_SPECIAL_CHARS; + mFullPath2ImageNotFound = mBaseFolderPath + IMAGE_NOT_FOUND; if (!mGlobalSetupDone) { - RemoteOperationResult result = null; File imageFile = mActivity.extractAsset(TestActivity.ASSETS__IMAGE_FILE_NAME); - for (int i=0; i { +public class GetSharesTest extends RemoteTest { private static final String LOG_TAG = GetSharesTest.class.getCanonicalName(); - private static final String SHARED_FILE = "/sharedFileToGet" + Utils.getBuildNumber() + ".txt"; + private static final String SHARED_FILE = "/sharedFileToGet.txt"; private TestActivity mActivity; + private String mFullPath2SharedFile; - public GetSharesTest() { - super(TestActivity.class); - - } - @Override protected void setUp() throws Exception { super.setUp(); setActivityInitialTouchMode(false); mActivity = getActivity(); - + mFullPath2SharedFile = mBaseFolderPath + SHARED_FILE; + File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME); RemoteOperationResult result = mActivity.uploadFile( textFile.getAbsolutePath(), - SHARED_FILE, + mFullPath2SharedFile, "txt/plain"); if (!result.isSuccess()) { Utils.logAndThrow(LOG_TAG, result); } - result = mActivity.createShare(SHARED_FILE, ShareType.PUBLIC_LINK, "", false, "", 1); + result = mActivity.createShare(mFullPath2SharedFile, ShareType.PUBLIC_LINK, "", false, "", 1); if (!result.isSuccess() && result.getCode() != ResultCode.TIMEOUT) { Utils.logAndThrow(LOG_TAG, result); } @@ -87,7 +82,7 @@ public class GetSharesTest extends ActivityInstrumentationTestCase2 { +public class MoveFileTest extends RemoteTest { private static final String LOG_TAG = MoveFileTest.class.getCanonicalName(); /// Paths to files and folders in fixture - private static final String SRC_BASE_FOLDER = "/src" + Utils.getBuildNumber() + "/"; - private static final String TARGET_BASE_FOLDER = "/target" + Utils.getBuildNumber() + "/"; + private static final String SRC_BASE_FOLDER = "/src/"; + private static final String TARGET_BASE_FOLDER = "/target/"; private static final String NO_FILE = "nofile.txt"; private static final String FILE1 = "file1.txt"; private static final String FILE2 = "file2.txt"; @@ -209,7 +207,7 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2 OwnCloudClient mClient = null; public MoveFileTest() { - super(TestActivity.class); + super(); Protocol pr = Protocol.getProtocol("https"); if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) { @@ -244,7 +242,7 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2 RemoteOperationResult result = null; for (String folderPath : FOLDERS_IN_FIXTURE) { - result = TestActivity.createFolder(folderPath, true, mClient); + result = TestActivity.createFolder(mBaseFolderPath + folderPath, true, mClient); if (!result.isSuccess() && result.getCode() != ResultCode.TIMEOUT) { Utils.logAndThrow(LOG_TAG, result); } @@ -255,7 +253,7 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2 ); for (String filePath : FILES_IN_FIXTURE) { result = TestActivity.uploadFile( - txtFile.getAbsolutePath(), filePath, "txt/plain", mClient + txtFile.getAbsolutePath(), mBaseFolderPath + filePath, "txt/plain", mClient ); if (!result.isSuccess()) { Utils.logAndThrow(LOG_TAG, result); @@ -277,8 +275,8 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2 // move file MoveRemoteFileOperation moveOperation = new MoveRemoteFileOperation( - SRC_PATH_TO_FILE_1, - TARGET_PATH_TO_FILE_1, + mBaseFolderPath + SRC_PATH_TO_FILE_1, + mBaseFolderPath + TARGET_PATH_TO_FILE_1, false ); RemoteOperationResult result = moveOperation.execute(mClient); @@ -286,8 +284,8 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2 // move & rename file, different location moveOperation = new MoveRemoteFileOperation( - SRC_PATH_TO_FILE_2, - TARGET_PATH_TO_FILE_2_RENAMED, + mBaseFolderPath + SRC_PATH_TO_FILE_2, + mBaseFolderPath + TARGET_PATH_TO_FILE_2_RENAMED, false ); result = moveOperation.execute(mClient); @@ -295,8 +293,8 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2 // move & rename file, same location (rename file) moveOperation = new MoveRemoteFileOperation( - SRC_PATH_TO_FILE_3, - SRC_PATH_TO_FILE_3_RENAMED, + mBaseFolderPath + SRC_PATH_TO_FILE_3, + mBaseFolderPath + SRC_PATH_TO_FILE_3_RENAMED, false ); result = moveOperation.execute(mClient); @@ -304,8 +302,8 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2 // move empty folder moveOperation = new MoveRemoteFileOperation( - SRC_PATH_TO_EMPTY_FOLDER, - TARGET_PATH_TO_EMPTY_FOLDER, + mBaseFolderPath + SRC_PATH_TO_EMPTY_FOLDER, + mBaseFolderPath + TARGET_PATH_TO_EMPTY_FOLDER, false ); result = moveOperation.execute(mClient); @@ -313,8 +311,8 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2 // move non-empty folder moveOperation = new MoveRemoteFileOperation( - SRC_PATH_TO_FULL_FOLDER_1, - TARGET_PATH_TO_FULL_FOLDER_1, + mBaseFolderPath + SRC_PATH_TO_FULL_FOLDER_1, + mBaseFolderPath + TARGET_PATH_TO_FULL_FOLDER_1, false ); result = moveOperation.execute(mClient); @@ -322,8 +320,8 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2 // move & rename folder, different location moveOperation = new MoveRemoteFileOperation( - SRC_PATH_TO_FULL_FOLDER_2, - TARGET_PATH_TO_FULL_FOLDER_2_RENAMED, + mBaseFolderPath + SRC_PATH_TO_FULL_FOLDER_2, + mBaseFolderPath + TARGET_PATH_TO_FULL_FOLDER_2_RENAMED, false ); result = moveOperation.execute(mClient); @@ -331,8 +329,8 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2 // move & rename folder, same location (rename folder) moveOperation = new MoveRemoteFileOperation( - SRC_PATH_TO_FULL_FOLDER_3, - SRC_PATH_TO_FULL_FOLDER_3_RENAMED, + mBaseFolderPath + SRC_PATH_TO_FULL_FOLDER_3, + mBaseFolderPath + SRC_PATH_TO_FULL_FOLDER_3_RENAMED, false ); result = moveOperation.execute(mClient); @@ -340,8 +338,8 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2 // move for nothing (success, but no interaction with network) moveOperation = new MoveRemoteFileOperation( - SRC_PATH_TO_FILE_4, - SRC_PATH_TO_FILE_4, + mBaseFolderPath + SRC_PATH_TO_FILE_4, + mBaseFolderPath + SRC_PATH_TO_FILE_4, false ); result = moveOperation.execute(mClient); @@ -349,9 +347,9 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2 // move overwriting moveOperation = new MoveRemoteFileOperation( - SRC_PATH_TO_FULL_FOLDER_4, - TARGET_PATH_TO_ALREADY_EXISTENT_EMPTY_FOLDER_4, - true + mBaseFolderPath + SRC_PATH_TO_FULL_FOLDER_4, + mBaseFolderPath + TARGET_PATH_TO_ALREADY_EXISTENT_EMPTY_FOLDER_4, + true ); result = moveOperation.execute(mClient); assertTrue(result.isSuccess()); @@ -361,45 +359,45 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2 // file to move does not exist moveOperation = new MoveRemoteFileOperation( - SRC_PATH_TO_NON_EXISTENT_FILE, - TARGET_PATH_TO_NON_EXISTENT_FILE, - false + mBaseFolderPath + SRC_PATH_TO_NON_EXISTENT_FILE, + mBaseFolderPath + TARGET_PATH_TO_NON_EXISTENT_FILE, + false ); result = moveOperation.execute(mClient); assertTrue(result.getCode() == ResultCode.FILE_NOT_FOUND); // folder to move into does no exist moveOperation = new MoveRemoteFileOperation( - SRC_PATH_TO_FILE_5, - TARGET_PATH_TO_FILE_5_INTO_NON_EXISTENT_FOLDER, - false + mBaseFolderPath + SRC_PATH_TO_FILE_5, + mBaseFolderPath + TARGET_PATH_TO_FILE_5_INTO_NON_EXISTENT_FOLDER, + false ); result = moveOperation.execute(mClient); assertTrue(result.getHttpCode() == HttpStatus.SC_CONFLICT); // target location (renaming) has invalid characters moveOperation = new MoveRemoteFileOperation( - SRC_PATH_TO_FILE_6, - TARGET_PATH_RENAMED_WITH_INVALID_CHARS, - false + mBaseFolderPath + SRC_PATH_TO_FILE_6, + mBaseFolderPath + TARGET_PATH_RENAMED_WITH_INVALID_CHARS, + false ); result = moveOperation.execute(mClient); assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); // name collision moveOperation = new MoveRemoteFileOperation( - SRC_PATH_TO_FILE_7, - TARGET_PATH_TO_ALREADY_EXISTENT_FILE_7, - false + mBaseFolderPath + SRC_PATH_TO_FILE_7, + mBaseFolderPath + TARGET_PATH_TO_ALREADY_EXISTENT_FILE_7, + false ); result = moveOperation.execute(mClient); assertTrue(result.getCode() == ResultCode.INVALID_OVERWRITE); // move a folder into a descendant moveOperation = new MoveRemoteFileOperation( - SRC_BASE_FOLDER, - SRC_PATH_TO_EMPTY_FOLDER, - false + mBaseFolderPath + SRC_BASE_FOLDER, + mBaseFolderPath + SRC_PATH_TO_EMPTY_FOLDER, + false ); result = moveOperation.execute(mClient); assertTrue(result.getCode() == ResultCode.INVALID_MOVE_INTO_DESCENDANT); @@ -411,8 +409,8 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2 Log.v(LOG_TAG, "Deleting remote fixture..."); String[] mPathsToCleanUp = { - SRC_BASE_FOLDER, - TARGET_BASE_FOLDER + mBaseFolderPath + SRC_BASE_FOLDER, + mBaseFolderPath + TARGET_BASE_FOLDER }; for (String path : mPathsToCleanUp) { diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/ReadFileTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/ReadFileTest.java index 93dacd92..ec828f2c 100644 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/ReadFileTest.java +++ b/test_client/tests/src/com/owncloud/android/lib/test_project/test/ReadFileTest.java @@ -29,25 +29,20 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; import com.owncloud.android.lib.test_project.TestActivity; -import android.test.ActivityInstrumentationTestCase2; - /** * Class to test Read File Operation * @author masensio * @author David A. Velasco */ -public class ReadFileTest extends ActivityInstrumentationTestCase2 { +public class ReadFileTest extends RemoteTest { private static final String LOG_TAG = ReadFileTest.class.getCanonicalName(); private TestActivity mActivity; - private String FILE_PATH = "/fileToRead" + Utils.getBuildNumber() + ".txt"; - - public ReadFileTest() { - super(TestActivity.class); - } + private String FILE_PATH = "/fileToRead.txt"; + private String mFullPath2File; @Override protected void setUp() throws Exception { @@ -55,11 +50,12 @@ public class ReadFileTest extends ActivityInstrumentationTestCase2 { +public class ReadFolderTest extends RemoteTest { private static final String LOG_TAG = ReadFolderTest.class.getCanonicalName(); - private static final String FOLDER_PATH = "/folderToRead" + Utils.getBuildNumber(); + private static final String FOLDER_PATH = "/folderToRead"; private static final String [] FILE_PATHS = { FOLDER_PATH + "/file1.txt", FOLDER_PATH + "/file2.txt", @@ -51,24 +49,22 @@ public class ReadFolderTest extends ActivityInstrumentationTestCase2 1); assertTrue(result.getData().size() == 4); @@ -94,7 +90,7 @@ public class ReadFolderTest extends ActivityInstrumentationTestCase2 { + + private static final String LOG_TAG = RemoteTest.class.getSimpleName(); + + protected String mBaseFolderPath = "/test_for_build_"; + + public RemoteTest() { + super(TestActivity.class); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + setActivityInitialTouchMode(false); + mBaseFolderPath += Utils.getBuildNumber(getActivity()); + + RemoteOperationResult result = getActivity().createFolder(mBaseFolderPath, true); + if (!result.isSuccess() && result.getCode() != ResultCode.TIMEOUT) { + Utils.logAndThrow(LOG_TAG, result); + } + } + + + @Override + protected void tearDown() throws Exception { + RemoteOperationResult removeResult = getActivity().removeFile(mBaseFolderPath); + if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) { + Utils.logAndThrow(LOG_TAG, removeResult); + } + super.tearDown(); + } + +} diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/RemoveShareTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/RemoveShareTest.java index 2ea83a15..b9e8d6dd 100644 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/RemoveShareTest.java +++ b/test_client/tests/src/com/owncloud/android/lib/test_project/test/RemoveShareTest.java @@ -32,39 +32,35 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; import com.owncloud.android.lib.test_project.TestActivity; -import android.test.ActivityInstrumentationTestCase2; - -public class RemoveShareTest extends ActivityInstrumentationTestCase2 { +public class RemoveShareTest extends RemoteTest { private static final String LOG_TAG = RemoveShareTest.class.getCanonicalName(); - private static final String FILE_TO_UNSHARE = "/fileToUnshare" + Utils.getBuildNumber() + ".txt"; + private static final String FILE_TO_UNSHARE = "/fileToUnshare.txt"; private TestActivity mActivity; + + private String mFullPath2FileToUnshare; private long mShareId; - public RemoveShareTest() { - super(TestActivity.class); - - } - @Override protected void setUp() throws Exception { super.setUp(); setActivityInitialTouchMode(false); mActivity = getActivity(); + mFullPath2FileToUnshare = mBaseFolderPath + FILE_TO_UNSHARE; File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME); RemoteOperationResult result = mActivity.uploadFile( textFile.getAbsolutePath(), - FILE_TO_UNSHARE, + mFullPath2FileToUnshare, "txt/plain"); if (!result.isSuccess()) { Utils.logAndThrow(LOG_TAG, result); } - result = mActivity.createShare(FILE_TO_UNSHARE, ShareType.PUBLIC_LINK, "", false, "", 1); + result = mActivity.createShare(mFullPath2FileToUnshare, ShareType.PUBLIC_LINK, "", false, "", 1); if (!result.isSuccess()) { Utils.logAndThrow(LOG_TAG, result); } else { @@ -85,7 +81,7 @@ public class RemoveShareTest extends ActivityInstrumentationTestCase2 { +public class RenameFileTest extends RemoteTest { private static final String LOG_TAG = RenameFileTest.class.getCanonicalName(); /* Folder data to rename. This folder must exist on the account */ - private static final String OLD_FOLDER_NAME = "folderToRename" + Utils.getBuildNumber(); + private static final String OLD_FOLDER_NAME = "folderToRename"; private static final String OLD_FOLDER_PATH = FileUtils.PATH_SEPARATOR + OLD_FOLDER_NAME; - private static final String NEW_FOLDER_NAME = "renamedFolder" + Utils.getBuildNumber(); + private static final String NEW_FOLDER_NAME = "renamedFolder"; private static final String NEW_FOLDER_PATH = FileUtils.PATH_SEPARATOR + NEW_FOLDER_NAME; /* File data to rename. This file must exist on the account */ - private static final String OLD_FILE_NAME = "fileToRename" + Utils.getBuildNumber() + ".png"; + private static final String OLD_FILE_NAME = "fileToRename.png"; private static final String OLD_FILE_PATH = FileUtils.PATH_SEPARATOR + OLD_FILE_NAME; - private static final String NEW_FILE_NAME = "renamedFile" + Utils.getBuildNumber() + ".png"; + private static final String NEW_FILE_NAME = "renamedFile.png"; private static final String NEW_FILE_PATH = FileUtils.PATH_SEPARATOR + NEW_FILE_NAME; @@ -61,22 +60,26 @@ public class RenameFileTest extends ActivityInstrumentationTestCase2", true); assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); - result = mActivity.renameFile(OLD_FOLDER_NAME, OLD_FOLDER_PATH, + result = mActivity.renameFile(OLD_FOLDER_NAME, mFullPath2OldFolder, NEW_FOLDER_NAME + ":", true); assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); - result = mActivity.renameFile(OLD_FOLDER_NAME, OLD_FOLDER_PATH, + result = mActivity.renameFile(OLD_FOLDER_NAME, mFullPath2OldFolder, NEW_FOLDER_NAME + "\"", true); assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); - result = mActivity.renameFile(OLD_FOLDER_NAME, OLD_FOLDER_PATH, + result = mActivity.renameFile(OLD_FOLDER_NAME, mFullPath2OldFolder, NEW_FOLDER_NAME + "|", true); assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); - result = mActivity.renameFile(OLD_FOLDER_NAME, OLD_FOLDER_PATH, + result = mActivity.renameFile(OLD_FOLDER_NAME, mFullPath2OldFolder, NEW_FOLDER_NAME + "?", true); assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); - result = mActivity.renameFile(OLD_FOLDER_NAME, OLD_FOLDER_PATH, + result = mActivity.renameFile(OLD_FOLDER_NAME, mFullPath2OldFolder, NEW_FOLDER_NAME + "*", true); assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); } @@ -154,14 +157,14 @@ public class RenameFileTest extends ActivityInstrumentationTestCase2" + NEW_FILE_NAME, false); assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); result = mActivity.renameFile( OLD_FILE_NAME, - OLD_FILE_PATH, + mFullPath2OldFile, ":" + NEW_FILE_NAME, false); assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); result = mActivity.renameFile( OLD_FILE_NAME, - OLD_FILE_PATH, + mFullPath2OldFile, "\"" + NEW_FILE_NAME, false); assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); result = mActivity.renameFile( OLD_FILE_NAME, - OLD_FILE_PATH, + mFullPath2OldFile, "|" + NEW_FILE_NAME, false); assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); result = mActivity.renameFile( OLD_FILE_NAME, - OLD_FILE_PATH, + mFullPath2OldFile, "?" + NEW_FILE_NAME, false); assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); result = mActivity.renameFile( OLD_FILE_NAME, - OLD_FILE_PATH, + mFullPath2OldFile, "*" + NEW_FILE_NAME, false); assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/UploadFileTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/UploadFileTest.java index 8330e208..08cf686f 100644 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/UploadFileTest.java +++ b/test_client/tests/src/com/owncloud/android/lib/test_project/test/UploadFileTest.java @@ -26,8 +26,6 @@ package com.owncloud.android.lib.test_project.test; import java.io.File; -import android.test.ActivityInstrumentationTestCase2; - import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; import com.owncloud.android.lib.test_project.TestActivity; @@ -39,15 +37,15 @@ import com.owncloud.android.lib.test_project.TestActivity; * */ -public class UploadFileTest extends ActivityInstrumentationTestCase2 { +public class UploadFileTest extends RemoteTest { private static final String LOG_TAG = UploadFileTest.class.getCanonicalName(); - private static final String UPLOAD_PATH = "/uploadedImage" + Utils.getBuildNumber() + ".png"; + private static final String UPLOAD_PATH = "/uploadedImage.png"; - private static final String CHUNKED_UPLOAD_PATH = "/uploadedVideo" + Utils.getBuildNumber() + ".MP4"; + private static final String CHUNKED_UPLOAD_PATH = "/uploadedVideo.MP4"; - private static final String FILE_NOT_FOUND_PATH = "/notFoundShouldNotBeHere" + Utils.getBuildNumber() + ".png"; + private static final String FILE_NOT_FOUND_PATH = "/notFoundShouldNotBeHere.png"; private TestActivity mActivity; @@ -55,10 +53,6 @@ public class UploadFileTest extends ActivityInstrumentationTestCase2 Date: Wed, 12 Nov 2014 19:14:07 +0100 Subject: [PATCH 16/22] Move build_number resource to the right context --- test_client/custom_rules.xml | 14 ++++++++++ test_client/res/values/setup.xml | 1 + test_client/tests/custom_rules.xml | 16 ----------- test_client/tests/res/values/setup.xml | 28 ------------------- .../android/lib/test_project/test/Utils.java | 1 + 5 files changed, 16 insertions(+), 44 deletions(-) delete mode 100644 test_client/tests/res/values/setup.xml diff --git a/test_client/custom_rules.xml b/test_client/custom_rules.xml index 0d50badc..cb014b3a 100644 --- a/test_client/custom_rules.xml +++ b/test_client/custom_rules.xml @@ -43,5 +43,19 @@ byline="true" /> + + + + + + + + + + \ No newline at end of file diff --git a/test_client/res/values/setup.xml b/test_client/res/values/setup.xml index ac5cedde..4c54c7f9 100644 --- a/test_client/res/values/setup.xml +++ b/test_client/res/values/setup.xml @@ -24,6 +24,7 @@ --> + diff --git a/test_client/tests/custom_rules.xml b/test_client/tests/custom_rules.xml index 9b2ff335..1849940c 100644 --- a/test_client/tests/custom_rules.xml +++ b/test_client/tests/custom_rules.xml @@ -1,22 +1,6 @@ - - - - - - - - - - - - diff --git a/test_client/tests/res/values/setup.xml b/test_client/tests/res/values/setup.xml deleted file mode 100644 index 08bb772b..00000000 --- a/test_client/tests/res/values/setup.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/Utils.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/Utils.java index a1b60f09..5f826f74 100644 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/Utils.java +++ b/test_client/tests/src/com/owncloud/android/lib/test_project/test/Utils.java @@ -28,6 +28,7 @@ import android.content.Context; import android.util.Log; import com.owncloud.android.lib.common.operations.RemoteOperationResult; +import com.owncloud.android.lib.test_project.R; public class Utils { From 950a3ff8f71e324dd944a6a2907618b4704765dc Mon Sep 17 00:00:00 2001 From: "David A. Velasco" Date: Fri, 14 Nov 2014 14:59:05 +0100 Subject: [PATCH 17/22] Apply protocol enabling to extra createSocket method after merging fix on tunneled HTTP --- .../android/lib/common/network/AdvancedSslSocketFactory.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/com/owncloud/android/lib/common/network/AdvancedSslSocketFactory.java b/src/com/owncloud/android/lib/common/network/AdvancedSslSocketFactory.java index de3d9cb5..7d6a59b8 100644 --- a/src/com/owncloud/android/lib/common/network/AdvancedSslSocketFactory.java +++ b/src/com/owncloud/android/lib/common/network/AdvancedSslSocketFactory.java @@ -313,6 +313,7 @@ public class AdvancedSslSocketFactory implements SecureProtocolSocketFactory { public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException, UnknownHostException { Socket sslSocket = mSslContext.getSocketFactory().createSocket(socket, host, port, autoClose); + ((SSLSocket) sslSocket).setEnabledProtocols(new String[]{"TLSv1", "TLSv1.1", "TLSv1.2"}); verifyPeerIdentity(host, port, sslSocket); return sslSocket; } From 5ce6e92b533094870067418e5c7c6cdde1145639 Mon Sep 17 00:00:00 2001 From: "David A. Velasco" Date: Mon, 17 Nov 2014 09:40:47 +0100 Subject: [PATCH 18/22] Enabling secure protocols in a single method --- .../network/AdvancedSslSocketFactory.java | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/com/owncloud/android/lib/common/network/AdvancedSslSocketFactory.java b/src/com/owncloud/android/lib/common/network/AdvancedSslSocketFactory.java index 7d6a59b8..9a0d5454 100644 --- a/src/com/owncloud/android/lib/common/network/AdvancedSslSocketFactory.java +++ b/src/com/owncloud/android/lib/common/network/AdvancedSslSocketFactory.java @@ -95,7 +95,7 @@ public class AdvancedSslSocketFactory implements SecureProtocolSocketFactory { throws IOException, UnknownHostException { Socket socket = mSslContext.getSocketFactory().createSocket(host, port, clientHost, clientPort); - ((SSLSocket) socket).setEnabledProtocols(new String[]{"TLSv1", "TLSv1.1", "TLSv1.2"}); + enableSecureProtocols(socket); verifyPeerIdentity(host, port, socket); return socket; } @@ -172,7 +172,7 @@ public class AdvancedSslSocketFactory implements SecureProtocolSocketFactory { SocketFactory socketfactory = mSslContext.getSocketFactory(); Log_OC.d(TAG, " ... with connection timeout " + timeout + " and socket timeout " + params.getSoTimeout()); Socket socket = socketfactory.createSocket(); - ((SSLSocket) socket).setEnabledProtocols(new String[]{"TLSv1", "TLSv1.1", "TLSv1.2"}); + enableSecureProtocols(socket); SocketAddress localaddr = new InetSocketAddress(localAddress, localPort); SocketAddress remoteaddr = new InetSocketAddress(host, port); socket.setSoTimeout(params.getSoTimeout()); @@ -190,11 +190,22 @@ public class AdvancedSslSocketFactory implements SecureProtocolSocketFactory { UnknownHostException { Log_OC.d(TAG, "Creating SSL Socket with remote " + host + ":" + port); Socket socket = mSslContext.getSocketFactory().createSocket(host, port); - ((SSLSocket) socket).setEnabledProtocols(new String[]{"TLSv1", "TLSv1.1", "TLSv1.2"}); + enableSecureProtocols(socket); verifyPeerIdentity(host, port, socket); return socket; } + + @Override + public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException, + UnknownHostException { + Socket sslSocket = mSslContext.getSocketFactory().createSocket(socket, host, port, autoClose); + enableSecureProtocols(sslSocket); + verifyPeerIdentity(host, port, sslSocket); + return sslSocket; + } + + public boolean equals(Object obj) { return ((obj != null) && obj.getClass().equals( AdvancedSslSocketFactory.class)); @@ -309,12 +320,9 @@ public class AdvancedSslSocketFactory implements SecureProtocolSocketFactory { } } - @Override - public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException, - UnknownHostException { - Socket sslSocket = mSslContext.getSocketFactory().createSocket(socket, host, port, autoClose); - ((SSLSocket) sslSocket).setEnabledProtocols(new String[]{"TLSv1", "TLSv1.1", "TLSv1.2"}); - verifyPeerIdentity(host, port, sslSocket); - return sslSocket; - } + + private void enableSecureProtocols(Socket socket) { + ((SSLSocket) socket).setEnabledProtocols(new String[]{"TLSv1", "TLSv1.1", "TLSv1.2"}); + } + } From 9881150410d2afbc0c8511d0403131bd3905c172 Mon Sep 17 00:00:00 2001 From: "David A. Velasco" Date: Mon, 17 Nov 2014 09:56:54 +0100 Subject: [PATCH 19/22] Grant that a security provider supporting TLSv1.2 is requested --- .../android/lib/common/network/NetworkUtils.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/com/owncloud/android/lib/common/network/NetworkUtils.java b/src/com/owncloud/android/lib/common/network/NetworkUtils.java index ad0d0ba0..ea19fc3c 100644 --- a/src/com/owncloud/android/lib/common/network/NetworkUtils.java +++ b/src/com/owncloud/android/lib/common/network/NetworkUtils.java @@ -93,13 +93,22 @@ public class NetworkUtils { } } - public static AdvancedSslSocketFactory getAdvancedSslSocketFactory(Context context) throws GeneralSecurityException, IOException { + public static AdvancedSslSocketFactory getAdvancedSslSocketFactory(Context context) + throws GeneralSecurityException, IOException { if (mAdvancedSslSocketFactory == null) { KeyStore trustStore = getKnownServersStore(context); AdvancedX509TrustManager trustMgr = new AdvancedX509TrustManager(trustStore); TrustManager[] tms = new TrustManager[] { trustMgr }; - SSLContext sslContext = SSLContext.getInstance("TLS"); + SSLContext sslContext; + try { + sslContext = SSLContext.getInstance("TLSv1.2"); + } catch (NoSuchAlgorithmException e) { + Log_OC.w(TAG, "TLSv1.2 is not supported in this device; falling through TLSv1.0"); + sslContext = SSLContext.getInstance("TLSv1"); + // should be available in any device; see reference of supported protocols in + // http://developer.android.com/reference/javax/net/ssl/SSLSocket.html + } sslContext.init(null, tms, null); mHostnameVerifier = new BrowserCompatHostnameVerifier(); From 93e08bc215de6e76c213d8ec2d0b6b8efc19cab8 Mon Sep 17 00:00:00 2001 From: "David A. Velasco" Date: Mon, 17 Nov 2014 10:41:35 +0100 Subject: [PATCH 20/22] Grant that all supported secure protocol is enabled, but no unsupported protocol is tried to be enabled --- .../network/AdvancedSslSocketFactory.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/com/owncloud/android/lib/common/network/AdvancedSslSocketFactory.java b/src/com/owncloud/android/lib/common/network/AdvancedSslSocketFactory.java index 9a0d5454..99c05e68 100644 --- a/src/com/owncloud/android/lib/common/network/AdvancedSslSocketFactory.java +++ b/src/com/owncloud/android/lib/common/network/AdvancedSslSocketFactory.java @@ -36,6 +36,7 @@ import javax.net.SocketFactory; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLException; import javax.net.ssl.SSLHandshakeException; +import javax.net.ssl.SSLParameters; import javax.net.ssl.SSLPeerUnverifiedException; import javax.net.ssl.SSLSession; import javax.net.ssl.SSLSocket; @@ -320,9 +321,22 @@ public class AdvancedSslSocketFactory implements SecureProtocolSocketFactory { } } - + /** + * Grants that all protocols supported by the Security Provider in mSslContext are enabled in socket. + * + * Grants also that no unsupported protocol is tried to be enabled. That would trigger an exception, breaking + * the connection process although some protocols are supported. + * + * This is not cosmetic: not all the supported protocols are enabled by default. Too see an overview of + * supported and enabled protocols in the stock Security Provider in Android see the tables in + * http://developer.android.com/reference/javax/net/ssl/SSLSocket.html. + * + * @param socket + */ private void enableSecureProtocols(Socket socket) { - ((SSLSocket) socket).setEnabledProtocols(new String[]{"TLSv1", "TLSv1.1", "TLSv1.2"}); + SSLParameters params = mSslContext.getSupportedSSLParameters(); + String [] supportedProtocols = params.getProtocols(); + ((SSLSocket) socket).setEnabledProtocols(supportedProtocols); } } From fcf3bd2769db5dd0368fceff28c0971d66f969de Mon Sep 17 00:00:00 2001 From: "David A. Velasco" Date: Mon, 17 Nov 2014 10:47:37 +0100 Subject: [PATCH 21/22] Clean-up at NetworkUtils.java --- .../lib/common/network/NetworkUtils.java | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/com/owncloud/android/lib/common/network/NetworkUtils.java b/src/com/owncloud/android/lib/common/network/NetworkUtils.java index ea19fc3c..aefc3256 100644 --- a/src/com/owncloud/android/lib/common/network/NetworkUtils.java +++ b/src/com/owncloud/android/lib/common/network/NetworkUtils.java @@ -57,6 +57,12 @@ public class NetworkUtils { /** Default timeout for establishing a connection */ public static final int DEFAULT_CONNECTION_TIMEOUT = 60000; + + /** Standard name for protocol TLS version 1.2 in Java Secure Socket Extension (JSSE) API */ + public static final String PROTOCOL_TLSv1_2 = "TLSv1.2"; + + /** Standard name for protocol TLS version 1.0 in JSSE API */ + public static final String PROTOCOL_TLSv1_0 = "TLSv1"; /** Connection manager for all the OwnCloudClients */ private static MultiThreadedHttpConnectionManager mConnManager = null; @@ -72,7 +78,9 @@ public class NetworkUtils { * Registers or unregisters the proper components for advanced SSL handling. * @throws IOException */ - public static void registerAdvancedSslContext(boolean register, Context context) throws GeneralSecurityException, IOException { + @SuppressWarnings("deprecation") + public static void registerAdvancedSslContext(boolean register, Context context) + throws GeneralSecurityException, IOException { Protocol pr = null; try { pr = Protocol.getProtocol("https"); @@ -136,9 +144,11 @@ public class NetworkUtils { * @throws KeyStoreException When the KeyStore instance could not be created. * @throws IOException When an existing local trust store could not be loaded. * @throws NoSuchAlgorithmException When the existing local trust store was saved with an unsupported algorithm. - * @throws CertificateException When an exception occurred while loading the certificates from the local trust store. + * @throws CertificateException When an exception occurred while loading the certificates from the local + * trust store. */ - private static KeyStore getKnownServersStore(Context context) throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException { + private static KeyStore getKnownServersStore(Context context) + throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException { if (mKnownServersStore == null) { //mKnownServersStore = KeyStore.getInstance("BKS"); mKnownServersStore = KeyStore.getInstance(KeyStore.getDefaultType()); @@ -152,15 +162,17 @@ public class NetworkUtils { in.close(); } } else { - mKnownServersStore.load(null, LOCAL_TRUSTSTORE_PASSWORD.toCharArray()); // necessary to initialize an empty KeyStore instance + // next is necessary to initialize an empty KeyStore instance + mKnownServersStore.load(null, LOCAL_TRUSTSTORE_PASSWORD.toCharArray()); } } return mKnownServersStore; } - public static void addCertToKnownServersStore(Certificate cert, Context context) throws KeyStoreException, NoSuchAlgorithmException, - CertificateException, IOException { + public static void addCertToKnownServersStore(Certificate cert, Context context) + throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException { + KeyStore knownServers = getKnownServersStore(context); knownServers.setCertificateEntry(Integer.toString(cert.hashCode()), cert); FileOutputStream fos = null; @@ -182,7 +194,8 @@ public class NetworkUtils { return mConnManager; } - public static boolean isCertInKnownServersStore(Certificate cert, Context context) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException { + public static boolean isCertInKnownServersStore(Certificate cert, Context context) + throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException { KeyStore knownServers = getKnownServersStore(context); Log_OC.d(TAG, "Certificate - HashCode: " + cert.hashCode() + " " From a5a2b2890fd2cb2eb0986f8358bf4f79411a8db4 Mon Sep 17 00:00:00 2001 From: "David A. Velasco" Date: Mon, 17 Nov 2014 12:34:17 +0100 Subject: [PATCH 22/22] Let the setup() - testXXX() - tearDown() flow normally --- .../lib/test_project/test/DeleteFileTest.java | 37 +++++-------- .../test_project/test/DownloadFileTest.java | 54 ++++++++----------- .../lib/test_project/test/RenameFileTest.java | 40 +++++--------- 3 files changed, 48 insertions(+), 83 deletions(-) diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/DeleteFileTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/DeleteFileTest.java index 019cc062..d9a1e6cd 100644 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/DeleteFileTest.java +++ b/test_client/tests/src/com/owncloud/android/lib/test_project/test/DeleteFileTest.java @@ -30,8 +30,6 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; import com.owncloud.android.lib.test_project.TestActivity; -import android.util.Log; - /** * Class to test Delete a File Operation * @author masensio @@ -48,8 +46,6 @@ public class DeleteFileTest extends RemoteTest { /* File to delete. */ private static final String FILE_PATH = "/fileToDelete.txt"; - private static boolean mGlobalSetupDone = false; - private TestActivity mActivity; private String mFullPath2Folder; private String mFullPath2File; @@ -62,26 +58,19 @@ public class DeleteFileTest extends RemoteTest { mFullPath2Folder = mBaseFolderPath + FOLDER_PATH; mFullPath2File = mBaseFolderPath + FILE_PATH; - if (!mGlobalSetupDone) { - - Log.v(LOG_TAG, "Starting global set up"); - RemoteOperationResult result = mActivity.createFolder(mFullPath2Folder, true); - if (!result.isSuccess() && result.getCode() != ResultCode.TIMEOUT) { - Utils.logAndThrow(LOG_TAG, result); - } - - File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME); - result = mActivity.uploadFile( - textFile.getAbsolutePath(), - mFullPath2File, - "txt/plain"); - if (!result.isSuccess()) { - Utils.logAndThrow(LOG_TAG, result); - } - - Log.v(LOG_TAG, "Global set up done"); - mGlobalSetupDone = true; - } + RemoteOperationResult result = mActivity.createFolder(mFullPath2Folder, true); + if (!result.isSuccess() && result.getCode() != ResultCode.TIMEOUT) { + Utils.logAndThrow(LOG_TAG, result); + } + + File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME); + result = mActivity.uploadFile( + textFile.getAbsolutePath(), + mFullPath2File, + "txt/plain"); + if (!result.isSuccess()) { + Utils.logAndThrow(LOG_TAG, result); + } } diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/DownloadFileTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/DownloadFileTest.java index b3e91e97..56e679b9 100644 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/DownloadFileTest.java +++ b/test_client/tests/src/com/owncloud/android/lib/test_project/test/DownloadFileTest.java @@ -31,8 +31,6 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; import com.owncloud.android.lib.test_project.TestActivity; -import android.util.Log; - /** * Class to test Download File Operation * @author masensio @@ -49,8 +47,6 @@ public class DownloadFileTest extends RemoteTest { private static final String IMAGE_PATH_WITH_SPECIAL_CHARS = "/@file@download.png"; private static final String IMAGE_NOT_FOUND = "/fileNotFound.png"; - private static boolean mGlobalSetupDone = false; - private String mFullPath2Image; private String mFullPath2ImageWitSpecialChars; private String mFullPath2ImageNotFound; @@ -68,35 +64,29 @@ public class DownloadFileTest extends RemoteTest { mFullPath2ImageWitSpecialChars = mBaseFolderPath + IMAGE_PATH_WITH_SPECIAL_CHARS; mFullPath2ImageNotFound = mBaseFolderPath + IMAGE_NOT_FOUND; - if (!mGlobalSetupDone) { - - File imageFile = mActivity.extractAsset(TestActivity.ASSETS__IMAGE_FILE_NAME); + File imageFile = mActivity.extractAsset(TestActivity.ASSETS__IMAGE_FILE_NAME); - RemoteOperationResult result = mActivity.uploadFile( - imageFile.getAbsolutePath(), - mFullPath2Image, - "image/png"); - if (!result.isSuccess()) { - Utils.logAndThrow(LOG_TAG, result); - } - - result = mActivity.uploadFile( - imageFile.getAbsolutePath(), - mFullPath2ImageWitSpecialChars, - "image/png"); - if (!result.isSuccess()) { - Utils.logAndThrow(LOG_TAG, result); - } - - result = mActivity.removeFile(mFullPath2ImageNotFound); - if (!result.isSuccess() && result.getCode() != ResultCode.FILE_NOT_FOUND) { - Utils.logAndThrow(LOG_TAG, result); - } - - Log.v(LOG_TAG, "Global set up done"); - mGlobalSetupDone = true; - } - + RemoteOperationResult result = mActivity.uploadFile( + imageFile.getAbsolutePath(), + mFullPath2Image, + "image/png"); + if (!result.isSuccess()) { + Utils.logAndThrow(LOG_TAG, result); + } + + result = mActivity.uploadFile( + imageFile.getAbsolutePath(), + mFullPath2ImageWitSpecialChars, + "image/png"); + if (!result.isSuccess()) { + Utils.logAndThrow(LOG_TAG, result); + } + + result = mActivity.removeFile(mFullPath2ImageNotFound); + if (!result.isSuccess() && result.getCode() != ResultCode.FILE_NOT_FOUND) { + Utils.logAndThrow(LOG_TAG, result); + } + } /** diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/RenameFileTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/RenameFileTest.java index 4a6ca60f..e14bc11f 100644 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/RenameFileTest.java +++ b/test_client/tests/src/com/owncloud/android/lib/test_project/test/RenameFileTest.java @@ -31,8 +31,6 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCo import com.owncloud.android.lib.resources.files.FileUtils; import com.owncloud.android.lib.test_project.TestActivity; -import android.util.Log; - /** * Class to test Rename File Operation * @author masensio @@ -56,8 +54,6 @@ public class RenameFileTest extends RemoteTest { private static final String NEW_FILE_PATH = FileUtils.PATH_SEPARATOR + NEW_FILE_NAME; - private static boolean mGlobalSetupDone = false; - private String mToCleanUpInServer; private TestActivity mActivity; private String mFullPath2OldFolder; @@ -74,28 +70,20 @@ public class RenameFileTest extends RemoteTest { mFullPath2NewFolder = mBaseFolderPath + NEW_FOLDER_PATH; mFullPath2OldFile = mBaseFolderPath + OLD_FILE_PATH; mFullPath2NewFile = mBaseFolderPath + NEW_FILE_PATH; - - if (!mGlobalSetupDone) { - - Log.v(LOG_TAG, "Starting global set up"); - RemoteOperationResult result = mActivity.createFolder(mFullPath2OldFolder, true); - if (!result.isSuccess() && result.getCode() != ResultCode.TIMEOUT) { - Utils.logAndThrow(LOG_TAG, result); - } - - File imageFile = mActivity.extractAsset(TestActivity.ASSETS__IMAGE_FILE_NAME); - result = mActivity.uploadFile( - imageFile.getAbsolutePath(), - mFullPath2OldFile, - "image/png"); - if (!result.isSuccess()) { - Utils.logAndThrow(LOG_TAG, result); - } - - Log.v(LOG_TAG, "Global set up done"); - mGlobalSetupDone = true; - } + RemoteOperationResult result = mActivity.createFolder(mFullPath2OldFolder, true); + if (!result.isSuccess() && result.getCode() != ResultCode.TIMEOUT) { + Utils.logAndThrow(LOG_TAG, result); + } + + File imageFile = mActivity.extractAsset(TestActivity.ASSETS__IMAGE_FILE_NAME); + result = mActivity.uploadFile( + imageFile.getAbsolutePath(), + mFullPath2OldFile, + "image/png"); + if (!result.isSuccess()) { + Utils.logAndThrow(LOG_TAG, result); + } mToCleanUpInServer = null; } @@ -232,14 +220,12 @@ public class RenameFileTest extends RemoteTest { @Override protected void tearDown() throws Exception { - /* if (mToCleanUpInServer != null) { RemoteOperationResult removeResult = mActivity.removeFile(mToCleanUpInServer); if (!removeResult.isSuccess()) { Utils.logAndThrow(LOG_TAG, removeResult); } } - */ super.tearDown(); }