From dad5cd115af2c1eb050599b6b14a0480dbb56721 Mon Sep 17 00:00:00 2001 From: "David A. Velasco" Date: Thu, 10 Dec 2015 14:18:00 +0100 Subject: [PATCH 1/5] Added constants to analyze share permissions --- src/com/owncloud/android/lib/resources/shares/OCShare.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/com/owncloud/android/lib/resources/shares/OCShare.java b/src/com/owncloud/android/lib/resources/shares/OCShare.java index 347bd1ae..7bbb0724 100644 --- a/src/com/owncloud/android/lib/resources/shares/OCShare.java +++ b/src/com/owncloud/android/lib/resources/shares/OCShare.java @@ -47,6 +47,11 @@ public class OCShare implements Parcelable, Serializable { private static final String TAG = OCShare.class.getSimpleName(); public static final int DEFAULT_PERMISSION = -1; + public static final int READ_PERMISSION_FLAG = 1; + public static final int UPDATE_PERMISSION_FLAG = 2; + public static final int CREATE_PERMISSION_FLAG = 4; + public static final int DELETE_PERMISSION_FLAG = 8; + public static final int SHARE_PERMISSION_FLAG = 16; private long mId; private long mFileSource; From 249cb901ebd392373d0ef812b8f0a2489705c0ea Mon Sep 17 00:00:00 2001 From: "David A. Velasco" Date: Wed, 16 Dec 2015 16:32:48 +0100 Subject: [PATCH 2/5] Added support to update share permissions --- .../shares/SharePermissionsBuilder.java | 106 ++++++++++++++++++ .../shares/UpdateRemoteShareOperation.java | 23 +++- 2 files changed, 125 insertions(+), 4 deletions(-) create mode 100644 src/com/owncloud/android/lib/resources/shares/SharePermissionsBuilder.java diff --git a/src/com/owncloud/android/lib/resources/shares/SharePermissionsBuilder.java b/src/com/owncloud/android/lib/resources/shares/SharePermissionsBuilder.java new file mode 100644 index 00000000..85fcf7ff --- /dev/null +++ b/src/com/owncloud/android/lib/resources/shares/SharePermissionsBuilder.java @@ -0,0 +1,106 @@ +/* ownCloud Android Library is available under MIT license + * @author David A. Velasco + * Copyright (C) 2015 ownCloud Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +package com.owncloud.android.lib.resources.shares; + + +/** + * Provides method to define a set of share permissions and calculate the appropiate + * int value representing it. + */ +public class SharePermissionsBuilder { + + /** Set of permissions */ + private int mPermissions = OCShare.READ_PERMISSION_FLAG; // READ is minimum permission + + /** + * Sets or clears permission to reshare a file or folder. + * + * @param enabled 'True' to set, 'false' to clear. + * @return Instance to builder itself, to allow consecutive calls to setters + */ + public SharePermissionsBuilder setSharePermission(boolean enabled) { + updatePermission(OCShare.SHARE_PERMISSION_FLAG, enabled); + return this; + } + + /** + * Sets or clears permission to update a folder or folder. + * + * @param enabled 'True' to set, 'false' to clear. + * @return Instance to builder itself, to allow consecutive calls to setters + */ + public SharePermissionsBuilder setUpdatePermission(boolean enabled) { + updatePermission(OCShare.UPDATE_PERMISSION_FLAG, enabled); + return this; + } + + /** + * Sets or clears permission to create files in share folder. + * + * @param enabled 'True' to set, 'false' to clear. + * @return Instance to builder itself, to allow consecutive calls to setters + */ + public SharePermissionsBuilder setCreatePermission(boolean enabled) { + updatePermission(OCShare.CREATE_PERMISSION_FLAG, enabled); + return this; + } + + /** + * Sets or clears permission to delete files in a shared folder. + * + * @param enabled 'True' to set, 'false' to clear. + * @return Instance to builder itself, to allow consecutive calls to setters + */ + public SharePermissionsBuilder setDeletePermission(boolean enabled) { + updatePermission(OCShare.DELETE_PERMISSION_FLAG, enabled); + return this; + } + + /** + * Common code to update the value of the set of permissions. + * + * @param permissionsFlag Flag for the permission to update. + * @param enable 'True' to set, 'false' to clear. + */ + private void updatePermission(int permissionsFlag, boolean enable) { + if (enable) { + // add permission + mPermissions |= permissionsFlag; + } else { + // delete permission + mPermissions &= ~permissionsFlag; + } + } + + /** + * 'Builds' the int value for the accumulated set of permissions. + * + * @return An int value representing the accumulated set of permissions. + */ + public int build() { + return mPermissions; + } +} diff --git a/src/com/owncloud/android/lib/resources/shares/UpdateRemoteShareOperation.java b/src/com/owncloud/android/lib/resources/shares/UpdateRemoteShareOperation.java index aa6ae537..00178ed8 100644 --- a/src/com/owncloud/android/lib/resources/shares/UpdateRemoteShareOperation.java +++ b/src/com/owncloud/android/lib/resources/shares/UpdateRemoteShareOperation.java @@ -56,6 +56,7 @@ public class UpdateRemoteShareOperation extends RemoteOperation { private static final String PARAM_PASSWORD = "password"; private static final String PARAM_EXPIRATION_DATE = "expireDate"; + private static final String PARAM_PERMISSIONS = "permissions"; private static final String FORMAT_EXPIRATION_DATE = "yyyy-MM-dd"; private static final String ENTITY_CONTENT_TYPE = "application/x-www-form-urlencoded"; private static final String ENTITY_CHARSET = "UTF-8"; @@ -70,6 +71,9 @@ public class UpdateRemoteShareOperation extends RemoteOperation { /** Expiration date to set for the public link */ private long mExpirationDateInMillis; + /** Access permissions for the file bound to the share */ + private int mPermissions; + /** * Constructor. No update is initialized by default, need to be applied with setters below. @@ -98,7 +102,7 @@ public class UpdateRemoteShareOperation extends RemoteOperation { /** * Set expiration date to update in Share resource. * - * @param expirationDateInMillis Expiration date to set to the public link. + * @param expirationDateInMillis Expiration date to set to the target share. * A negative value clears the current expiration date. * Zero value (start-of-epoch) results in no update done on * the expiration date. @@ -108,6 +112,16 @@ public class UpdateRemoteShareOperation extends RemoteOperation { } + /** + * Set permissions to update in Share resource. + * + * @param permissions Permissions date to set to the target share. + * Values <= 0 result in no update applied to the permissions. + */ + public void setPermissions(int permissions) { + mPermissions = permissions; + } + @Override protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result = null; @@ -131,11 +145,12 @@ public class UpdateRemoteShareOperation extends RemoteOperation { parametersToUpdate.add(new Pair(PARAM_EXPIRATION_DATE, formattedExpirationDate)); } // else, ignore - no update + if (mPermissions > 0) { + // set permissions + parametersToUpdate.add(new Pair(PARAM_PERMISSIONS, Integer.toString(mPermissions))); + } /* TODO complete rest of parameters - if (mPermissions > 0) { - parametersToUpdate.add(new Pair("permissions", Integer.toString(mPermissions))); - } if (mPublicUpload != null) { parametersToUpdate.add(new Pair("publicUpload", mPublicUpload.toString()); } From 275c042f7884f8a56cb4b5cb94ef9be98884e698 Mon Sep 17 00:00:00 2001 From: "David A. Velasco" Date: Mon, 18 Jan 2016 13:54:45 +0100 Subject: [PATCH 3/5] Added constants for maximum Share permissions --- .../shares/GetRemoteSharesForFileOperation.java | 6 +++--- .../owncloud/android/lib/resources/shares/OCShare.java | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.java b/src/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.java index 8e9b2170..c2019f7a 100644 --- a/src/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.java +++ b/src/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.java @@ -56,9 +56,9 @@ public class GetRemoteSharesForFileOperation extends RemoteOperation { * Constructor * * @param remoteFilePath Path to file or folder - * @param reshares If set to false (default), only shares from the current user are - * returned - * If set to true, all shares from the given file are returned + * @param reshares If set to false (default), only shares owned by the current user are + * returned. + * If set to true, shares owned by any user from the given file are returned. * @param subfiles If set to false (default), lists only the folder being shared * If set to true, all shared files within the folder are returned. */ diff --git a/src/com/owncloud/android/lib/resources/shares/OCShare.java b/src/com/owncloud/android/lib/resources/shares/OCShare.java index 7bbb0724..0fe3aeb2 100644 --- a/src/com/owncloud/android/lib/resources/shares/OCShare.java +++ b/src/com/owncloud/android/lib/resources/shares/OCShare.java @@ -52,6 +52,16 @@ public class OCShare implements Parcelable, Serializable { public static final int CREATE_PERMISSION_FLAG = 4; public static final int DELETE_PERMISSION_FLAG = 8; public static final int SHARE_PERMISSION_FLAG = 16; + public static final int MAXIMUM_PERMISSIONS_FOR_FILE = + READ_PERMISSION_FLAG + + UPDATE_PERMISSION_FLAG + + SHARE_PERMISSION_FLAG + ; + public static final int MAXIMUM_PERMISSIONS_FOR_FOLDER = + MAXIMUM_PERMISSIONS_FOR_FILE + + CREATE_PERMISSION_FLAG + + DELETE_PERMISSION_FLAG + ; private long mId; private long mFileSource; From b3535a3678018fc4ffd51865d53cb0d904b05112 Mon Sep 17 00:00:00 2001 From: "David A. Velasco" Date: Tue, 26 Jan 2016 18:39:01 +0100 Subject: [PATCH 4/5] Updated automatic tests to cover share permissions updates --- .../test/UpdatePrivateShareTest.java | 252 ++++++++++++++++++ ...reTest.java => UpdatePublicShareTest.java} | 16 +- 2 files changed, 261 insertions(+), 7 deletions(-) create mode 100644 test_client/tests/src/com/owncloud/android/lib/test_project/test/UpdatePrivateShareTest.java rename test_client/tests/src/com/owncloud/android/lib/test_project/test/{UpdateShareTest.java => UpdatePublicShareTest.java} (95%) diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/UpdatePrivateShareTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/UpdatePrivateShareTest.java new file mode 100644 index 00000000..60b1d141 --- /dev/null +++ b/test_client/tests/src/com/owncloud/android/lib/test_project/test/UpdatePrivateShareTest.java @@ -0,0 +1,252 @@ +/* ownCloud Android Library is available under MIT license + * @author masensio + * @author David A. Velasco + * Copyright (C) 2015 ownCloud Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +package com.owncloud.android.lib.test_project.test; + +import java.io.File; +import java.security.GeneralSecurityException; +import java.util.Calendar; + +import junit.framework.AssertionFailedError; + +import org.apache.commons.httpclient.protocol.Protocol; +import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; + +import android.content.Context; +import android.net.Uri; +import android.util.Log; + +import com.owncloud.android.lib.common.OwnCloudClient; +import com.owncloud.android.lib.common.OwnCloudClientFactory; +import com.owncloud.android.lib.common.OwnCloudCredentialsFactory; +import com.owncloud.android.lib.common.network.NetworkUtils; +import com.owncloud.android.lib.common.operations.RemoteOperationResult; +import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; +import com.owncloud.android.lib.resources.shares.OCShare; +import com.owncloud.android.lib.resources.shares.RemoveRemoteShareOperation; +import com.owncloud.android.lib.resources.shares.ShareType; +import com.owncloud.android.lib.resources.shares.UpdateRemoteShareOperation; +import com.owncloud.android.lib.test_project.R; +import com.owncloud.android.lib.test_project.SelfSignedConfidentSslSocketFactory; +import com.owncloud.android.lib.test_project.TestActivity; + +/** + * Class to test UpdateRemoteShareOperation + * with private shares + * + */ +public class UpdatePrivateShareTest extends RemoteTest { + private static final String LOG_TAG = UpdatePrivateShareTest.class.getCanonicalName(); + + /* File to share and update */ + private static final String FILE_TO_SHARE = "/fileToShare.txt"; + + /* Folder to share and update */ + private static final String FOLDER_TO_SHARE = "/folderToShare"; + + /* Sharees */ + private static final String USER_SHAREE = "admin"; + private static final String GROUP_SHAREE = "admin"; + + private String mFullPath2FileToShare; + private String mFullPath2FolderToShare; + + private OCShare mFileShare; + private OCShare mFolderShare; + + String mServerUri, mUser, mPass; + OwnCloudClient mClient = null; + + public UpdatePrivateShareTest(){ + super(); + + Protocol pr = Protocol.getProtocol("https"); + if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) { + try { + ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory(); + Protocol.registerProtocol( + "https", + new Protocol("https", psf, 443)); + + } catch (GeneralSecurityException e) { + throw new AssertionFailedError( + "Self-signed confident SSL context could not be loaded"); + } + } + } + + protected Context getContext() { + return getActivity(); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + + // Next initialization cannot be done in the constructor because getContext() is not + // ready yet, returns NULL. + initAccessToServer(getContext()); + + Log.v(LOG_TAG, "Setting up the remote fixture..."); + + // Upload the file + mFullPath2FileToShare = mBaseFolderPath + FILE_TO_SHARE; + + File textFile = getActivity().extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME); + RemoteOperationResult result = getActivity().uploadFile( + textFile.getAbsolutePath(), + mFullPath2FileToShare, + "txt/plain"); + if (!result.isSuccess()) { + Utils.logAndThrow(LOG_TAG, result); + } + + // Share the file privately with other user + result = getActivity().createShare( + mFullPath2FileToShare, + ShareType.USER, + USER_SHAREE, + false, + "", + OCShare.MAXIMUM_PERMISSIONS_FOR_FILE); + + if (result.isSuccess()){ + mFileShare = (OCShare) result.getData().get(0); + } else{ + mFileShare = null; + } + + // Create the folder + mFullPath2FolderToShare = mBaseFolderPath + FOLDER_TO_SHARE; + result = getActivity().createFolder( + mFullPath2FolderToShare, + true); + if (!result.isSuccess()) { + Utils.logAndThrow(LOG_TAG, result); + } + + // Share the folder privately with a group + result = getActivity().createShare( + mFullPath2FolderToShare, + ShareType.GROUP, + GROUP_SHAREE, + false, + "", + OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER); + + if (result.isSuccess()){ + mFolderShare = (OCShare) result.getData().get(0); + } else{ + mFolderShare = null; + } + + Log.v(LOG_TAG, "Remote fixture created."); + + } + + + public void testUpdateSharePermissions() { + Log.v(LOG_TAG, "testUpdateSharePermissions in"); + + if (mFileShare != null) { + /// successful tests + // Update Share permissions on a shared file + UpdateRemoteShareOperation updateShare = new UpdateRemoteShareOperation(mFileShare.getRemoteId()); + updateShare.setPermissions(OCShare.READ_PERMISSION_FLAG); // minimum permissions + RemoteOperationResult result = updateShare.execute(mClient); + assertTrue(result.isSuccess()); + + // Update Share permissions on a shared folder + updateShare = new UpdateRemoteShareOperation(mFolderShare.getRemoteId()); + updateShare.setPermissions(OCShare.READ_PERMISSION_FLAG + OCShare.DELETE_PERMISSION_FLAG); + result = updateShare.execute(mClient); + assertTrue(result.isSuccess()); + + + /// unsuccessful tests + // Update Share with invalid permissions + updateShare = new UpdateRemoteShareOperation(mFileShare.getRemoteId()); + updateShare.setPermissions(OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER + 1); // greater than maximum value + result = updateShare.execute(mClient); + assertFalse(result.isSuccess()); + + // Unshare the file before next unsuccessful tests + RemoveRemoteShareOperation unshare = new RemoveRemoteShareOperation((int) mFileShare.getRemoteId()); + result = unshare.execute(mClient); + + if (result.isSuccess()) { + // Update Share permissions on unknown share + UpdateRemoteShareOperation updateNoShare = new UpdateRemoteShareOperation(mFileShare.getRemoteId()); + updateShare.setPermissions(OCShare.READ_PERMISSION_FLAG); // minimum permissions + result = updateShare.execute(mClient); + assertFalse(result.isSuccess()); + } + + } + + } + + @Override + protected void tearDown() throws Exception { + Log.v(LOG_TAG, "Deleting remote fixture..."); + if (mFullPath2FileToShare != null) { + RemoteOperationResult removeResult = getActivity().removeFile(mFullPath2FileToShare); + if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) { + Utils.logAndThrow(LOG_TAG, removeResult); + } + } + super.tearDown(); + Log.v(LOG_TAG, "Remote fixture delete."); + } + + + private void initAccessToServer(Context context) { + Log.v(LOG_TAG, "Setting up client instance to access OC server..."); + + mServerUri = context.getString(R.string.server_base_url); + mUser = context.getString(R.string.username); + mPass = context.getString(R.string.password); + + mClient = new OwnCloudClient( + Uri.parse(mServerUri), + NetworkUtils.getMultiThreadedConnManager() + ); + mClient.setDefaultTimeouts( + OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT, + OwnCloudClientFactory.DEFAULT_CONNECTION_TIMEOUT); + mClient.setFollowRedirects(true); + mClient.setCredentials( + OwnCloudCredentialsFactory.newBasicCredentials( + mUser, + mPass + ) + ); + + Log.v(LOG_TAG, "Client instance set up."); + + } + +} diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/UpdateShareTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/UpdatePublicShareTest.java similarity index 95% rename from test_client/tests/src/com/owncloud/android/lib/test_project/test/UpdateShareTest.java rename to test_client/tests/src/com/owncloud/android/lib/test_project/test/UpdatePublicShareTest.java index 389146b5..6bc9837f 100644 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/UpdateShareTest.java +++ b/test_client/tests/src/com/owncloud/android/lib/test_project/test/UpdatePublicShareTest.java @@ -1,5 +1,6 @@ /* ownCloud Android Library is available under MIT license * @author masensio + * @author David A. Velasco * Copyright (C) 2015 ownCloud Inc. * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -54,17 +55,18 @@ import com.owncloud.android.lib.test_project.TestActivity; /** * Class to test UpdateRemoteShareOperation + * with public shares * */ -public class UpdateShareTest extends RemoteTest { - private static final String LOG_TAG = UpdateShareTest.class.getCanonicalName(); +public class UpdatePublicShareTest extends RemoteTest { + private static final String LOG_TAG = UpdatePublicShareTest.class.getCanonicalName(); /* File to share and update.*/ private static final String FILE_TO_SHARE = "/fileToShare.txt"; // Data for tests private static final String PASSWORD = "password"; - private static final String PASS_SPECIAL_CHARS = "p@sswórd"; + private static final String PASS_SPECIAL_CHARS = "p@sswďż˝rd"; private String mFullPath2FileToShare; @@ -73,7 +75,7 @@ public class UpdateShareTest extends RemoteTest { String mServerUri, mUser, mPass; OwnCloudClient mClient = null; - public UpdateShareTest(){ + public UpdatePublicShareTest(){ super(); Protocol pr = Protocol.getProtocol("https"); @@ -117,7 +119,7 @@ public class UpdateShareTest extends RemoteTest { Utils.logAndThrow(LOG_TAG, result); } - // Share the file + // Share the file with a public link result = getActivity().createShare( mFullPath2FileToShare, ShareType.PUBLIC_LINK, @@ -137,8 +139,8 @@ public class UpdateShareTest extends RemoteTest { } - public void testUpdateRemoteShareOperation() { - Log.v(LOG_TAG, "testUpdateShare in"); + public void testUpdatePublicShare() { + Log.v(LOG_TAG, "testUpdatePublicShare in"); if (mShare != null) { // successful tests From ac9771ea3a58c5a423a1341f390c26c8e6ccba3e Mon Sep 17 00:00:00 2001 From: "David A. Velasco" Date: Wed, 27 Jan 2016 10:31:46 +0100 Subject: [PATCH 5/5] Migration to different test server --- .travis.yml | 28 +++++++++---------- .../GetRemoteSharesForFileOperation.java | 10 +++---- .../lib/test_project/test/GetShareesTest.java | 16 +++++------ .../test/UpdatePrivateShareTest.java | 15 +++++++--- 4 files changed, 38 insertions(+), 31 deletions(-) diff --git a/.travis.yml b/.travis.yml index 04831290..2598e3e7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,8 +6,7 @@ android: - android-19 branches: only: - - master - + - master before_install: - echo no | android create avd --force -n test -t $ANDROID_TARGET --abi $ANDROID_ABI -c 20M @@ -25,21 +24,22 @@ script: - ./gradlew clean build env: global: - - secure: a21NrzTCQnkTKtRGo7B1lyF2WWbpBT2N64V2Tf+oUcRLOUx3XM/mDi60mAdGd0WXV9tHD8GGmu0tQ7LGZ2VsIxixVxjzEYwX4HRTodewYez6WxBMjVEHHy+3jmc1zU4k3AAqr+uW7L4BKa5r9tH+nq9ecJMDMgW8o9MKXuP7Vso= - - secure: UVnaC5Qzat2C8WlMMb8aycz1ChZKjP8Kz89qBbVcqYK+PLAGKpUNxFa39/2oA5jkMyyOcXYC9bX1ZYzHLH7nJ8LbQgaxXMT4gvgvN0l6KezjDavIW60idD9BbugkwzNj/cjoU/DdxBykPsTn4vSRaESVNTdEbM27YU4FBPzTANY= - - secure: XEQY8s7p65lWWOuKbVDdTh6ZJtRTJ74Zw3H/+2Ms6vjZhFZsdUJjGo66LW6YvlhmYDXgiPB9piYQGcrGgT3hXJwXoge6n1pdixnV250J0T0dIZMbXYTWTARxDsyq48+LgUuF3pgqvqDWhBcemrePWv48q7fs/mwzuFSOyc8QwLk= - # The next declaration is the encrypted COVERITY_SCAN_TOKEN, created - # via the "travis encrypt" command using the project repo's public key - - secure: "epTZ0zZGDbHL3o6vSC9uNkZsi5j5SA6O/tvQBH7QW/dluuzIJxIjfhNbZHDyBReYDleirLzUFQpdWAUdvulCMLs/qZdIzFGlYXZSpxEnvPYMGQcilwADdJcxLw8L+3+ET5hSexxhjrTGw427IljkqGUpqQTxaLwFdFu98lDWSbc=" + # The next declaration is the encrypted COVERITY_SCAN_TOKEN, created + # via the "travis encrypt" command using the project repo's public key + - secure: epTZ0zZGDbHL3o6vSC9uNkZsi5j5SA6O/tvQBH7QW/dluuzIJxIjfhNbZHDyBReYDleirLzUFQpdWAUdvulCMLs/qZdIzFGlYXZSpxEnvPYMGQcilwADdJcxLw8L+3+ET5hSexxhjrTGw427IljkqGUpqQTxaLwFdFu98lDWSbc= + # The next 3 declarations are the variables needed to access the test server, + # added via "travis encrypt", using the repo public key + - secure: gPCBnpGLA2sdSMtfhT+/InThmXNEU8XrrS54uuIP8iXBLvVe0yZrNl76GbMosV0ry3YtDngsmsbHwRjPPb0+3mTTdAqZ60HHzGaNPgEm6b5t0t4bpJ3LW9osLZsuf9jRsI2LD66zxblaMrK2+8hN/dUrj707ijsZHp3SPSQJ6g8= + - secure: AnxLVarfwM7IhJ7Sca35USyRlFHFvlcBhWTt2TVDcyQ+ldDyb+U6IWXFK0Yy82QP0ZH/RCLu7FnmHK/rKG0BHNRt1Ymco1VkTQql0MZcHXP+4IKgEvgJyUn1TqYj+hSVmM6lgTA+QUjZYGSfwU8mhUFiU7644ZTdTe6ALdqa+v8= + - secure: ezKyZbb3q1Phcv/vJntuJe0C2req+Hp4/C+tFZIWZ3o8wRO9jVI3bnED9TWQyQOOT0SoRYjJ5zqp0UcEOGCzPeWFO6bA7RWp+zA/R9sziLNcVWMVv3WXnuClQjPBHJeXRnP7YmNjxDmSfV97a14dk5d9LgJZYliTDepH4dLsxro= matrix: - ANDROID_TARGET=android-19 ANDROID_ABI=armeabi-v7a - addons: coverity_scan: project: - name: "owncloud/android-library" - description: "Build submitted via Travis CI" + name: owncloud/android-library + description: Build submitted via Travis CI notification_email: lukas@owncloud.com - build_command_prepend: "gradle clean" - build_command: "gradle build" - branch_pattern: "coverity_scan" + build_command_prepend: gradle clean + build_command: gradle build + branch_pattern: coverity_scan diff --git a/src/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.java b/src/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.java index c2019f7a..6076b40f 100644 --- a/src/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.java +++ b/src/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.java @@ -55,12 +55,12 @@ public class GetRemoteSharesForFileOperation extends RemoteOperation { /** * Constructor * - * @param remoteFilePath Path to file or folder - * @param reshares If set to false (default), only shares owned by the current user are + * @param remoteFilePath Path to file or folder + * @param reshares If set to false (default), only shares owned by the current user are * returned. - * If set to true, shares owned by any user from the given file are returned. - * @param subfiles If set to false (default), lists only the folder being shared - * If set to true, all shared files within the folder are returned. + * If set to true, shares owned by any user from the given file are returned. + * @param subfiles If set to false (default), lists only the folder being shared + * If set to true, all shared files within the folder are returned. */ public GetRemoteSharesForFileOperation(String remoteFilePath, boolean reshares, boolean subfiles) { diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/GetShareesTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/GetShareesTest.java index 80bcd107..c80f805c 100644 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/GetShareesTest.java +++ b/test_client/tests/src/com/owncloud/android/lib/test_project/test/GetShareesTest.java @@ -127,9 +127,9 @@ public class GetShareesTest extends RemoteTest { JSONObject value; byte type; int userCount = 0, groupCount = 0; - assertTrue(result.isSuccess() && result.getData().size() == 3); + assertTrue(result.isSuccess() && result.getData().size() > 0); try { - for (int i=0; i<3; i++) { + for (int i=0; i 0); + assertTrue(groupCount > 0); } catch (JSONException e) { AssertionFailedError afe = new AssertionFailedError(e.getLocalizedMessage()); afe.setStackTrace(e.getStackTrace()); throw afe; } - - // search for sharees including "ad" + + // search for sharees including "ad" - expecting user "admin" & group "admin" getShareesOperation = new GetRemoteShareesOperation("ad", 1, 50); result = getShareesOperation.execute(mClient); assertTrue(result.isSuccess() && result.getData().size() == 2); @@ -172,8 +172,8 @@ public class GetShareesTest extends RemoteTest { } - // search for sharees including "b" - getShareesOperation = new GetRemoteShareesOperation("b", 1, 50); + // search for sharees including "bd" - expecting 0 results + getShareesOperation = new GetRemoteShareesOperation("bd", 1, 50); result = getShareesOperation.execute(mClient); assertTrue(result.isSuccess() && result.getData().size() == 0); diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/UpdatePrivateShareTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/UpdatePrivateShareTest.java index 60b1d141..d839530b 100644 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/UpdatePrivateShareTest.java +++ b/test_client/tests/src/com/owncloud/android/lib/test_project/test/UpdatePrivateShareTest.java @@ -174,7 +174,9 @@ public class UpdatePrivateShareTest extends RemoteTest { if (mFileShare != null) { /// successful tests // Update Share permissions on a shared file - UpdateRemoteShareOperation updateShare = new UpdateRemoteShareOperation(mFileShare.getRemoteId()); + UpdateRemoteShareOperation updateShare = new UpdateRemoteShareOperation( + mFileShare.getRemoteId() + ); updateShare.setPermissions(OCShare.READ_PERMISSION_FLAG); // minimum permissions RemoteOperationResult result = updateShare.execute(mClient); assertTrue(result.isSuccess()); @@ -189,17 +191,22 @@ public class UpdatePrivateShareTest extends RemoteTest { /// unsuccessful tests // Update Share with invalid permissions updateShare = new UpdateRemoteShareOperation(mFileShare.getRemoteId()); - updateShare.setPermissions(OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER + 1); // greater than maximum value + // greater than maximum value + updateShare.setPermissions(OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER + 1); result = updateShare.execute(mClient); assertFalse(result.isSuccess()); // Unshare the file before next unsuccessful tests - RemoveRemoteShareOperation unshare = new RemoveRemoteShareOperation((int) mFileShare.getRemoteId()); + RemoveRemoteShareOperation unshare = new RemoveRemoteShareOperation( + (int) mFileShare.getRemoteId() + ); result = unshare.execute(mClient); if (result.isSuccess()) { // Update Share permissions on unknown share - UpdateRemoteShareOperation updateNoShare = new UpdateRemoteShareOperation(mFileShare.getRemoteId()); + UpdateRemoteShareOperation updateNoShare = new UpdateRemoteShareOperation( + mFileShare.getRemoteId() + ); updateShare.setPermissions(OCShare.READ_PERMISSION_FLAG); // minimum permissions result = updateShare.execute(mClient); assertFalse(result.isSuccess());