Skip to content

Commit

Permalink
test wipe check
Browse files Browse the repository at this point in the history
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
  • Loading branch information
tobiasKaminsky committed Sep 28, 2023
1 parent 5c83a0b commit d38866d
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 10 deletions.
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

0 comments on commit d38866d

Please sign in to comment.