<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
+ <uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.INTERNET"/>
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-sdk
android:minSdkVersion="8"
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
- <classpathentry combineaccessrules="false" exported="true" kind="src" path="/oc_framework-test-project"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/oc_framework-test-project"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
import java.util.Date;
import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
+import com.owncloud.android.oc_framework.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.oc_framework_test_project.TestActivity;
import android.test.ActivityInstrumentationTestCase2;
-import android.util.Log;
public class CreateFolderTest extends ActivityInstrumentationTestCase2<TestActivity> {
boolean createFullPath = true;
RemoteOperationResult result = mActivity.createFolder(remotePath, createFullPath);
- Log.d("test CreateFolder", "-----------------------" + result.getCode().name());
- Log.d("test CreateFolder", "-----------------------" + result.getLogMessage());
- assertTrue(result.isSuccess());
+ assertTrue(result.isSuccess() || result.getCode() == ResultCode.TIMEOUT);
}
- public void testCreateFolderSpecialCharacters() {
- String remotePath = "/test^^SpecialCharacters" + mCurrentDate;
+ public void testCreateFolderSpecialCharacters() {
boolean createFullPath = true;
+ String remotePath = "/testSpecialCharacters_//" + mCurrentDate;
RemoteOperationResult result = mActivity.createFolder(remotePath, createFullPath);
- assertFalse(result.isSuccess());
+ assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
+
+ remotePath = "/testSpecialCharacters_\\" + mCurrentDate;
+ result = mActivity.createFolder(remotePath, createFullPath);
+ assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
+
+ remotePath = "/testSpecialCharacters_<" + mCurrentDate;
+ result = mActivity.createFolder(remotePath, createFullPath);
+ assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
+
+ remotePath = "/testSpecialCharacters_>" + mCurrentDate;
+ result = mActivity.createFolder(remotePath, createFullPath);
+ assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
+
+ remotePath = "/testSpecialCharacters_:" + mCurrentDate;
+ result = mActivity.createFolder(remotePath, createFullPath);
+ assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
+
+ remotePath = "/testSpecialCharacters_\"" + mCurrentDate;
+ result = mActivity.createFolder(remotePath, createFullPath);
+ assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
+
+ remotePath = "/testSpecialCharacters_|" + mCurrentDate;
+ result = mActivity.createFolder(remotePath, createFullPath);
+ assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
+
+ remotePath = "/testSpecialCharacters_?" + mCurrentDate;
+ result = mActivity.createFolder(remotePath, createFullPath);
+ assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
+
+ remotePath = "/testSpecialCharacters_*" + mCurrentDate;
+ result = mActivity.createFolder(remotePath, createFullPath);
+ assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
}
import java.io.IOException;
-import com.owncloud.android.oc_framework.authentication.AccountUtils.AccountNotFoundException;
-import com.owncloud.android.oc_framework.network.OwnCloudClientUtils;
+import com.owncloud.android.oc_framework.accounts.AccountUtils.AccountNotFoundException;
+import com.owncloud.android.oc_framework.network.webdav.OwnCloudClientFactory;
import com.owncloud.android.oc_framework.network.webdav.WebdavClient;
import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
import com.owncloud.android.oc_framework.operations.remote.CreateRemoteFolderOperation;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
+ // This account must exists on the simulator / device
String accountHost = "beta.owncloud.com";
String accountUser = "masensio";
String accountName = accountUser + "@"+ accountHost;
String accountPass = "masensio";
String accountType = "owncloud";
- String authorities = "org.owncloud";
AccountManager am = AccountManager.get(this);
}
}
- if (mAccount == null) {
- mAccount = new Account(accountName, accountType);
- am.addAccountExplicitly(mAccount, accountPass, null);
- am.setUserData(mAccount, "oc_version", "5.0.14");
- am.setUserData(mAccount, "oc_base_url", "http://beta.owncloud.com/owncloud");
- } else {
+// if (mAccount == null) {
+// mAccount = new Account(accountName, accountType);
+// am.addAccountExplicitly(mAccount, accountPass, null);
+// am.setUserData(mAccount, "oc_version", "5.0.14");
+// am.setUserData(mAccount, "oc_base_url", "http://beta.owncloud.com/owncloud");
+// } else {
Log.d(TAG, "oc_version --->"+ am.getUserData(mAccount, "oc_version") );
Log.d(TAG, "oc_base_url --->"+ am.getUserData(mAccount, "oc_base_url") );
- }
+// }
try {
- mClient = OwnCloudClientUtils.createOwnCloudClient(mAccount, this.getApplicationContext(), authorities);
+ mClient = OwnCloudClientFactory.createOwnCloudClient(mAccount, this.getApplicationContext());
} catch (OperationCanceledException e) {
Log.e(TAG, "Error while trying to access to " + mAccount.name, e);
e.printStackTrace();
ACCOUNT_NOT_FOUND,
ACCOUNT_EXCEPTION,
ACCOUNT_NOT_NEW,
- ACCOUNT_NOT_THE_SAME
+ ACCOUNT_NOT_THE_SAME,
+ INVALID_CHARACTER_IN_NAME
}
private boolean mSuccess = false;
} else if (mCode == ResultCode.ACCOUNT_NOT_THE_SAME) {
return "Authenticated with a different account than the one updating";
+ } else if (mCode == ResultCode.INVALID_CHARACTER_IN_NAME) {
+ return "The file name contains an forbidden character";
}
return "Operation finished with HTTP status code " + mHttpCode + " (" + (isSuccess() ? "success" : "fail") + ")";
package com.owncloud.android.oc_framework.operations.remote;
-import java.io.File;
-
import org.apache.commons.httpclient.HttpStatus;
import org.apache.jackrabbit.webdav.client.methods.MkColMethod;
import com.owncloud.android.oc_framework.network.webdav.WebdavUtils;
import com.owncloud.android.oc_framework.operations.RemoteOperation;
import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
+import com.owncloud.android.oc_framework.operations.RemoteOperationResult.ResultCode;
+import com.owncloud.android.oc_framework.utils.FileUtils;
private static final int READ_TIMEOUT = 10000;
private static final int CONNECTION_TIMEOUT = 5000;
- private static final String PATH_SEPARATOR = "/";
+
protected String mRemotePath;
protected boolean mCreateFullPath;
RemoteOperationResult result = null;
MkColMethod mkcol = null;
- try {
- mkcol = new MkColMethod(client.getBaseUri() + WebdavUtils.encodePath(mRemotePath));
- int status = client.executeMethod(mkcol, READ_TIMEOUT, CONNECTION_TIMEOUT);
- if (!mkcol.succeeded() && mkcol.getStatusCode() == HttpStatus.SC_CONFLICT && mCreateFullPath) {
- result = createParentFolder(getParentPath(), client);
- status = client.executeMethod(mkcol, READ_TIMEOUT, CONNECTION_TIMEOUT); // second (and last) try
- }
-
- result = new RemoteOperationResult(mkcol.succeeded(), status, mkcol.getResponseHeaders());
- Log.d(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage());
- client.exhaustResponse(mkcol.getResponseBodyAsStream());
-
- } catch (Exception e) {
- result = new RemoteOperationResult(e);
- Log.e(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage(), e);
-
- } finally {
- if (mkcol != null)
- mkcol.releaseConnection();
+ boolean noInvalidChars = FileUtils.validateName(mRemotePath);
+ if (noInvalidChars) {
+ try {
+ mkcol = new MkColMethod(client.getBaseUri() + WebdavUtils.encodePath(mRemotePath));
+ int status = client.executeMethod(mkcol, READ_TIMEOUT, CONNECTION_TIMEOUT);
+ if (!mkcol.succeeded() && mkcol.getStatusCode() == HttpStatus.SC_CONFLICT && mCreateFullPath) {
+ result = createParentFolder(FileUtils.getParentPath(mRemotePath), client);
+ status = client.executeMethod(mkcol, READ_TIMEOUT, CONNECTION_TIMEOUT); // second (and last) try
+ }
+
+ result = new RemoteOperationResult(mkcol.succeeded(), status, mkcol.getResponseHeaders());
+ Log.d(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage());
+ client.exhaustResponse(mkcol.getResponseBodyAsStream());
+
+ } catch (Exception e) {
+ result = new RemoteOperationResult(e);
+ Log.e(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage(), e);
+
+ } finally {
+ if (mkcol != null)
+ mkcol.releaseConnection();
+ }
+ } else {
+ result = new RemoteOperationResult(ResultCode.INVALID_CHARACTER_IN_NAME);
}
+
return result;
}
return operation.execute(client);
}
- private String getParentPath() {
- String parentPath = new File(mRemotePath).getParent();
- parentPath = parentPath.endsWith(PATH_SEPARATOR) ? parentPath : parentPath + PATH_SEPARATOR;
- return parentPath;
- }
+
}
# Project target.
target=android-19
-android.library.reference.1=actionbarsherlock/library
+android.library.reference.1=actionbarsherlock\\library
android.library.reference.2=oc_framework
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
+ <classpathentry combineaccessrules="false" kind="src" path="/owncloud-android"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
import android.test.AndroidTestCase;
-import com.owncloud.android.authentication.AccountUtils;
-import com.owncloud.android.utils.OwnCloudVersion;
+import com.owncloud.android.oc_framework.accounts.AccountUtils;
+import com.owncloud.android.oc_framework.utils.OwnCloudVersion;
public class AccountUtilsTest extends AndroidTestCase {