Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work related to connection options logic #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

3a4oT
Copy link
Contributor

@3a4oT 3a4oT commented Mar 11, 2020

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.

@3a4oT
Copy link
Contributor Author

3a4oT commented Mar 11, 2020

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),
    ]
}

@3a4oT
Copy link
Contributor Author

3a4oT commented Mar 11, 2020

cc @Joannis , @aaronjedwards

@Joannis
Copy link
Collaborator

Joannis commented Mar 11, 2020

@3a4oT why don't you just allocate a bytebuffer using ByteBufferAllocator?

@3a4oT 3a4oT force-pushed the login-options-validation branch from c616b47 to 0f2786d Compare March 11, 2020 12:22
@3a4oT
Copy link
Contributor Author

3a4oT commented Mar 11, 2020

@Joannis thanks. Done.

@aaronjedwards aaronjedwards changed the title Work related to connection options logic. Work related to connection options logic Jun 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants