swift-tds
swift-tds copied to clipboard
Work related to connection options logic
Motivation
tried to fix the TODO item.
https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-tds/773a62b6-ee89-4c02-9e5e-344882630aac
Login Data Validation Rules
cchHostName MUST specify at most 128 Unicode characters.
cchUserName MUST specify at most 128 Unicode characters.
cchPassword MUST specify at most 128 Unicode characters.
cchAppName MUST specify at most 128 Unicode characters.
cchServerName MUST specify at most 128 Unicode characters.
cbExtension MUST NOT exceed 255 bytes.
cchCltIntName MUST specify at most 128 Unicode characters.
cchLanguage MUST specify at most 128 Unicode characters.
cchDatabase MUST specify at most 128 Unicode characters.
cchAtchDBFile MUST specify at most 260 Unicode characters.
cchChangePassword MUST specify at most 128 Unicode characters.
Modification
- added connection option validation.
- added a new error type.
- Fixed some typos.
I want to add tests but stuck with mocking ByteBuffer
. If fails with a Precondition failed: new writerIndex: 259, expected: range(0, 255): file
Do you have any suggestions on how to mock it?
import XCTest
import NIO
@testable import TDS
final class TDSTests: XCTestCase {
func testLoginOptionValidation() {
let lopremipusm129 = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus gravida mauris eu tincidunt venenatis. Aliquam nec sem volutpat."
let auth: TDSMessages.Login7Message = TDSMessages.Login7Message(
hostname: lopremipusm129,
username: "username",
password: "password",
appName: "TDSTester",
serverName: "",
clientInterfaceName: "SwiftTDS",
language: "",
database: "database",
sspiData: "")
var buffer = ByteBuffer(ByteBufferView(repeating: 0, count: 255))
do {
try auth.serialize(into: &buffer)
} catch {
XCTAssertTrue(error is TDSError)
}
}
static var allTests = [
("testLoginOptionValidation", testLoginOptionValidation),
]
}
cc @Joannis , @aaronjedwards
@3a4oT why don't you just allocate a bytebuffer using ByteBufferAllocator?
@Joannis thanks. Done.