-
Notifications
You must be signed in to change notification settings - Fork 96
feat(e2ee): add deletion functions #2000
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
...c/androidTest/java/com/owncloud/android/lib/resources/users/DeleteE2ERemoteOperationIT.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * Nextcloud Android Library | ||
| * | ||
| * SPDX-FileCopyrightText: 2026 Alper Ozturk <alper.ozturk@nextcloud.com> | ||
| * SPDX-License-Identifier: MIT | ||
| */ | ||
|
|
||
| package com.owncloud.android.lib.resources.users | ||
|
|
||
| import com.owncloud.android.AbstractIT | ||
| import com.owncloud.android.lib.resources.e2ee.DeleteEncryptedFilesRemoteOperation | ||
| import junit.framework.TestCase.assertTrue | ||
| import org.junit.Test | ||
|
|
||
| class DeleteE2ERemoteOperationIT : AbstractIT() { | ||
| @Test | ||
| fun testDeleteEncryptedFiles() { | ||
| val sut = DeleteEncryptedFilesRemoteOperation() | ||
| val result = sut.execute(nextcloudClient) | ||
| assertTrue(result.isSuccess) | ||
| } | ||
|
|
||
| @Test | ||
| fun testDeletePrivateKey() { | ||
| val sut = DeletePrivateKeyRemoteOperation() | ||
| val result = sut.execute(nextcloudClient) | ||
| assertTrue(result.isSuccess) | ||
| } | ||
|
|
||
| @Test | ||
| fun testDeletePublicKey() { | ||
| val sut = DeletePublicKeyRemoteOperation() | ||
| val result = sut.execute(nextcloudClient) | ||
| assertTrue(result.isSuccess) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
.../main/java/com/owncloud/android/lib/resources/e2ee/DeleteEncryptedFilesRemoteOperation.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /* | ||
| * Nextcloud Android Library | ||
| * | ||
| * SPDX-FileCopyrightText: 2026 Alper Ozturk <alper.ozturk@nextcloud.com> | ||
| * SPDX-License-Identifier: MIT | ||
| */ | ||
|
|
||
| package com.owncloud.android.lib.resources.e2ee | ||
|
|
||
| import com.nextcloud.common.NextcloudClient | ||
| import com.nextcloud.operations.DeleteMethod | ||
| import com.owncloud.android.lib.common.operations.RemoteOperation | ||
| import com.owncloud.android.lib.common.operations.RemoteOperationResult | ||
| import com.owncloud.android.lib.common.utils.Log_OC | ||
| import org.apache.commons.httpclient.HttpStatus | ||
|
|
||
| class DeleteEncryptedFilesRemoteOperation : RemoteOperation<Unit>() { | ||
| @Deprecated("Deprecated in Java") | ||
| @Suppress("Detekt.TooGenericExceptionCaught", "DEPRECATION") | ||
| override fun run(client: NextcloudClient): RemoteOperationResult<Unit> { | ||
| val method = | ||
| DeleteMethod(uri = client.baseUri.toString() + ENCRYPTED_FILES_URL, useOcsApiRequestHeader = true) | ||
|
|
||
| return try { | ||
| val status = client.execute(method) | ||
|
|
||
| if (status == HttpStatus.SC_OK) { | ||
| RemoteOperationResult<Unit>(true, method) | ||
| } else { | ||
| RemoteOperationResult<Unit>(false, method).also { | ||
| Log_OC.e( | ||
| TAG, | ||
| "Deleting encrypted files failed: ${method.getResponseBodyAsString()}", | ||
| it.exception | ||
| ) | ||
| } | ||
| } | ||
| } catch (e: Exception) { | ||
| RemoteOperationResult<Unit>(e).also { | ||
| Log_OC.e(TAG, "Deleting encrypted files failed: ${it.logMessage}", it.exception) | ||
| } | ||
| } finally { | ||
| method.releaseConnection() | ||
| } | ||
| } | ||
|
|
||
| companion object { | ||
| private val TAG = DeleteEncryptedFilesRemoteOperation::class.java.simpleName | ||
| private const val ENCRYPTED_FILES_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v1/encrypted-files" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 0 additions & 53 deletions
53
...rc/main/java/com/owncloud/android/lib/resources/users/DeletePublicKeyRemoteOperation.java
This file was deleted.
Oops, something went wrong.
49 changes: 49 additions & 0 deletions
49
.../src/main/java/com/owncloud/android/lib/resources/users/DeletePublicKeyRemoteOperation.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /* | ||
| * Nextcloud Android Library | ||
| * | ||
| * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-FileCopyrightText: 2017 Tobias Kaminsky <tobias@kaminsky.me> | ||
| * SPDX-License-Identifier: MIT | ||
| */ | ||
| package com.owncloud.android.lib.resources.users | ||
|
|
||
| import com.nextcloud.common.NextcloudClient | ||
| import com.nextcloud.operations.DeleteMethod | ||
| import com.owncloud.android.lib.common.operations.RemoteOperation | ||
| import com.owncloud.android.lib.common.operations.RemoteOperationResult | ||
| import com.owncloud.android.lib.common.utils.Log_OC | ||
| import java.net.HttpURLConnection | ||
|
|
||
| class DeletePublicKeyRemoteOperation : RemoteOperation<Unit>() { | ||
| @Deprecated("Deprecated in Java") | ||
| @Suppress("Detekt.TooGenericExceptionCaught", "DEPRECATION") | ||
| override fun run(client: NextcloudClient): RemoteOperationResult<Unit> { | ||
| var postMethod: DeleteMethod? = null | ||
| var result: RemoteOperationResult<Unit> | ||
|
|
||
| try { | ||
| postMethod = DeleteMethod(client.baseUri.toString() + PUBLIC_KEY_URL, true) | ||
| postMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE) | ||
|
|
||
| val status = client.execute(postMethod) | ||
|
|
||
| result = RemoteOperationResult<Unit>(status == HttpURLConnection.HTTP_OK, postMethod) | ||
| } catch (e: Exception) { | ||
| result = RemoteOperationResult<Unit>(e) | ||
| Log_OC.e( | ||
| TAG, | ||
| "Deletion of public key failed: " + result.getLogMessage(), | ||
| result.exception | ||
| ) | ||
| } finally { | ||
| postMethod?.releaseConnection() | ||
| } | ||
| return result | ||
| } | ||
|
|
||
| companion object { | ||
| private val TAG: String = DeletePublicKeyRemoteOperation::class.java.getSimpleName() | ||
| private const val PUBLIC_KEY_URL = | ||
| "/ocs/v2.php/apps/end_to_end_encryption/api/v1/public-key" | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those tests will also return success if there is no key/file at all, right?
I guess it is hard to test it within library, but then we should test it within client: