Browse Source

Merge pull request #11567 from nextcloud/nmc/fileOwnerNameIgnoreCase

Fix file owner and account name check ignore case.
Andy Scherzinger 2 years ago
parent
commit
a139938300

+ 22 - 0
app/src/androidTest/java/com/nextcloud/client/account/UserAccountManagerImplTest.java

@@ -7,6 +7,7 @@ import android.os.Bundle;
 import com.nextcloud.client.preferences.AppPreferences;
 import com.nextcloud.client.preferences.AppPreferences;
 import com.nextcloud.client.preferences.AppPreferencesImpl;
 import com.nextcloud.client.preferences.AppPreferencesImpl;
 import com.owncloud.android.AbstractOnServerIT;
 import com.owncloud.android.AbstractOnServerIT;
+import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.lib.common.accounts.AccountUtils;
 import com.owncloud.android.lib.common.accounts.AccountUtils;
 
 
 import org.junit.Before;
 import org.junit.Before;
@@ -48,4 +49,25 @@ public class UserAccountManagerImplTest extends AbstractOnServerIT {
         // assume that userId == loginname (as we manually set it)
         // assume that userId == loginname (as we manually set it)
         assertEquals(userId, accountManager.getUserData(account, AccountUtils.Constants.KEY_USER_ID));
         assertEquals(userId, accountManager.getUserData(account, AccountUtils.Constants.KEY_USER_ID));
     }
     }
+
+    @Test
+    public void checkName() {
+        UserAccountManagerImpl sut = new UserAccountManagerImpl(targetContext, accountManager);
+
+        Account owner = new Account("John@nextcloud.local", "nextcloud");
+        Account account1 = new Account("John@nextcloud.local", "nextcloud");
+        Account account2 = new Account("john@nextcloud.local", "nextcloud");
+
+        OCFile file1 = new OCFile("/test1.pdf");
+        file1.setOwnerId("John");
+
+        assertTrue(sut.accountOwnsFile(file1, owner));
+        assertTrue(sut.accountOwnsFile(file1, account1));
+        assertTrue(sut.accountOwnsFile(file1, account2));
+
+        file1.setOwnerId("john");
+        assertTrue(sut.accountOwnsFile(file1, owner));
+        assertTrue(sut.accountOwnsFile(file1, account1));
+        assertTrue(sut.accountOwnsFile(file1, account2));
+    }
 }
 }

+ 3 - 1
app/src/main/java/com/nextcloud/client/account/UserAccountManagerImpl.java

@@ -2,7 +2,9 @@
  * Nextcloud Android client application
  * Nextcloud Android client application
  *
  *
  * @author Chris Narkiewicz
  * @author Chris Narkiewicz
+ * @author TSI-mc
  * Copyright (C) 2019 Chris Narkiewicz
  * Copyright (C) 2019 Chris Narkiewicz
+ * Copyright (C) 2023 TSI-mc
  *
  *
  * This program is free software; you can redistribute it and/or
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
@@ -340,7 +342,7 @@ public class UserAccountManagerImpl implements UserAccountManager {
     @Override
     @Override
     public  boolean accountOwnsFile(OCFile file, Account account) {
     public  boolean accountOwnsFile(OCFile file, Account account) {
         final String ownerId = file.getOwnerId();
         final String ownerId = file.getOwnerId();
-        return TextUtils.isEmpty(ownerId) || account.name.split("@")[0].equals(ownerId);
+        return TextUtils.isEmpty(ownerId) || account.name.split("@")[0].equalsIgnoreCase(ownerId);
     }
     }
 
 
     @Override
     @Override