Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,15 @@ steps:

services:
- name: server
image: nextcloudci/server:server-3
image: nextcloudci/server:server-13
commands:
- /initnc.sh
- su www-data -c "OC_PASS=user1 php /var/www/html/occ user:add --password-from-env --display-name='User One' user1"
- su www-data -c "OC_PASS=user2 php /var/www/html/occ user:add --password-from-env --display-name='User Two' user2"
- su www-data -c "php /var/www/html/occ group:add users"
- su www-data -c "php /var/www/html/occ group:adduser users user1"
- su www-data -c "php /var/www/html/occ group:adduser users user2"
- /run.sh

trigger:
branch:
Expand Down
2 changes: 1 addition & 1 deletion scripts/analysis/findbugs-results.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
181
185
10 changes: 6 additions & 4 deletions src/androidTest/java/com/owncloud/android/AbstractIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.owncloud.android.lib.common.OwnCloudBasicCredentials;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientFactory;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.resources.files.ReadFolderRemoteOperation;
import com.owncloud.android.lib.resources.files.RemoveFileRemoteOperation;
import com.owncloud.android.lib.resources.files.model.RemoteFile;
Expand All @@ -22,7 +23,6 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;

import static junit.framework.TestCase.assertTrue;

Expand Down Expand Up @@ -101,13 +101,15 @@ public static File extractAsset(String fileName, Context context) throws IOExcep

