-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WIP Signed-off-by: Milen Pivchev <[email protected]> * WIP Signed-off-by: Milen Pivchev <[email protected]> * cleanup Signed-off-by: Milen Pivchev <[email protected]> * WIP Signed-off-by: Milen Pivchev <[email protected]> * WIP Signed-off-by: Milen Pivchev <[email protected]> * Make singleton Signed-off-by: Milen Pivchev <[email protected]> * WIP Signed-off-by: Milen Pivchev <[email protected]> * WIP Signed-off-by: Milen Pivchev <[email protected]> * WIP Signed-off-by: Milen Pivchev <[email protected]> * WIP Signed-off-by: Milen Pivchev <[email protected]> * WIP Signed-off-by: Milen Pivchev <[email protected]> * WIP Signed-off-by: Milen Pivchev <[email protected]> * WIP Signed-off-by: Milen Pivchev <[email protected]> * WIP Signed-off-by: Milen Pivchev <[email protected]> * WIP Signed-off-by: Milen Pivchev <[email protected]> * WIP Signed-off-by: Milen Pivchev <[email protected]> * WIP Signed-off-by: Milen Pivchev <[email protected]> * WIP Signed-off-by: Milen Pivchev <[email protected]> * WIP Signed-off-by: Milen Pivchev <[email protected]> * WIP Signed-off-by: Milen Pivchev <[email protected]> --------- Signed-off-by: Milen Pivchev <[email protected]> Co-authored-by: Milen Pivchev <[email protected]> Signed-off-by: Milen Pivchev <[email protected]> # Conflicts: # Sources/NextcloudKit/Utils/FileNameValidator.swift # Tests/NextcloudKitUnitTests/FileNameValidatorTests.swift
- Loading branch information
1 parent
a2f4cb3
commit 7c17db8
Showing
2 changed files
with
120 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
Tests/NextcloudKitUnitTests/FileNameValidatorTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// | ||
// fileNameValidatorTests.swift | ||
// | ||
// | ||
// Created by Milen Pivchev on 12.07.24. | ||
// Copyright © 2024 Milen Pivchev. All rights reserved. | ||
// | ||
// Author: Milen Pivchev <[email protected]> | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
// | ||
|
||
import XCTest | ||
@testable import NextcloudKit | ||
|
||
class FileNameValidatorTests: XCTestCase { | ||
let fileNameValidator = FileNameValidator.shared | ||
|
||
override func setUp() { | ||
fileNameValidator.setup( | ||
forbiddenFileNames: [".htaccess",".htaccess"], | ||
forbiddenFileNameBasenames: ["con", "prn", "aux", "nul", "com0", "com1", "com2", "com3", "com4", | ||
"com5", "com6", "com7", "com8", "com9", "com¹", "com²", "com³", | ||
"lpt0", "lpt1", "lpt2", "lpt3", "lpt4", "lpt5", "lpt6", "lpt7", | ||
"lpt8", "lpt9", "lpt¹", "lpt²", "lpt³"], | ||
forbiddenFileNameCharacters: ["<", ">", ":", "\\\\", "/", "|", "?", "*", "&"], | ||
forbiddenFileNameExtensions: [".filepart",".part"] | ||
) | ||
super.setUp() | ||
} | ||
|
||
func testInvalidCharacter() { | ||
let result = fileNameValidator.checkFileName("file<name") | ||
XCTAssertEqual(result?.errorDescription, fileNameValidator.fileInvalidCharacterError.errorDescription) | ||
} | ||
|
||
func testReservedName() { | ||
let result = fileNameValidator.checkFileName("CON") | ||
XCTAssertEqual(result?.errorDescription, fileNameValidator.fileReservedNameError.errorDescription) | ||
} | ||
|
||
func testForbiddenFilenameExtension() { | ||
let result = fileNameValidator.checkFileName("my_fav_file.filepart") | ||
XCTAssertEqual(result?.errorDescription, fileNameValidator.fileForbiddenFileExtensionError.errorDescription) | ||
} | ||
|
||
func testEndsWithSpaceOrPeriod() { | ||
let result = fileNameValidator.checkFileName("filename ") | ||
XCTAssertEqual(result?.errorDescription, fileNameValidator.fileEndsWithSpacePeriodError.errorDescription) | ||
|
||
let result2 = fileNameValidator.checkFileName("filename.") | ||
XCTAssertEqual(result2?.errorDescription, fileNameValidator.fileEndsWithSpacePeriodError.errorDescription) | ||
} | ||
|
||
func testValidFileName() { | ||
let result = fileNameValidator.checkFileName("validFileName") | ||
XCTAssertNil(result?.errorDescription) | ||
} | ||
|
||
func testValidFolderAndFilePaths() { | ||
let folderPath = "validFolder" | ||
|
||
let result = fileNameValidator.checkFolderPath(folderPath: folderPath) | ||
XCTAssertTrue(result) | ||
} | ||
|
||
func testFolderPathWithReservedName() { | ||
let folderPath = "CON" | ||
|
||
let result = fileNameValidator.checkFolderPath(folderPath: folderPath) | ||
XCTAssertFalse(result) | ||
} | ||
|
||
func testFolderPathWithInvalidCharacter() { | ||
let folderPath = "invalid<Folder" | ||
|
||
let result = fileNameValidator.checkFolderPath(folderPath: folderPath) | ||
XCTAssertFalse(result) | ||
} | ||
|
||
func testFolderPathEndingWithSpace() { | ||
let folderPath = "folderWithSpace " | ||
|
||
let result = fileNameValidator.checkFolderPath(folderPath: folderPath) | ||
XCTAssertFalse(result) | ||
} | ||
|
||
func testFolderPathEndingWithPeriod() { | ||
let folderPath = "validFolder." | ||
|
||
let result = fileNameValidator.checkFolderPath(folderPath: folderPath) | ||
XCTAssertFalse(result) | ||
} | ||
|
||
func testFilePathWithNestedFolder() { | ||
let folderPath = "validFolder/secondValidFolder/CON" | ||
|
||
let result = fileNameValidator.checkFolderPath(folderPath: folderPath) | ||
XCTAssertFalse(result) | ||
} | ||
} |