From 5b775867cb87433ed7bca42ad1f726544eb0c1af Mon Sep 17 00:00:00 2001 From: Kishikawa Katsumi Date: Sun, 8 Sep 2024 12:30:11 +0900 Subject: [PATCH] Add test --- Tests/SMBClientTests/SMBClientTests.swift | 32 +++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Tests/SMBClientTests/SMBClientTests.swift b/Tests/SMBClientTests/SMBClientTests.swift index 5656f33..f748b57 100644 --- a/Tests/SMBClientTests/SMBClientTests.swift +++ b/Tests/SMBClientTests/SMBClientTests.swift @@ -544,6 +544,38 @@ final class SMBClientTests: XCTestCase { try await assertDirectoryDoesNotExist(at: remotePath, client: client) } + func testUploadInvalidCharacterPath() async throws { + let user = alice + let client = SMBClient(host: "localhost", port: 4445) + try await client.login(username: user.username, password: user.password) + try await client.connectShare(user.share) + + let length = 1024 + var data = Data(count: length) + for i in 0..", "?", #"\"#, "|"] + for invalidCharacter in invalidCharacters { + let filename = invalidCharacter + do { + try await client.upload(content: data, path: filename) + } catch let error as ErrorResponse { + if ["/", #"\"#].contains(invalidCharacter) { + XCTAssert(NTStatus(error.header.status) == .objectNameCollision) + } else { + XCTAssert(NTStatus(error.header.status) == .objectNameInvalid) + } + } catch { + XCTFail() + } + } + + try await client.treeDisconnect() + try await client.logoff() + } + func testDeleteFile() async throws { let user = alice