diff --git a/src/com/owncloud/android/lib/common/OwnCloudClient.java b/src/com/owncloud/android/lib/common/OwnCloudClient.java index ace942e4..e6696ef0 100644 --- a/src/com/owncloud/android/lib/common/OwnCloudClient.java +++ b/src/com/owncloud/android/lib/common/OwnCloudClient.java @@ -284,6 +284,9 @@ public class OwnCloudClient extends HttpClient { * @param uri */ public void setBaseUri(Uri uri) { + if (uri == null) { + throw new IllegalArgumentException("URI cannot be NULL"); + } mBaseUri = uri; } diff --git a/src/com/owncloud/android/lib/common/operations/RemoteOperation.java b/src/com/owncloud/android/lib/common/operations/RemoteOperation.java index 1384bd7a..bef4b86c 100644 --- a/src/com/owncloud/android/lib/common/operations/RemoteOperation.java +++ b/src/com/owncloud/android/lib/common/operations/RemoteOperation.java @@ -281,7 +281,6 @@ public abstract class RemoteOperation implements Runnable { /** DEPRECATED BLOCK - will be removed at version 1.0 ; don't trust in this code * to trigger authentication update */ if (mCallerActivity != null && mAccount != null && mContext != null && !result.isSuccess() && -// (result.getCode() == ResultCode.UNAUTHORIZED || (result.isTemporalRedirection() && result.isIdPRedirection()))) { (result.getCode() == ResultCode.UNAUTHORIZED || result.isIdPRedirection())) { /// possible fail due to lack of authorization in an operation performed in foreground OwnCloudCredentials cred = mClient.getCredentials(); diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/OwnCloudClientTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/OwnCloudClientTest.java index 476a8ceb..43de601a 100644 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/OwnCloudClientTest.java +++ b/test_client/tests/src/com/owncloud/android/lib/test_project/test/OwnCloudClientTest.java @@ -303,6 +303,9 @@ public class OwnCloudClientTest extends AndroidTestCase { assertTrue("WebDAV URI does not point to the right entry point for OAuth2 " + "authenticated servers", webdavUri.getPath().endsWith(AccountUtils.ODAV_PATH)); + assertTrue("WebDAV URI is not a subpath of base URI", + webdavUri.getAuthority().equals(mServerUri.getAuthority()) && + webdavUri.getPath().startsWith(mServerUri.getPath())); client.setCredentials(OwnCloudCredentialsFactory.newBasicCredentials( mUsername, mPassword)); @@ -331,21 +334,24 @@ public class OwnCloudClientTest extends AndroidTestCase { public void testGetSetBaseUri() { - // TODO implement test body - /** - * Sets the root URI to the ownCloud server. - * - * Use with care. - * - * @param uri - *-/ - public void setBaseUri(Uri uri) { - mBaseUri = uri; - } - public Uri getBaseUri() { - return mBaseUri; - } - */ + OwnCloudClient client = + new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager()); + assertEquals("Returned base URI different that URI passed to constructor", + mServerUri, client.getBaseUri()); + + Uri otherUri = Uri.parse("https://whatever.com/basePath/here"); + client.setBaseUri(otherUri); + assertEquals("Returned base URI different that URI passed to constructor", + otherUri, client.getBaseUri()); + + try { + client.setBaseUri(null); + throw new AssertionFailedError("Accepted NULL parameter"); + + } catch(Exception e) { + assertTrue("Unexpected exception passing NULL base URI", + (e instanceof IllegalArgumentException)); + } } @@ -368,8 +374,7 @@ public class OwnCloudClientTest extends AndroidTestCase { public void testSetFollowRedirects() { - // TODO implement test body - // to implement this we need a redirected server + // TODO - to implement this test we need a redirected server }