Skip to content

Commit

Permalink
Merge pull request #582 from nextcloud/backport/571/stable-2.5
Browse files Browse the repository at this point in the history
[stable-2.5] Share: use message in RemoteOperationResult instead of data
  • Loading branch information
tobiasKaminsky authored Feb 24, 2021
2 parents dc7bd54 + 956002b commit 7fa7caa
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 12 deletions.
4 changes: 4 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ services:
- su www-data -c "php /var/www/html/occ app:enable text"
- su www-data -c "git clone -b master https://github.com/nextcloud/end_to_end_encryption/ /var/www/html/apps/end_to_end_encryption/"
- su www-data -c "php /var/www/html/occ app:enable end_to_end_encryption"
- su www-data -c "git clone -b master https://github.com/nextcloud/password_policy/ /var/www/html/apps/password_policy/"
- su www-data -c "php /var/www/html/occ app:enable password_policy"
- /usr/local/bin/run.sh

trigger:
Expand Down Expand Up @@ -192,6 +194,8 @@ services:
- su www-data -c "git clone -b stable20 https://github.com/nextcloud/text.git /var/www/html/apps/text/"
- su www-data -c "php /var/www/html/occ app:enable text"
- su www-data -c "php /var/www/html/occ app:enable end_to_end_encryption"
- su www-data -c "git clone -b stable20 https://github.com/nextcloud/password_policy.git /var/www/html/apps/password_policy/"
- su www-data -c "php /var/www/html/occ app:enable password_policy"
- /usr/local/bin/run.sh

trigger:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.owncloud.android.AbstractIT
import com.owncloud.android.lib.resources.files.CreateFolderRemoteOperation
import com.owncloud.android.lib.resources.files.RemoveFileRemoteOperation
import junit.framework.Assert.assertEquals
import junit.framework.Assert.assertFalse
import junit.framework.Assert.assertTrue
import org.junit.Assert
import org.junit.Test
Expand Down Expand Up @@ -123,4 +124,59 @@ class UpdateShareRemoteOperationIT : AbstractIT() {

assertTrue(RemoveFileRemoteOperation("/label/").execute(client).isSuccess)
}

@Test
fun invalidPassword() {
val folder = "/invalidPassword/"
Assert.assertTrue(CreateFolderRemoteOperation(folder, true).execute(client).isSuccess)

// share folder via public link
val createOperationResult = CreateShareRemoteOperation(
folder,
ShareType.PUBLIC_LINK,
"",
true,
"",
OCShare.READ_PERMISSION_FLAG
).execute(client)

assertTrue(createOperationResult.isSuccess)

val share = createOperationResult.data[0] as OCShare

val sut = UpdateShareRemoteOperation(share.remoteId)
sut.setPassword("1")

val result = sut.execute(client)
assertFalse(result.isSuccess)
assertEquals("Password needs to be at least 8 characters long", result.message)

assertTrue(RemoveFileRemoteOperation(folder).execute(client).isSuccess)
}

@Test
fun validPassword() {
val folder = "/validPassword/"
Assert.assertTrue(CreateFolderRemoteOperation(folder, true).execute(client).isSuccess)

// share folder via public link
val createOperationResult = CreateShareRemoteOperation(
folder,
ShareType.PUBLIC_LINK,
"",
true,
"",
OCShare.READ_PERMISSION_FLAG
).execute(client)

assertTrue(createOperationResult.isSuccess)

val share = createOperationResult.data[0] as OCShare

val sut = UpdateShareRemoteOperation(share.remoteId)
sut.setPassword("arnservcvcbtp234")

assertTrue(sut.execute(client).isSuccess)
assertTrue(RemoveFileRemoteOperation(folder).execute(client).isSuccess)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public enum ResultCode {
private String mHttpPhrase = null;
private Exception mException = null;
private ResultCode mCode = ResultCode.UNKNOWN_ERROR;
private String message;
@ToString.Exclude private String mRedirectedLocation;
@ToString.Exclude private ArrayList<String> mAuthenticateHeaders = new ArrayList<>();
@ToString.Exclude private String mLastPermanentLocation = null;
Expand Down Expand Up @@ -340,8 +341,9 @@ public RemoteOperationResult(boolean success, HttpMethod httpMethod) {
}
if (xmlParser.isVirusException()) {
mCode = ResultCode.VIRUS_DETECTED;
mHttpPhrase = xmlParser.getMessage();
}

mHttpPhrase = xmlParser.getMessage();
}
} catch (Exception e) {
Log_OC.w(TAG, "Error reading exception from server: " + e.getMessage());
Expand Down Expand Up @@ -702,4 +704,16 @@ public String getLastPermanentLocation() {
public void setLastPermanentLocation(String lastPermanentLocation) {
mLastPermanentLocation = lastPermanentLocation;
}

public void setMessage(String message) {
this.message = message;
}

/**
* Message that is returned by server, e.g. password policy violation on ocs share api
* @return message that can be shown to user
*/
public String getMessage() {
return message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,16 @@ public RemoteOperationResult parse(String serverResponse) {

} else if (shareXmlParser.isWrongParameter()) {
result = new RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_WRONG_PARAMETER);
resultData.add(shareXmlParser.getMessage());
result.setData(resultData);

result.setMessage(shareXmlParser.getMessage());
} else if (shareXmlParser.isNotFound()) {
result = new RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND);
resultData.add(shareXmlParser.getMessage());
result.setData(resultData);

result.setMessage(shareXmlParser.getMessage());
} else if (shareXmlParser.isForbidden()) {
result = new RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_FORBIDDEN);
resultData.add(shareXmlParser.getMessage());
result.setData(resultData);

result.setMessage(shareXmlParser.getMessage());
} else {
result = new RemoteOperationResult(RemoteOperationResult.ResultCode.WRONG_SERVER_RESPONSE);

result.setMessage(shareXmlParser.getMessage());
}

} catch (XmlPullParserException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public class ShareXMLParser {

private String mStatus;
private int mStatusCode;
private String mMessage;
private String mMessage = "";

// Getters and Setters
public String getStatus() {
Expand Down

0 comments on commit 7fa7caa

Please sign in to comment.