|
@@ -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)
|
|
|
|
|
|
@@ -40,6 +41,8 @@ class FileNameValidatorTests : AbstractIT() {
|
|
|
|
|
|
@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,12 +52,16 @@ 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() {
|
|
|
|
+ testOnlyOnServer(NextcloudVersion.nextcloud_30)
|
|
|
|
+
|
|
val result = FileNameValidator.checkFileName("my_fav_file.filepart", capability, targetContext)
|
|
val result = FileNameValidator.checkFileName("my_fav_file.filepart", 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, "filepart"),
|
|
@@ -79,7 +86,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 +105,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 +121,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 +132,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 +143,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 +154,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")
|
|
|
|
|
|
@@ -168,6 +183,8 @@ class FileNameValidatorTests : AbstractIT() {
|
|
|
|
|
|
@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 +202,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)
|