@After
public void after() {
ArrayList list = new ReadFolderRemoteOperation("/").execute(client).getData();
RemoteOperationResult result = new ReadFolderRemoteOperation("/").execute(client);
assertTrue(result.getLogMessage(), result.isSuccess());

for (Object object : list) {
for (Object object : result.getData()) {
RemoteFile remoteFile = (RemoteFile) object;

if (!remoteFile.getRemotePath().equals("/")) {
new RemoveFileRemoteOperation(remoteFile.getRemotePath()).execute(client);
assertTrue(new RemoveFileRemoteOperation(remoteFile.getRemotePath())
.execute(client).isSuccess());
}
}
}
Expand Down
224 changes: 224 additions & 0 deletions src/androidTest/java/com/owncloud/android/FileIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,22 @@

import android.net.Uri;

import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.resources.files.CreateFolderRemoteOperation;
import com.owncloud.android.lib.resources.files.ReadFolderRemoteOperation;
import com.owncloud.android.lib.resources.files.RemoveFileRemoteOperation;
import com.owncloud.android.lib.resources.files.model.RemoteFile;
import com.owncloud.android.lib.resources.shares.CreateShareRemoteOperation;
import com.owncloud.android.lib.resources.shares.OCShare;
import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.lib.resources.shares.ShareeUser;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

Expand Down Expand Up @@ -68,4 +78,218 @@ public void testCreateFolderWithWrongURL() {

client.setBaseUri(uri);
}

@Test
public void testZeroSharees() {
// create & verify folder
String path = "/testFolder/";
assertTrue(new CreateFolderRemoteOperation(path, true).execute(client).isSuccess());
assertTrue(new ReadFolderRemoteOperation(path).execute(client).isSuccess());

// verify
RemoteOperationResult result = new ReadFolderRemoteOperation("/").execute(client);
assertTrue(result.isSuccess());

RemoteFile parentFolder = (RemoteFile) result.getData().get(0);
assertEquals("/", parentFolder.getRemotePath());

for (int i = 1; i < result.getData().size(); i++) {
RemoteFile child = (RemoteFile) result.getData().get(i);

if (path.equals(child.getRemotePath())) {
assertEquals(0, child.getSharees().length);
}
}
}

@Test
public void testShareViaLinkSharees() {
// create & verify folder
String path = "/testFolder/";
assertTrue(new CreateFolderRemoteOperation(path, true).execute(client).isSuccess());
assertTrue(new ReadFolderRemoteOperation(path).execute(client).isSuccess());

// share folder
assertTrue(new CreateShareRemoteOperation(path,
ShareType.PUBLIC_LINK,
"",
false,
"",
OCShare.DEFAULT_PERMISSION)
.execute(client).isSuccess());

// verify
RemoteOperationResult result = new ReadFolderRemoteOperation("/").execute(client);
assertTrue(result.isSuccess());

RemoteFile parentFolder = (RemoteFile) result.getData().get(0);
assertEquals("/", parentFolder.getRemotePath());

for (int i = 1; i < result.getData().size(); i++) {
RemoteFile child = (RemoteFile) result.getData().get(i);

if (path.equals(child.getRemotePath())) {
assertEquals(0, child.getSharees().length);
}
}
}

@Test
public void testShareToGroupSharees() {
// create & verify folder
String path = "/testFolder/";
assertTrue(new CreateFolderRemoteOperation(path, true).execute(client).isSuccess());
assertTrue(new ReadFolderRemoteOperation(path).execute(client).isSuccess());

ShareeUser sharee = new ShareeUser("users", "", ShareType.GROUP);

// share folder
assertTrue(new CreateShareRemoteOperation(path,
ShareType.GROUP,
"users",
false,
"",
OCShare.DEFAULT_PERMISSION)
.execute(client).isSuccess());

// verify
RemoteOperationResult result = new ReadFolderRemoteOperation("/").execute(client);
assertTrue(result.isSuccess());

RemoteFile parentFolder = (RemoteFile) result.getData().get(0);
assertEquals("/", parentFolder.getRemotePath());

for (int i = 1; i < result.getData().size(); i++) {
RemoteFile child = (RemoteFile) result.getData().get(i);

if (path.equals(child.getRemotePath())) {
assertEquals(1, child.getSharees().length);
assertEquals(sharee, child.getSharees()[0]);
}
}
}

@Test
public void testOneSharees() {
// create & verify folder
String path = "/testFolder/";
assertTrue(new CreateFolderRemoteOperation(path, true).execute(client).isSuccess());
assertTrue(new ReadFolderRemoteOperation(path).execute(client).isSuccess());

ShareeUser sharee = new ShareeUser("user1", "User One", ShareType.USER);

// share folder
assertTrue(new CreateShareRemoteOperation(path,
ShareType.USER,
"user1",
false,
"",
OCShare.DEFAULT_PERMISSION)
.execute(client).isSuccess());

// verify
RemoteOperationResult result = new ReadFolderRemoteOperation("/").execute(client);
assertTrue(result.isSuccess());

RemoteFile parentFolder = (RemoteFile) result.getData().get(0);
assertEquals("/", parentFolder.getRemotePath());

for (int i = 1; i < result.getData().size(); i++) {
RemoteFile child = (RemoteFile) result.getData().get(i);

if (path.equals(child.getRemotePath())) {
assertEquals(1, child.getSharees().length);
assertEquals(sharee, child.getSharees()[0]);
}
}
}

@Test
public void testTwoShareesOnParent() {
// create & verify folder
String path = "/testFolder/";
assertTrue(new CreateFolderRemoteOperation(path, true).execute(client).isSuccess());
assertTrue(new ReadFolderRemoteOperation(path).execute(client).isSuccess());

List<ShareeUser> sharees = new ArrayList<>();
sharees.add(new ShareeUser("user1", "User One", ShareType.USER));
sharees.add(new ShareeUser("user2", "User Two", ShareType.USER));

// share folder
assertTrue(new CreateShareRemoteOperation(path,
ShareType.USER,
"user1",
false,
"",
OCShare.DEFAULT_PERMISSION)
.execute(client).isSuccess());

assertTrue(new CreateShareRemoteOperation(path,
ShareType.USER,
"user2",
false,
"",
OCShare.DEFAULT_PERMISSION)
.execute(client).isSuccess());

// verify
RemoteOperationResult result = new ReadFolderRemoteOperation("/").execute(client);
assertTrue(result.isSuccess());

RemoteFile parentFolder = (RemoteFile) result.getData().get(0);
assertEquals("/", parentFolder.getRemotePath());

for (int i = 1; i < result.getData().size(); i++) {
RemoteFile child = (RemoteFile) result.getData().get(i);

if (path.equals(child.getRemotePath())) {
assertEquals(2, child.getSharees().length);

for (ShareeUser user : child.getSharees()) {
assertTrue(sharees.contains(user));
}
}
}
}

@Test
public void testTwoSharees() {
// create & verify folder
String path = "/testFolder/";
assertTrue(new CreateFolderRemoteOperation(path, true).execute(client).isSuccess());
assertTrue(new ReadFolderRemoteOperation(path).execute(client).isSuccess());

List<ShareeUser> sharees = new ArrayList<>();
sharees.add(new ShareeUser("user1", "User One", ShareType.USER));
sharees.add(new ShareeUser("user2", "User Two", ShareType.USER));

// share folder
assertTrue(new CreateShareRemoteOperation(path,
ShareType.USER,
"user1",
false,
"",
OCShare.DEFAULT_PERMISSION)
.execute(client).isSuccess());

assertTrue(new CreateShareRemoteOperation(path,
ShareType.USER,
"user2",
false,
"",
OCShare.DEFAULT_PERMISSION)
.execute(client).isSuccess());

// verify
RemoteOperationResult result = new ReadFolderRemoteOperation(path).execute(client);
assertTrue(result.isSuccess());

RemoteFile folder = (RemoteFile) result.getData().get(0);
assertEquals(path, folder.getRemotePath());
assertEquals(2, folder.getSharees().length);

for (ShareeUser user : folder.getSharees()) {
assertTrue(sharees.contains(user));
}
}
}
Loading