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
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/


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";

Expand All @@ -43,8 +43,8 @@ public GenerateAppPasswordRemoteOperation(SessionTimeOut sessionTimeOut) {
this.sessionTimeOut = sessionTimeOut;
}

protected RemoteOperationResult run(OwnCloudClient client) {
RemoteOperationResult result;
protected RemoteOperationResult<String> run(OwnCloudClient client) {
RemoteOperationResult<String> result;
GetMethod getMethod = null;

try {
Expand All @@ -61,14 +61,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 {
Expand Down
Loading