diff --git a/library/src/androidTest/java/com/nextcloud/android/lib/resources/users/GenerateAppPasswordRemoteOperationIT.java b/library/src/androidTest/java/com/nextcloud/android/lib/resources/users/GenerateAppPasswordRemoteOperationIT.java index 9712052c6..8bafc1163 100644 --- a/library/src/androidTest/java/com/nextcloud/android/lib/resources/users/GenerateAppPasswordRemoteOperationIT.java +++ b/library/src/androidTest/java/com/nextcloud/android/lib/resources/users/GenerateAppPasswordRemoteOperationIT.java @@ -46,15 +46,16 @@ public class GenerateAppPasswordRemoteOperationIT extends AbstractIT { @Test public void generateAppPassword() { GenerateAppPasswordRemoteOperation sut = new GenerateAppPasswordRemoteOperation(); - RemoteOperationResult result = sut.execute(client); + RemoteOperationResult result = sut.execute(client); assertTrue(result.isSuccess()); - String appPassword = (String) result.getSingleData(); + String appPassword = result.getResultData(); assertFalse(TextUtils.isEmpty(appPassword)); OwnCloudCredentials oldOwnCloudCredentials = client.getCredentials(); - OwnCloudCredentials newOwnCloudCredentials = new OwnCloudBasicCredentials(oldOwnCloudCredentials.getUsername(), + OwnCloudCredentials newOwnCloudCredentials = new OwnCloudBasicCredentials( + oldOwnCloudCredentials.getUsername(), appPassword); assertNotEquals(oldOwnCloudCredentials, newOwnCloudCredentials); diff --git a/library/src/androidTest/java/com/owncloud/android/lib/resources/users/CheckRemoteWipeRemoteOperationIT.kt b/library/src/androidTest/java/com/owncloud/android/lib/resources/users/CheckRemoteWipeRemoteOperationIT.kt new file mode 100644 index 000000000..5ecce264b --- /dev/null +++ b/library/src/androidTest/java/com/owncloud/android/lib/resources/users/CheckRemoteWipeRemoteOperationIT.kt @@ -0,0 +1,58 @@ +/* Nextcloud Android Library is available under MIT license + * + * @author Tobias Kaminsky + * Copyright (C) 2023 Tobias Kaminsky + * Copyright (C) 2023 Nextcloud GmbH + * + * 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.users + +import android.text.TextUtils +import com.nextcloud.android.lib.resources.users.GenerateAppPasswordRemoteOperation +import com.owncloud.android.AbstractIT +import com.owncloud.android.lib.common.OwnCloudBasicCredentials +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Test + +class CheckRemoteWipeRemoteOperationIT : AbstractIT() { + @Test + fun testCheckWipe() { + val appTokenResult = GenerateAppPasswordRemoteOperation().execute(client) + assertTrue(appTokenResult.isSuccess) + + val appPassword = appTokenResult.resultData + assertFalse(TextUtils.isEmpty(appPassword)) + + client.credentials = OwnCloudBasicCredentials( + client.credentials.username, + appPassword, + true + ) + + val wipeResult = CheckRemoteWipeRemoteOperation().execute(client) + + // device should not be wiped + assertFalse(wipeResult.isSuccess) + } +} diff --git a/library/src/main/java/com/nextcloud/android/lib/resources/users/GenerateAppPasswordRemoteOperation.java b/library/src/main/java/com/nextcloud/android/lib/resources/users/GenerateAppPasswordRemoteOperation.java index bd66d365b..18c2a875a 100644 --- a/library/src/main/java/com/nextcloud/android/lib/resources/users/GenerateAppPasswordRemoteOperation.java +++ b/library/src/main/java/com/nextcloud/android/lib/resources/users/GenerateAppPasswordRemoteOperation.java @@ -41,7 +41,7 @@ */ -public class GenerateAppPasswordRemoteOperation extends OCSRemoteOperation { +public class GenerateAppPasswordRemoteOperation extends OCSRemoteOperation { private static final String TAG = GenerateAppPasswordRemoteOperation.class.getSimpleName(); private static final int SYNC_READ_TIMEOUT = 40000; private static final int SYNC_CONNECTION_TIMEOUT = 5000; @@ -52,8 +52,8 @@ public class GenerateAppPasswordRemoteOperation extends OCSRemoteOperation { private static final String NODE_DATA = "data"; private static final String NODE_APPPASSWORD = "apppassword"; - protected RemoteOperationResult run(OwnCloudClient client) { - RemoteOperationResult result; + protected RemoteOperationResult run(OwnCloudClient client) { + RemoteOperationResult result; GetMethod getMethod = null; try { @@ -70,14 +70,14 @@ protected RemoteOperationResult run(OwnCloudClient client) { JSONObject respJSON = new JSONObject(response); String password = respJSON.getJSONObject(NODE_OCS).getJSONObject(NODE_DATA).getString(NODE_APPPASSWORD); - result = new RemoteOperationResult(true, getMethod); - result.setSingleData(password); + result = new RemoteOperationResult<>(true, getMethod); + result.setResultData(password); } else { - result = new RemoteOperationResult(false, getMethod); + result = new RemoteOperationResult<>(false, getMethod); client.exhaustResponse(getMethod.getResponseBodyAsStream()); } } catch (Exception e) { - result = new RemoteOperationResult(e); + result = new RemoteOperationResult<>(e); Log_OC.e(TAG, "Generate app password failed: " + result.getLogMessage(), result.getException()); } finally {