Skip to content

Commit 1163f24

Browse files
test wipe check
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
1 parent c427101 commit 1163f24

3 files changed

Lines changed: 69 additions & 10 deletions

File tree

library/src/androidTest/java/com/nextcloud/android/lib/resources/users/GenerateAppPasswordRemoteOperationIT.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@ public class GenerateAppPasswordRemoteOperationIT extends AbstractIT {
2626
@Test
2727
public void generateAppPassword() {
2828
GenerateAppPasswordRemoteOperation sut = new GenerateAppPasswordRemoteOperation();
29-
RemoteOperationResult result = sut.execute(client);
29+
RemoteOperationResult<String> result = sut.execute(client);
3030

3131
assertTrue(result.isSuccess());
3232

33-
String appPassword = (String) result.getSingleData();
33+
String appPassword = result.getResultData();
3434
assertFalse(TextUtils.isEmpty(appPassword));
3535

3636
OwnCloudCredentials oldOwnCloudCredentials = client.getCredentials();
37-
OwnCloudCredentials newOwnCloudCredentials = new OwnCloudBasicCredentials(oldOwnCloudCredentials.getUsername(),
37+
OwnCloudCredentials newOwnCloudCredentials = new OwnCloudBasicCredentials(
38+
oldOwnCloudCredentials.getUsername(),
3839
appPassword);
3940

4041
assertNotEquals(oldOwnCloudCredentials, newOwnCloudCredentials);
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/* Nextcloud Android Library is available under MIT license
2+
*
3+
* @author Tobias Kaminsky
4+
* Copyright (C) 2023 Tobias Kaminsky
5+
* Copyright (C) 2023 Nextcloud GmbH
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*
26+
*/
27+
28+
package com.owncloud.android.lib.resources.users
29+
30+
import android.text.TextUtils
31+
import com.nextcloud.android.lib.resources.users.GenerateAppPasswordRemoteOperation
32+
import com.owncloud.android.AbstractIT
33+
import com.owncloud.android.lib.common.OwnCloudBasicCredentials
34+
import org.junit.Assert.assertFalse
35+
import org.junit.Assert.assertTrue
36+
import org.junit.Test
37+
38+
class CheckRemoteWipeRemoteOperationIT : AbstractIT() {
39+
@Test
40+
fun testCheckWipe() {
41+
val appTokenResult = GenerateAppPasswordRemoteOperation().execute(client)
42+
assertTrue(appTokenResult.isSuccess)
43+
44+
val appPassword = appTokenResult.resultData
45+
assertFalse(TextUtils.isEmpty(appPassword))
46+
47+
client.credentials = OwnCloudBasicCredentials(
48+
client.credentials.username,
49+
appPassword,
50+
true
51+
)
52+
53+
val wipeResult = CheckRemoteWipeRemoteOperation().execute(client)
54+
55+
// device should not be wiped
56+
assertFalse(wipeResult.isSuccess)
57+
}
58+
}

library/src/main/java/com/nextcloud/android/lib/resources/users/GenerateAppPasswordRemoteOperation.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525

2626

27-
public class GenerateAppPasswordRemoteOperation extends OCSRemoteOperation {
27+
public class GenerateAppPasswordRemoteOperation extends OCSRemoteOperation<String> {
2828
private static final String TAG = GenerateAppPasswordRemoteOperation.class.getSimpleName();
2929
private static final String DIRECT_ENDPOINT = "/ocs/v2.php/core/getapppassword";
3030

@@ -43,8 +43,8 @@ public GenerateAppPasswordRemoteOperation(SessionTimeOut sessionTimeOut) {
4343
this.sessionTimeOut = sessionTimeOut;
4444
}
4545

46-
protected RemoteOperationResult run(OwnCloudClient client) {
47-
RemoteOperationResult result;
46+
protected RemoteOperationResult<String> run(OwnCloudClient client) {
47+
RemoteOperationResult<String> result;
4848
GetMethod getMethod = null;
4949

5050
try {
@@ -61,14 +61,14 @@ protected RemoteOperationResult run(OwnCloudClient client) {
6161
JSONObject respJSON = new JSONObject(response);
6262
String password = respJSON.getJSONObject(NODE_OCS).getJSONObject(NODE_DATA).getString(NODE_APPPASSWORD);
6363

64-
result = new RemoteOperationResult(true, getMethod);
65-
result.setSingleData(password);
64+
result = new RemoteOperationResult<>(true, getMethod);
65+
result.setResultData(password);
6666
} else {
67-
result = new RemoteOperationResult(false, getMethod);
67+
result = new RemoteOperationResult<>(false, getMethod);
6868
client.exhaustResponse(getMethod.getResponseBodyAsStream());
6969
}
7070
} catch (Exception e) {
71-
result = new RemoteOperationResult(e);
71+
result = new RemoteOperationResult<>(e);
7272
Log_OC.e(TAG, "Generate app password failed: " + result.getLogMessage(),
7373
result.getException());
7474
} finally {

0 commit comments

Comments
 (0)