Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ class AuthenticationStateMachineTests: XCTestCase {
XCTAssertEqual(state.authenticationMessageReceived(.ok), .wait)
}

func testAuthenticateMD5WithoutPassword() {
let authContext = AuthContext(username: "test", password: nil, database: "test")
var state = ConnectionStateMachine(.waitingToStartAuthentication)
let salt: (UInt8, UInt8, UInt8, UInt8) = (0, 1, 2, 3)

XCTAssertEqual(state.provideAuthenticationContext(authContext), .sendStartupMessage(authContext))
XCTAssertEqual(state.authenticationMessageReceived(.md5(salt: salt)),
.closeConnectionAndCleanup(.init(action: .close, tasks: [], error: .authMechanismRequiresPassword, closePromise: nil)))
}

func testAuthenticateOkAfterStartUpWithoutAuthChallenge() {
let authContext = AuthContext(username: "test", password: "abc123", database: "test")
var state = ConnectionStateMachine(.waitingToStartAuthentication)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ class ConnectionStateMachineTests: XCTestCase {
XCTAssertEqual(state.authenticationMessageReceived(.md5(salt: salt)), .sendPasswordMessage(.md5(salt: salt), authContext))
}

func testSSLStartupFailHandler() {
struct SSLHandlerAddError: Error, Equatable {}

var state = ConnectionStateMachine()
XCTAssertEqual(state.connected(requireTLS: true), .sendSSLRequest)
XCTAssertEqual(state.sslSupportedReceived(), .establishSSLConnection)
let failError: PSQLError = .failedToAddSSLHandler(underlying: SSLHandlerAddError())
XCTAssertEqual(state.errorHappened(failError), .closeConnectionAndCleanup(.init(action: .close, tasks: [], error: failError, closePromise: nil)))
}

func testSSLStartupSSLUnsupported() {
var state = ConnectionStateMachine()

Expand Down
2 changes: 2 additions & 0 deletions Tests/PostgresNIOTests/New/PSQLBackendMessageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ class PSQLBackendMessageTests: XCTestCase {
XCTAssertEqual("\(PSQLBackendMessage.authentication(.sspi))",
".authentication(.sspi)")

XCTAssertEqual("\(PSQLBackendMessage.parameterStatus(.init(parameter: "foo", value: "bar")))",
#".parameterStatus(parameter: "foo", value: "bar")"#)
XCTAssertEqual("\(PSQLBackendMessage.backendKeyData(.init(processID: 1234, secretKey: 4567)))",
".backendKeyData(processID: 1234, secretKey: 4567)")

Expand Down