Skip to content

Commit a5cdfbd

Browse files
Merge pull request #887 from nextcloud/fix/userid-encoding-missing
Restore userID encoding when building files DAV uri
2 parents b2cdf32 + 43c3fc4 commit a5cdfbd

File tree

5 files changed

+66
-7
lines changed

5 files changed

+66
-7
lines changed

.drone.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ services:
107107
- su www-data -c "OC_PASS=user2 php /var/www/html/occ user:add --password-from-env --display-name='User Two' user2"
108108
- su www-data -c "OC_PASS=user3 php /var/www/html/occ user:add --password-from-env --display-name='User Three' user3"
109109
- su www-data -c "OC_PASS=test php /var/www/html/occ user:add --password-from-env --display-name='Test@Test' test@test"
110+
- su www-data -c "OC_PASS=test php /var/www/html/occ user:add --password-from-env --display-name='Test Spaces' 'test test'"
110111
- su www-data -c "php /var/www/html/occ user:setting user2 files quota 1G"
111112
- su www-data -c "php /var/www/html/occ group:add users"
112113
- su www-data -c "php /var/www/html/occ group:adduser users user1"
@@ -201,6 +202,7 @@ services:
201202
- su www-data -c "OC_PASS=user2 php /var/www/html/occ user:add --password-from-env --display-name='User Two' user2"
202203
- su www-data -c "OC_PASS=user3 php /var/www/html/occ user:add --password-from-env --display-name='User Three' user3"
203204
- su www-data -c "OC_PASS=test php /var/www/html/occ user:add --password-from-env --display-name='Test@Test' test@test"
205+
- su www-data -c "OC_PASS=test php /var/www/html/occ user:add --password-from-env --display-name='Test Spaces' 'test test'"
204206
- su www-data -c "php /var/www/html/occ user:setting user2 files quota 1G"
205207
- su www-data -c "php /var/www/html/occ group:add users"
206208
- su www-data -c "php /var/www/html/occ group:adduser users user1"
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Nextcloud Android Library is available under MIT license
3+
*
4+
* @author Álvaro Brey Vilas
5+
* Copyright (C) 2022 Álvaro Brey Vilas
6+
* Copyright (C) 2022 Nextcloud GmbH
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
22+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
28+
package com.owncloud.android.lib.common
29+
30+
import com.owncloud.android.AbstractIT
31+
import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation
32+
import org.junit.Assert
33+
import org.junit.Test
34+
import org.junit.runner.RunWith
35+
import org.junit.runners.Parameterized
36+
37+
@RunWith(Parameterized::class)
38+
class UsernameVariationsIT(private val username: String) : AbstractIT() {
39+
companion object {
40+
@Parameterized.Parameters(name = "{0}")
41+
@JvmStatic
42+
fun data(): Collection<Array<Any>> = listOf(
43+
arrayOf("test"),
44+
arrayOf("test test"),
45+
arrayOf("test@test")
46+
)
47+
}
48+
49+
@Test
50+
fun testExistenceCheckWithUsername() {
51+
val ocClient = OwnCloudClientFactory.createOwnCloudClient(url, context, true)
52+
ocClient.credentials = OwnCloudBasicCredentials(username, "test")
53+
ocClient.userId = username // for test same as userId
54+
55+
val existenceCheck = ExistenceCheckRemoteOperation("/", false).execute(ocClient)
56+
Assert.assertTrue(existenceCheck.isSuccess)
57+
}
58+
}

library/src/main/java/com/nextcloud/common/NextcloudClient.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class NextcloudClient private constructor(
180180
}
181181

182182
fun getUserIdEncoded(): String {
183-
return UserIdEncoder.encode(delegate.userId!!)
183+
return delegate.userIdEncoded!!
184184
}
185185

186186
fun getUserIdPlain(): String {

library/src/main/java/com/nextcloud/common/NextcloudUriDelegate.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ class NextcloudUriDelegate(baseUri: Uri, var userId: String?) : NextcloudUriProv
4141

4242
constructor(baseUri: Uri) : this(baseUri, null)
4343

44+
val userIdEncoded: String?
45+
get() = userId?.let { UserIdEncoder.encode(it) }
46+
4447
/**
4548
* Root URI of the Nextcloud server
4649
*/
@@ -51,7 +54,7 @@ class NextcloudUriDelegate(baseUri: Uri, var userId: String?) : NextcloudUriProv
5154
}
5255

5356
override val filesDavUri: Uri
54-
get() = Uri.parse("$davUri/files/$userId")
57+
get() = Uri.parse("$davUri/files/$userIdEncoded")
5558
override val uploadUri: Uri
5659
get() = Uri.parse(baseUri.toString() + AccountUtils.DAV_UPLOAD)
5760
override val davUri: Uri

library/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -433,11 +433,7 @@ private void logCookie(Cookie cookie) {
433433
* @return uri-encoded userId
434434
*/
435435
public String getUserId() {
436-
final String userId = nextcloudUriDelegate.getUserId();
437-
if (userId == null) {
438-
return null;
439-
}
440-
return UserIdEncoder.encode(userId);
436+
return nextcloudUriDelegate.getUserIdEncoded();
441437
}
442438

443439
public String getUserIdPlain() {

0 commit comments

Comments
 (0)