|
@@ -8,8 +8,9 @@
|
|
package com.nextcloud.utils
|
|
package com.nextcloud.utils
|
|
|
|
|
|
import com.nextcloud.utils.fileNameValidator.FileNameValidator
|
|
import com.nextcloud.utils.fileNameValidator.FileNameValidator
|
|
-import com.owncloud.android.AbstractIT
|
|
|
|
|
|
+import com.owncloud.android.AbstractOnServerIT
|
|
import com.owncloud.android.R
|
|
import com.owncloud.android.R
|
|
|
|
+import com.owncloud.android.lib.resources.status.NextcloudVersion
|
|
import com.owncloud.android.lib.resources.status.OCCapability
|
|
import com.owncloud.android.lib.resources.status.OCCapability
|
|
import org.junit.Assert.assertEquals
|
|
import org.junit.Assert.assertEquals
|
|
import org.junit.Assert.assertFalse
|
|
import org.junit.Assert.assertFalse
|
|
@@ -19,7 +20,7 @@ import org.junit.Before
|
|
import org.junit.Test
|
|
import org.junit.Test
|
|
|
|
|
|
@Suppress("TooManyFunctions")
|
|
@Suppress("TooManyFunctions")
|
|
-class FileNameValidatorTests : AbstractIT() {
|
|
|
|
|
|
+class FileNameValidatorTests : AbstractOnServerIT() {
|
|
|
|
|
|
private var capability: OCCapability = fileDataStorageManager.getCapability(account.name)
|
|
private var capability: OCCapability = fileDataStorageManager.getCapability(account.name)
|
|
|
|
|
|
@@ -33,13 +34,15 @@ class FileNameValidatorTests : AbstractIT() {
|
|
"lpt0", "lpt1", "lpt2", "lpt3", "lpt4", "lpt5", "lpt6", "lpt7",
|
|
"lpt0", "lpt1", "lpt2", "lpt3", "lpt4", "lpt5", "lpt6", "lpt7",
|
|
"lpt8", "lpt9", "lpt¹", "lpt²", "lpt³"]
|
|
"lpt8", "lpt9", "lpt¹", "lpt²", "lpt³"]
|
|
"""
|
|
"""
|
|
- forbiddenFilenameExtensionJson = """[".filepart",".part"]"""
|
|
|
|
|
|
+ forbiddenFilenameExtensionJson = """[" ",".",".part",".part"]"""
|
|
forbiddenFilenameCharactersJson = """["<", ">", ":", "\\\\", "/", "|", "?", "*", "&"]"""
|
|
forbiddenFilenameCharactersJson = """["<", ">", ":", "\\\\", "/", "|", "?", "*", "&"]"""
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
fun testInvalidCharacter() {
|
|
fun testInvalidCharacter() {
|
|
|
|
+ testOnlyOnServer(NextcloudVersion.nextcloud_30)
|
|
|
|
+
|
|
val result = FileNameValidator.checkFileName("file<name", capability, targetContext)
|
|
val result = FileNameValidator.checkFileName("file<name", capability, targetContext)
|
|
assertEquals(
|
|
assertEquals(
|
|
String.format(targetContext.getString(R.string.file_name_validator_error_invalid_character), "<"),
|
|
String.format(targetContext.getString(R.string.file_name_validator_error_invalid_character), "<"),
|
|
@@ -49,26 +52,43 @@ class FileNameValidatorTests : AbstractIT() {
|
|
|
|
|
|
@Test
|
|
@Test
|
|
fun testReservedName() {
|
|
fun testReservedName() {
|
|
|
|
+ testOnlyOnServer(NextcloudVersion.nextcloud_30)
|
|
|
|
+
|
|
val result = FileNameValidator.checkFileName("CON", capability, targetContext)
|
|
val result = FileNameValidator.checkFileName("CON", capability, targetContext)
|
|
- assertEquals(targetContext.getString(R.string.file_name_validator_error_reserved_names, "CON"), result)
|
|
|
|
|
|
+ assertEquals(targetContext.getString(R.string.file_name_validator_error_reserved_names, "con"), result)
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
fun testForbiddenFilenameExtension() {
|
|
fun testForbiddenFilenameExtension() {
|
|
- val result = FileNameValidator.checkFileName("my_fav_file.filepart", capability, targetContext)
|
|
|
|
|
|
+ testOnlyOnServer(NextcloudVersion.nextcloud_30)
|
|
|
|
+
|
|
|
|
+ val result = FileNameValidator.checkFileName("my_fav_file.part", capability, targetContext)
|
|
assertEquals(
|
|
assertEquals(
|
|
- targetContext.getString(R.string.file_name_validator_error_forbidden_file_extensions, "filepart"),
|
|
|
|
|
|
+ targetContext.getString(R.string.file_name_validator_error_forbidden_file_extensions, ".part"),
|
|
result
|
|
result
|
|
)
|
|
)
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
fun testEndsWithSpaceOrPeriod() {
|
|
fun testEndsWithSpaceOrPeriod() {
|
|
- val result = FileNameValidator.checkFileName("filename ", capability, targetContext)
|
|
|
|
- assertEquals(targetContext.getString(R.string.file_name_validator_error_ends_with_space_period), result)
|
|
|
|
-
|
|
|
|
- val result2 = FileNameValidator.checkFileName("filename.", capability, targetContext)
|
|
|
|
- assertEquals(targetContext.getString(R.string.file_name_validator_error_ends_with_space_period), result2)
|
|
|
|
|
|
+ val firstFilename = "test "
|
|
|
|
+ val secondFilename = "test."
|
|
|
|
+ val result = FileNameValidator.checkFileName(firstFilename, capability, targetContext)
|
|
|
|
+ val result2 = FileNameValidator.checkFileName(secondFilename, capability, targetContext)
|
|
|
|
+
|
|
|
|
+ if (capability.version.isOlderThan(NextcloudVersion.nextcloud_30)) {
|
|
|
|
+ assertEquals(null, result)
|
|
|
|
+ assertEquals(null, result2)
|
|
|
|
+ } else {
|
|
|
|
+ assertEquals(
|
|
|
|
+ targetContext.getString(R.string.file_name_validator_error_forbidden_file_extensions, " "),
|
|
|
|
+ result
|
|
|
|
+ )
|
|
|
|
+ assertEquals(
|
|
|
|
+ targetContext.getString(R.string.file_name_validator_error_forbidden_file_extensions, "."),
|
|
|
|
+ result2
|
|
|
|
+ )
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
@@ -79,7 +99,7 @@ class FileNameValidatorTests : AbstractIT() {
|
|
|
|
|
|
@Test
|
|
@Test
|
|
fun testFileAlreadyExists() {
|
|
fun testFileAlreadyExists() {
|
|
- val existingFiles = mutableSetOf("existingFile")
|
|
|
|
|
|
+ val existingFiles = setOf("existingFile")
|
|
val result = FileNameValidator.checkFileName("existingFile", capability, targetContext, existingFiles)
|
|
val result = FileNameValidator.checkFileName("existingFile", capability, targetContext, existingFiles)
|
|
assertEquals(targetContext.getString(R.string.file_already_exists), result)
|
|
assertEquals(targetContext.getString(R.string.file_already_exists), result)
|
|
}
|
|
}
|
|
@@ -98,7 +118,7 @@ class FileNameValidatorTests : AbstractIT() {
|
|
|
|
|
|
@Test
|
|
@Test
|
|
fun testIsFileNameAlreadyExist() {
|
|
fun testIsFileNameAlreadyExist() {
|
|
- val existingFiles = mutableSetOf("existingFile")
|
|
|
|
|
|
+ val existingFiles = setOf("existingFile")
|
|
assertTrue(FileNameValidator.isFileNameAlreadyExist("existingFile", existingFiles))
|
|
assertTrue(FileNameValidator.isFileNameAlreadyExist("existingFile", existingFiles))
|
|
assertFalse(FileNameValidator.isFileNameAlreadyExist("newFile", existingFiles))
|
|
assertFalse(FileNameValidator.isFileNameAlreadyExist("newFile", existingFiles))
|
|
}
|
|
}
|
|
@@ -114,6 +134,8 @@ class FileNameValidatorTests : AbstractIT() {
|
|
|
|
|
|
@Test
|
|
@Test
|
|
fun testFolderPathWithReservedName() {
|
|
fun testFolderPathWithReservedName() {
|
|
|
|
+ testOnlyOnServer(NextcloudVersion.nextcloud_30)
|
|
|
|
+
|
|
val folderPath = "CON"
|
|
val folderPath = "CON"
|
|
val filePaths = listOf("file1.txt", "file2.doc", "file3.jpg")
|
|
val filePaths = listOf("file1.txt", "file2.doc", "file3.jpg")
|
|
|
|
|
|
@@ -123,6 +145,8 @@ class FileNameValidatorTests : AbstractIT() {
|
|
|
|
|
|
@Test
|
|
@Test
|
|
fun testFilePathWithReservedName() {
|
|
fun testFilePathWithReservedName() {
|
|
|
|
+ testOnlyOnServer(NextcloudVersion.nextcloud_30)
|
|
|
|
+
|
|
val folderPath = "validFolder"
|
|
val folderPath = "validFolder"
|
|
val filePaths = listOf("file1.txt", "PRN.doc", "file3.jpg")
|
|
val filePaths = listOf("file1.txt", "PRN.doc", "file3.jpg")
|
|
|
|
|
|
@@ -132,6 +156,8 @@ class FileNameValidatorTests : AbstractIT() {
|
|
|
|
|
|
@Test
|
|
@Test
|
|
fun testFolderPathWithInvalidCharacter() {
|
|
fun testFolderPathWithInvalidCharacter() {
|
|
|
|
+ testOnlyOnServer(NextcloudVersion.nextcloud_30)
|
|
|
|
+
|
|
val folderPath = "invalid<Folder"
|
|
val folderPath = "invalid<Folder"
|
|
val filePaths = listOf("file1.txt", "file2.doc", "file3.jpg")
|
|
val filePaths = listOf("file1.txt", "file2.doc", "file3.jpg")
|
|
|
|
|
|
@@ -141,6 +167,8 @@ class FileNameValidatorTests : AbstractIT() {
|
|
|
|
|
|
@Test
|
|
@Test
|
|
fun testFilePathWithInvalidCharacter() {
|
|
fun testFilePathWithInvalidCharacter() {
|
|
|
|
+ testOnlyOnServer(NextcloudVersion.nextcloud_30)
|
|
|
|
+
|
|
val folderPath = "validFolder"
|
|
val folderPath = "validFolder"
|
|
val filePaths = listOf("file1.txt", "file|2.doc", "file3.jpg")
|
|
val filePaths = listOf("file1.txt", "file|2.doc", "file3.jpg")
|
|
|
|
|
|
@@ -154,7 +182,7 @@ class FileNameValidatorTests : AbstractIT() {
|
|
val filePaths = listOf("file1.txt", "file2.doc", "file3.jpg")
|
|
val filePaths = listOf("file1.txt", "file2.doc", "file3.jpg")
|
|
|
|
|
|
val result = FileNameValidator.checkFolderAndFilePaths(folderPath, filePaths, capability, targetContext)
|
|
val result = FileNameValidator.checkFolderAndFilePaths(folderPath, filePaths, capability, targetContext)
|
|
- assertFalse(result)
|
|
|
|
|
|
+ assertEquals(capability.version.isOlderThan(NextcloudVersion.nextcloud_30), result)
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
@@ -163,11 +191,13 @@ class FileNameValidatorTests : AbstractIT() {
|
|
val filePaths = listOf("file1.txt", "file2.doc", "file3.")
|
|
val filePaths = listOf("file1.txt", "file2.doc", "file3.")
|
|
|
|
|
|
val result = FileNameValidator.checkFolderAndFilePaths(folderPath, filePaths, capability, targetContext)
|
|
val result = FileNameValidator.checkFolderAndFilePaths(folderPath, filePaths, capability, targetContext)
|
|
- assertFalse(result)
|
|
|
|
|
|
+ assertEquals(capability.version.isOlderThan(NextcloudVersion.nextcloud_30), result)
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
fun testFilePathWithNestedFolder() {
|
|
fun testFilePathWithNestedFolder() {
|
|
|
|
+ testOnlyOnServer(NextcloudVersion.nextcloud_30)
|
|
|
|
+
|
|
val folderPath = "validFolder\\secondValidFolder\\CON"
|
|
val folderPath = "validFolder\\secondValidFolder\\CON"
|
|
val filePaths = listOf("file1.txt", "file2.doc", "file3.")
|
|
val filePaths = listOf("file1.txt", "file2.doc", "file3.")
|
|
|
|
|
|
@@ -185,6 +215,8 @@ class FileNameValidatorTests : AbstractIT() {
|
|
|
|
|
|
@Test
|
|
@Test
|
|
fun testOnlyFolderPathWithOneReservedName() {
|
|
fun testOnlyFolderPathWithOneReservedName() {
|
|
|
|
+ testOnlyOnServer(NextcloudVersion.nextcloud_30)
|
|
|
|
+
|
|
val folderPath = "/A1/Aaaww/CON/W/C2/"
|
|
val folderPath = "/A1/Aaaww/CON/W/C2/"
|
|
|
|
|
|
val result = FileNameValidator.checkFolderAndFilePaths(folderPath, listOf(), capability, targetContext)
|
|
val result = FileNameValidator.checkFolderAndFilePaths(folderPath, listOf(), capability, targetContext)
|