Skip to content
Open

wip #16999

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 @@ -218,7 +218,7 @@ protected OCCapability getCapability() throws AccountUtils.AccountNotFoundExcept

@Before
public void enableAccessibilityChecks() {
androidx.test.espresso.accessibility.AccessibilityChecks.enable().setRunChecksFromRootView(true);
androidx.test.espresso.accessibility.AccessibilityChecks.enable().setRunChecksFromRootView(false);
}

@After
Expand Down
11 changes: 2 additions & 9 deletions app/src/androidTest/java/com/owncloud/android/DownloadIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
*/
package com.owncloud.android;

import android.net.Uri;

import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.db.OCUpload;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
Expand Down Expand Up @@ -97,12 +95,7 @@ private void verifyDownload(OCFile file1, OCFile file2) {
assertTrue(new File(file1.getStoragePath()).exists());
assertTrue(new File(file2.getStoragePath()).exists());

// test against hardcoded path to make sure that it is correct
assertEquals("/storage/emulated/0/Android/media/"+targetContext.getPackageName()+"/nextcloud/" +
Uri.encode(account.name, "@") + "/testUpload/nonEmpty.txt",
file1.getStoragePath());
assertEquals("/storage/emulated/0/Android/media/"+targetContext.getPackageName()+"/nextcloud/" +
Uri.encode(account.name, "@") + "/testUpload/nonEmpty2.txt",
file2.getStoragePath());
assertEquals(FileStorageUtils.getDefaultSavePathFor(account.name, file1), file1.getStoragePath());
assertEquals(FileStorageUtils.getDefaultSavePathFor(account.name, file2), file2.getStoragePath());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ import com.owncloud.android.operations.UploadFileOperation
import org.junit.After
import org.junit.Assert
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.MockitoAnnotations
import org.mockito.junit.MockitoJUnit
import org.mockito.junit.MockitoRule
import java.io.File
import java.util.Random
import java.util.UUID
Expand All @@ -47,6 +49,9 @@ import java.util.function.Supplier
@RunWith(AndroidJUnit4::class)
@SmallTest
class UploadStorageManagerTest : AbstractIT() {
@get:Rule
val mockitoRule: MockitoRule = MockitoJUnit.rule()

private lateinit var uploadsStorageManager: UploadsStorageManager

@Mock
Expand All @@ -58,8 +63,6 @@ class UploadStorageManagerTest : AbstractIT() {

@Before
fun setUp() {
MockitoAnnotations.openMocks(this)

val instrumentationCtx = ApplicationProvider.getApplicationContext<Context>()
val contentResolver = instrumentationCtx.contentResolver
uploadsStorageManager = UploadsStorageManager(currentAccountProvider, contentResolver)
Expand Down Expand Up @@ -233,7 +236,11 @@ class UploadStorageManagerTest : AbstractIT() {

@After
fun tearDown() {
deleteAllUploads()
userAccountManager.removeUser(user2)
if (::uploadsStorageManager.isInitialized) {
deleteAllUploads()
}
if (::userAccountManager.isInitialized && ::user2.isInitialized) {
userAccountManager.removeUser(user2)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -940,13 +940,13 @@
String expectedPath = FileStorageUtils.getDefaultSavePathFor(user.getAccountName(), ocFile);
if (!localPath.equalsIgnoreCase(expectedPath)) {
Log_OC.w(TAG, "removeLocalCopyIfNeeded: Path mismatch! Expected " + expectedPath
+ " but found " + localPath + ". Skipping deletion to prevent data loss.");
+ " but found " + localPath + ". Deleting from actual local path.");
}

Log_OC.d(TAG, "removeLocalCopyIfNeeded: deleting local file -> " + localPath);
boolean success = false;
try {
success = new File(expectedPath).delete();
success = new File(localPath).delete();

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
} catch (Exception e) {
Log_OC.e(TAG, "removeLocalCopyIfNeeded: deletion error: ", e);
}
Expand Down
Loading