diff --git a/library/src/androidTest/java/com/owncloud/android/lib/resources/files/UploadFileRemoteOperationIT.kt b/library/src/androidTest/java/com/owncloud/android/lib/resources/files/UploadFileRemoteOperationIT.kt index fa90f05596..3ce9f01432 100644 --- a/library/src/androidTest/java/com/owncloud/android/lib/resources/files/UploadFileRemoteOperationIT.kt +++ b/library/src/androidTest/java/com/owncloud/android/lib/resources/files/UploadFileRemoteOperationIT.kt @@ -23,9 +23,13 @@ package com.owncloud.android.lib.resources.files import android.os.Build import com.owncloud.android.AbstractIT +import com.owncloud.android.lib.common.OwnCloudBasicCredentials +import com.owncloud.android.lib.common.OwnCloudClientFactory +import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.common.utils.Log_OC import com.owncloud.android.lib.resources.files.model.RemoteFile import junit.framework.TestCase.assertEquals +import org.junit.Assert.assertFalse import org.junit.Assert.assertNotNull import org.junit.Assert.assertTrue import org.junit.Test @@ -36,6 +40,7 @@ import java.nio.file.attribute.BasicFileAttributes import java.util.concurrent.TimeUnit class UploadFileRemoteOperationIT : AbstractIT() { + @Throws(IOException::class) @Test fun creationTime() { val imageFile = getFile("imageFile.png") @@ -44,6 +49,7 @@ class UploadFileRemoteOperationIT : AbstractIT() { assertTrue(creationDate!! > (System.currentTimeMillis() / MILLI_TO_SECOND) - TIME_OFFSET) } + @Throws(IOException::class) @Test fun upload() { // create file @@ -94,6 +100,34 @@ class UploadFileRemoteOperationIT : AbstractIT() { ) } + @Throws(IOException::class) + @Test + fun uploadWithDisabledUser() { + // use disabled user + val client3 = OwnCloudClientFactory.createOwnCloudClient(url, context, true) + client3.credentials = OwnCloudBasicCredentials("disabled", "disabled") + + // create file + val filePath = createFile("text") + val remotePath = "/test.md" + + val creationTimestamp = getCreationTimestamp(File(filePath)) + val sut = + UploadFileRemoteOperation( + filePath, + remotePath, + "text/markdown", + "", + RANDOM_MTIME, + creationTimestamp, + true + ) + + val uploadResult = sut.execute(client3) + assertFalse(uploadResult.isSuccess) + assertEquals(RemoteOperationResult.ResultCode.USER_DISABLED, uploadResult.code) + } + private fun getCreationTimestamp(file: File): Long? { return if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { return null diff --git a/library/src/androidTest/java/com/owncloud/android/lib/resources/files/webdav/ChunkedFileUploadRemoteOperationIT.kt b/library/src/androidTest/java/com/owncloud/android/lib/resources/files/webdav/ChunkedFileUploadRemoteOperationIT.kt index 4cc3deeef1..9aa9ae0436 100644 --- a/library/src/androidTest/java/com/owncloud/android/lib/resources/files/webdav/ChunkedFileUploadRemoteOperationIT.kt +++ b/library/src/androidTest/java/com/owncloud/android/lib/resources/files/webdav/ChunkedFileUploadRemoteOperationIT.kt @@ -22,12 +22,16 @@ package com.owncloud.android.lib.resources.files.webdav import com.owncloud.android.AbstractIT +import com.owncloud.android.lib.common.OwnCloudBasicCredentials +import com.owncloud.android.lib.common.OwnCloudClientFactory import com.owncloud.android.lib.common.network.WebdavEntry import com.owncloud.android.lib.common.network.WebdavUtils import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode import com.owncloud.android.lib.resources.files.ChunkedFileUploadRemoteOperation import junit.framework.TestCase +import junit.framework.TestCase.assertEquals +import junit.framework.TestCase.assertFalse import junit.framework.TestCase.assertNotNull import org.apache.jackrabbit.webdav.client.methods.PropFindMethod import org.junit.Test @@ -73,6 +77,19 @@ class ChunkedFileUploadRemoteOperationIT : AbstractIT() { TestCase.assertSame(ResultCode.CANCELLED, uploadResult?.code) } + @Test + fun uploadWithDisabledUser() { + // use disabled user + val client3 = OwnCloudClientFactory.createOwnCloudClient(url, context, true) + client3.credentials = OwnCloudBasicCredentials("disabled", "disabled") + + val sut = genLargeUpload(true) + val uploadResult = sut.execute(client3) + + assertFalse(uploadResult.isSuccess) + assertEquals(ResultCode.USER_DISABLED, uploadResult.code) + } + @Test fun resume() { val filePath = createFile("chunkedFile.txt", BIG_FILE_ITERATION * 2) diff --git a/library/src/main/java/com/owncloud/android/lib/common/operations/ExceptionParser.java b/library/src/main/java/com/owncloud/android/lib/common/operations/ExceptionParser.java index 3367d5e8eb..2427375843 100644 --- a/library/src/main/java/com/owncloud/android/lib/common/operations/ExceptionParser.java +++ b/library/src/main/java/com/owncloud/android/lib/common/operations/ExceptionParser.java @@ -46,6 +46,8 @@ public class ExceptionParser { private static final String INVALID_PATH_EXCEPTION_STRING = "OC\\Connector\\Sabre\\Exception\\InvalidPath"; private static final String INVALID_PATH_EXCEPTION_UPLOAD_STRING = "OCP\\Files\\InvalidPathException"; private static final String VIRUS_EXCEPTION_STRING = "OCA\\DAV\\Connector\\Sabre\\Exception\\UnsupportedMediaType"; + private static final String USER_DISABLED_MESSAGE = "OC\\User\\LoginException: User disabled"; + private static final String SERVICE_UNAIVALABLE_STRING = "Sabre\\DAV\\Exception\\ServiceUnavailable"; // No namespaces private static final String ns = null; @@ -92,6 +94,10 @@ public boolean isVirusException() { return VIRUS_EXCEPTION_STRING.equalsIgnoreCase(exception) && message.startsWith("Virus"); } + public boolean isUserDisabledException() { + return SERVICE_UNAIVALABLE_STRING.equals(exception) && message.equalsIgnoreCase(USER_DISABLED_MESSAGE); + } + /** * Parse OCS node * diff --git a/library/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java b/library/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java index 23ad7a298d..2d3af0bd5d 100644 --- a/library/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java +++ b/library/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java @@ -138,7 +138,8 @@ public enum ResultCode { ETAG_UNCHANGED, VIRUS_DETECTED, FOLDER_ALREADY_EXISTS, - CANNOT_CREATE_FILE + CANNOT_CREATE_FILE, + USER_DISABLED } private boolean mSuccess = false; @@ -329,7 +330,9 @@ public RemoteOperationResult(boolean success, OkHttpMethodBase httpMethod) { public RemoteOperationResult(boolean success, HttpMethod httpMethod) { this(success, httpMethod.getStatusCode(), httpMethod.getStatusText(), httpMethod.getResponseHeaders()); - if (mHttpCode == HttpStatus.SC_BAD_REQUEST || mHttpCode == HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE) { + if (mHttpCode == HttpStatus.SC_BAD_REQUEST || + mHttpCode == HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE || + mHttpCode == HttpStatus.SC_SERVICE_UNAVAILABLE) { try { String bodyResponse = httpMethod.getResponseBodyAsString(); @@ -344,6 +347,10 @@ public RemoteOperationResult(boolean success, HttpMethod httpMethod) { mCode = ResultCode.VIRUS_DETECTED; } + if (xmlParser.isUserDisabledException()) { + mCode = ResultCode.USER_DISABLED; + } + mHttpPhrase = xmlParser.getMessage(); } } catch (Exception e) {