Skip to content

Commit

Permalink
E2E sharing
Browse files Browse the repository at this point in the history
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
  • Loading branch information
tobiasKaminsky committed Aug 28, 2023
1 parent d6d062d commit e08fc0d
Show file tree
Hide file tree
Showing 30 changed files with 725 additions and 217 deletions.
5 changes: 2 additions & 3 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 8 additions & 10 deletions library/src/androidTest/java/com/owncloud/android/AbstractIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,10 @@
*/
package com.owncloud.android;

import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;

import androidx.test.platform.app.InstrumentationRegistry;

import com.nextcloud.common.NextcloudClient;
import com.owncloud.android.lib.common.OwnCloudBasicCredentials;
import com.owncloud.android.lib.common.OwnCloudClient;
Expand All @@ -61,7 +54,6 @@
import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.BeforeClass;
import org.junit.Rule;

import java.io.File;
import java.io.FileOutputStream;
Expand All @@ -73,15 +65,21 @@
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;

import androidx.test.platform.app.InstrumentationRegistry;
import okhttp3.Credentials;

import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;

/**
* Common base for all integration tests
*/

public abstract class AbstractIT {
@Rule
public RetryTestRule retryTestRule = new RetryTestRule();
// @Rule
// public RetryTestRule retryTestRule = new RetryTestRule();

private static final int BUFFER_SIZE = 1024;
public static final long RANDOM_MTIME = 1464818400L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,27 @@
*/
package com.owncloud.android;

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

import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.resources.status.CapabilityBooleanType;
import com.owncloud.android.lib.resources.status.E2EVersion;
import com.owncloud.android.lib.resources.status.GetCapabilitiesRemoteOperation;
import com.owncloud.android.lib.resources.status.NextcloudVersion;
import com.owncloud.android.lib.resources.status.OCCapability;
import com.owncloud.android.lib.resources.status.OwnCloudVersion;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;

/**
* Class to test GetRemoteCapabilitiesOperation
*/
public class GetCapabilitiesIT extends AbstractIT {
public class GetCapabilitiesRemoteOperationIT extends AbstractIT {
/**
* Test get capabilities
*/
Expand Down Expand Up @@ -149,12 +151,15 @@ private void checkCapability(OCCapability capability, String userId) {
// groupfolder
if (capability.getVersion().isNewerOrEqual(NextcloudVersion.nextcloud_27)) {
if (userId.equals("test")) {
capability.getGroupfolders().isTrue();
assertTrue(capability.getGroupfolders().isTrue());
} else {
capability.getGroupfolders().isFalse();
assertTrue(capability.getGroupfolders().isFalse());
}
} else {
capability.getGroupfolders().isFalse();
assertTrue(capability.getGroupfolders().isFalse());
}

// e2e
assertNotSame(capability.getEndToEndEncryptionApiVersion(), E2EVersion.UNKNOWN);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

public class UpdateMetadataRemoteOperationIT extends AbstractIT {
@Test
public void uploadAndModify() {
public void uploadAndModifyV1() {
// tests only for NC19+
testOnlyOnServer(OwnCloudVersion.nextcloud_20);

Expand All @@ -58,10 +58,10 @@ public void uploadAndModify() {

// mark as encrypted
assertTrue(new ToggleEncryptionRemoteOperation(remoteFolder.getLocalId(),
remoteFolder.getRemotePath(),
true)
.execute(client)
.isSuccess());
remoteFolder.getRemotePath(),
true)
.execute(client)
.isSuccess());

// Lock
String token = new LockFileRemoteOperation(remoteFolder.getLocalId())
Expand All @@ -73,8 +73,8 @@ public void uploadAndModify() {
// add metadata
String expectedMetadata = "metadata";
assertTrue(new StoreMetadataRemoteOperation(remoteFolder.getLocalId(), expectedMetadata)
.execute(client)
.isSuccess());
.execute(client)
.isSuccess());

// unlock
assertTrue(new UnlockFileRemoteOperation(remoteFolder.getLocalId(), token).execute(client).isSuccess());
Expand All @@ -96,8 +96,8 @@ public void uploadAndModify() {
// update metadata
String updatedMetadata = "metadata2";
assertTrue(new UpdateMetadataRemoteOperation(remoteFolder.getLocalId(), updatedMetadata, token)
.execute(client)
.isSuccess());
.execute(client)
.isSuccess());

// unlock
assertTrue(new UnlockFileRemoteOperation(remoteFolder.getLocalId(), token).execute(client).isSuccess());
Expand All @@ -109,4 +109,88 @@ public void uploadAndModify() {

assertEquals(updatedMetadata, retrievedMetadata2);
}

@Test
public void uploadAndModifyV2() {
// tests only for NC19+
testOnlyOnServer(OwnCloudVersion.nextcloud_20);

// E2E server app checks for official NC client with >=3.13.0,
// and blocks all other clients, e.g. 3rd party apps using this lib
OwnCloudClientManagerFactory.setUserAgent("Mozilla/5.0 (Android) Nextcloud-android/3.13.0");

// create folder
String folder = "/" + RandomStringGenerator.make(20) + "/";
assertTrue(new CreateFolderRemoteOperation(folder, true).execute(client).isSuccess());
RemoteFile remoteFolder = (RemoteFile) new ReadFileRemoteOperation(folder).execute(client).getSingleData();

assertNotNull(remoteFolder);

// mark as encrypted
assertTrue(new ToggleEncryptionRemoteOperation(remoteFolder.getLocalId(),
remoteFolder.getRemotePath(),
true)
.execute(client)
.isSuccess());

// Lock
int counter = 0;
String token = new LockFileRemoteOperation(remoteFolder.getLocalId())
.execute(client)
.getResultData();
assertFalse(TextUtils.isEmpty(token));

// add metadata
String expectedMetadata = "metadata";
String signature = "signature";

assertTrue(new StoreMetadataV2RemoteOperation(
remoteFolder.getLocalId(),
expectedMetadata,
token,
signature)
.execute(client)
.isSuccess());

// unlock
assertTrue(new UnlockFileRemoteOperation(remoteFolder.getLocalId(), token).execute(client).isSuccess());

// verify metadata
MetadataResponse metadataResponse = new GetMetadataRemoteOperation(remoteFolder.getLocalId())
.execute(client)
.getResultData();

assertEquals(signature, metadataResponse.getSignature());
assertEquals(expectedMetadata, metadataResponse.getMetadata());

// Lock
counter += 1;
token = new LockFileRemoteOperation(remoteFolder.getLocalId(), counter)
.execute(client)
.getResultData();
assertFalse(TextUtils.isEmpty(token));

// update metadata
String updatedMetadata = "metadata2";
signature = "signature2";
assertTrue(
new UpdateMetadataV2RemoteOperation(
remoteFolder.getLocalId(),
updatedMetadata,
token,
signature)
.execute(client)
.isSuccess());

// unlock
assertTrue(new UnlockFileRemoteOperation(remoteFolder.getLocalId(), token).execute(client).isSuccess());

// verify metadata
metadataResponse = new GetMetadataRemoteOperation(remoteFolder.getLocalId())
.execute(client)
.getResultData();

assertEquals(signature, metadataResponse.getSignature());
assertEquals(updatedMetadata, metadataResponse.getMetadata());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
*
* Nextcloud Android client application
*
* @author Tobias Kaminsky
* Copyright (C) 2023 Tobias Kaminsky
* Copyright (C) 2023 Nextcloud GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.owncloud.android.lib.resources.users

import com.owncloud.android.AbstractIT
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory
import junit.framework.TestCase.assertNotNull
import junit.framework.TestCase.assertTrue
import org.junit.Before
import org.junit.Test

class GetPublicKeyRemoteOperationIT : AbstractIT() {
@Before
fun init() {
// E2E server app checks for official NC client with >=3.13.0,
// and blocks all other clients, e.g. 3rd party apps using this lib
OwnCloudClientManagerFactory.setUserAgent("Mozilla/5.0 (Android) Nextcloud-android/3.13.0")
}

@Test
fun getKey() {
var result = GetPublicKeyRemoteOperation().execute(nextcloudClient)

assertTrue(result.isSuccess)
assertNotNull(result.resultData)
val testKey = result.resultData

result = GetPublicKeyRemoteOperation("enc2").execute(nextcloudClient)

assertTrue(result.isSuccess)
assertNotNull(result.resultData)
assertTrue(testKey.compareTo(result.resultData) != 0)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
import okhttp3.Request
import okhttp3.Response
import java.io.IOException
import java.net.HttpURLConnection

/**
* Common base class for all new OkHttpMethods
Expand Down Expand Up @@ -181,4 +182,8 @@ abstract class OkHttpMethodBase(
}

abstract fun applyType(temp: Request.Builder)

fun isSuccess(): Boolean {
return getStatusCode() == HttpURLConnection.HTTP_OK
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import okhttp3.RequestBody

/**
* HTTP POST method that uses OkHttp with new NextcloudClient
* UTF8 by default
*/
class PostMethod(
uri: String,
Expand Down
Loading

0 comments on commit e08fc0d

Please sign in to comment.