Loading library/src/androidTest/java/com/nextcloud/android/lib/resources/users/GenerateAppPasswordRemoteOperationIT.java +4 −3 Original line number Diff line number Diff line Loading @@ -26,15 +26,16 @@ public class GenerateAppPasswordRemoteOperationIT extends AbstractIT { @Test public void generateAppPassword() { GenerateAppPasswordRemoteOperation sut = new GenerateAppPasswordRemoteOperation(); RemoteOperationResult result = sut.execute(client); RemoteOperationResult<String> 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); Loading library/src/androidTest/java/com/owncloud/android/lib/resources/users/CheckRemoteWipeRemoteOperationIT.kt 0 → 100644 +40 −0 Original line number Diff line number Diff line /* * Nextcloud Android Library * * SPDX-FileCopyrightText: 2020-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2023 Tobias Kaminsky <tobias@kaminsky.me> * SPDX-License-Identifier: MIT */ 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) } } library/src/main/java/com/nextcloud/android/lib/resources/users/GenerateAppPasswordRemoteOperation.java +7 −7 Original line number Diff line number Diff line Loading @@ -24,7 +24,7 @@ import org.json.JSONObject; */ public class GenerateAppPasswordRemoteOperation extends OCSRemoteOperation { public class GenerateAppPasswordRemoteOperation extends OCSRemoteOperation<String> { private static final String TAG = GenerateAppPasswordRemoteOperation.class.getSimpleName(); private static final String DIRECT_ENDPOINT = "/ocs/v2.php/core/getapppassword"; Loading @@ -43,8 +43,8 @@ public class GenerateAppPasswordRemoteOperation extends OCSRemoteOperation { this.sessionTimeOut = sessionTimeOut; } protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result; protected RemoteOperationResult<String> run(OwnCloudClient client) { RemoteOperationResult<String> result; GetMethod getMethod = null; try { Loading @@ -61,14 +61,14 @@ public class GenerateAppPasswordRemoteOperation extends OCSRemoteOperation { 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 { Loading Loading
library/src/androidTest/java/com/nextcloud/android/lib/resources/users/GenerateAppPasswordRemoteOperationIT.java +4 −3 Original line number Diff line number Diff line Loading @@ -26,15 +26,16 @@ public class GenerateAppPasswordRemoteOperationIT extends AbstractIT { @Test public void generateAppPassword() { GenerateAppPasswordRemoteOperation sut = new GenerateAppPasswordRemoteOperation(); RemoteOperationResult result = sut.execute(client); RemoteOperationResult<String> 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); Loading
library/src/androidTest/java/com/owncloud/android/lib/resources/users/CheckRemoteWipeRemoteOperationIT.kt 0 → 100644 +40 −0 Original line number Diff line number Diff line /* * Nextcloud Android Library * * SPDX-FileCopyrightText: 2020-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2023 Tobias Kaminsky <tobias@kaminsky.me> * SPDX-License-Identifier: MIT */ 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) } }
library/src/main/java/com/nextcloud/android/lib/resources/users/GenerateAppPasswordRemoteOperation.java +7 −7 Original line number Diff line number Diff line Loading @@ -24,7 +24,7 @@ import org.json.JSONObject; */ public class GenerateAppPasswordRemoteOperation extends OCSRemoteOperation { public class GenerateAppPasswordRemoteOperation extends OCSRemoteOperation<String> { private static final String TAG = GenerateAppPasswordRemoteOperation.class.getSimpleName(); private static final String DIRECT_ENDPOINT = "/ocs/v2.php/core/getapppassword"; Loading @@ -43,8 +43,8 @@ public class GenerateAppPasswordRemoteOperation extends OCSRemoteOperation { this.sessionTimeOut = sessionTimeOut; } protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result; protected RemoteOperationResult<String> run(OwnCloudClient client) { RemoteOperationResult<String> result; GetMethod getMethod = null; try { Loading @@ -61,14 +61,14 @@ public class GenerateAppPasswordRemoteOperation extends OCSRemoteOperation { 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 { Loading