diff --git a/src/com/owncloud/android/lib/common/network/AdvancedSslSocketFactory.java b/src/com/owncloud/android/lib/common/network/AdvancedSslSocketFactory.java
index b411c02d..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;
@@ -78,8 +79,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;
@@ -92,6 +96,7 @@ public class AdvancedSslSocketFactory implements SecureProtocolSocketFactory {
throws IOException, UnknownHostException {
Socket socket = mSslContext.getSocketFactory().createSocket(host, port, clientHost, clientPort);
+ enableSecureProtocols(socket);
verifyPeerIdentity(host, port, socket);
return socket;
}
@@ -168,6 +173,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();
+ enableSecureProtocols(socket);
SocketAddress localaddr = new InetSocketAddress(localAddress, localPort);
SocketAddress remoteaddr = new InetSocketAddress(host, port);
socket.setSoTimeout(params.getSoTimeout());
@@ -185,10 +191,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);
+ 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));
@@ -303,11 +321,22 @@ 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);
- verifyPeerIdentity(host, port, sslSocket);
- return sslSocket;
- }
+ /**
+ * 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) {
+ SSLParameters params = mSslContext.getSupportedSSLParameters();
+ String [] supportedProtocols = params.getProtocols();
+ ((SSLSocket) socket).setEnabledProtocols(supportedProtocols);
+ }
+
}
diff --git a/src/com/owncloud/android/lib/common/network/NetworkUtils.java b/src/com/owncloud/android/lib/common/network/NetworkUtils.java
index ad0d0ba0..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");
@@ -93,13 +101,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();
@@ -127,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());
@@ -143,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;
@@ -173,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() + " "
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/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;
}
/**
diff --git a/test_client/tests/custom_rules.xml b/test_client/tests/custom_rules.xml
index c771dcd6..1849940c 100644
--- a/test_client/tests/custom_rules.xml
+++ b/test_client/tests/custom_rules.xml
@@ -1,5 +1,6 @@
+
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..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,15 +31,13 @@ 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();
@@ -49,36 +45,33 @@ public class CreateFolderTest extends ActivityInstrumentationTestCase2 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);
}
@@ -130,7 +123,7 @@ public class CreateFolderTest extends ActivityInstrumentationTestCase2 {
+public class CreateShareTest extends RemoteTest {
private static final String LOG_TAG = CreateShareTest.class.getCanonicalName();
@@ -40,22 +39,19 @@ public class CreateShareTest extends ActivityInstrumentationTestCase2 {
+public class DeleteFileTest extends RemoteTest {
private static final String LOG_TAG = DeleteFileTest.class.getCanonicalName();
@@ -48,40 +46,31 @@ public class DeleteFileTest extends ActivityInstrumentationTestCase2 {
+public class DownloadFileTest extends RemoteTest {
private static final String LOG_TAG = DownloadFileTest.class.getCanonicalName();
@@ -49,49 +46,47 @@ public class DownloadFileTest extends ActivityInstrumentationTestCase2 {
+public class GetSharesTest extends RemoteTest {
private static final String LOG_TAG = GetSharesTest.class.getCanonicalName();
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);
- if (!result.isSuccess()) {
+ result = mActivity.createShare(mFullPath2SharedFile, ShareType.PUBLIC_LINK, "", false, "", 1);
+ if (!result.isSuccess() && result.getCode() != ResultCode.TIMEOUT) {
Utils.logAndThrow(LOG_TAG, result);
}
@@ -86,8 +82,8 @@ public class GetSharesTest extends ActivityInstrumentationTestCase2 {
+public class MoveFileTest extends RemoteTest {
private static final String LOG_TAG = MoveFileTest.class.getCanonicalName();
@@ -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,8 +242,8 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2
RemoteOperationResult result = null;
for (String folderPath : FOLDERS_IN_FIXTURE) {
- result = TestActivity.createFolder(folderPath, true, mClient);
- if (!result.isSuccess()) {
+ 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 c8a39401..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
@@ -26,27 +26,23 @@ 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;
-
/**
* 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.txt";
-
- public ReadFileTest() {
- super(TestActivity.class);
- }
+ private String mFullPath2File;
@Override
protected void setUp() throws Exception {
@@ -54,11 +50,12 @@ public class ReadFileTest extends ActivityInstrumentationTestCase2 {
+public class ReadFolderTest extends RemoteTest {
private static final String LOG_TAG = ReadFolderTest.class.getCanonicalName();
@@ -50,24 +49,22 @@ public class ReadFolderTest extends ActivityInstrumentationTestCase2 1);
assertTrue(result.getData().size() == 4);
@@ -93,8 +90,8 @@ 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 27a5fd61..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
@@ -29,41 +29,38 @@ import java.io.File;
import com.owncloud.android.lib.resources.shares.OCShare;
import com.owncloud.android.lib.resources.shares.ShareType;
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.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 {
@@ -84,8 +81,8 @@ public class RemoveShareTest extends ActivityInstrumentationTestCase2 {
+public class RenameFileTest extends RemoteTest {
private static final String LOG_TAG = RenameFileTest.class.getCanonicalName();
@@ -57,42 +54,36 @@ 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 +145,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 5a69f0d2..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,9 +26,8 @@ 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;
/**
@@ -38,7 +37,7 @@ 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();
@@ -54,10 +53,6 @@ public class UploadFileTest extends ActivityInstrumentationTestCase2