Skip to content
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

test wipe check #1205

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -46,15 +46,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,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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
*/


public class GenerateAppPasswordRemoteOperation extends OCSRemoteOperation {
public class GenerateAppPasswordRemoteOperation extends OCSRemoteOperation<String> {
private static final String TAG = GenerateAppPasswordRemoteOperation.class.getSimpleName();
private static final int SYNC_READ_TIMEOUT = 40000;
private static final int SYNC_CONNECTION_TIMEOUT = 5000;
Expand All @@ -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<String> run(OwnCloudClient client) {
RemoteOperationResult<String> result;
GetMethod getMethod = null;

try {
Expand All @@ -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 {
Expand Down
Loading