Skip to content

Commit 1140dd9

Browse files
authored
Add one Auth and one SSL test case (#159)
Adding two test cases as a by product of some other work... - Add a test case for instances in which adding a `SSLHandler` fails - Add a test case for instances in which a md5 password requested but none is provided.
1 parent 6629d63 commit 1140dd9

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

Tests/PostgresNIOTests/New/Connection State Machine/AuthenticationStateMachineTests.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ class AuthenticationStateMachineTests: XCTestCase {
2222
XCTAssertEqual(state.authenticationMessageReceived(.ok), .wait)
2323
}
2424

25+
func testAuthenticateMD5WithoutPassword() {
26+
let authContext = AuthContext(username: "test", password: nil, database: "test")
27+
var state = ConnectionStateMachine(.waitingToStartAuthentication)
28+
let salt: (UInt8, UInt8, UInt8, UInt8) = (0, 1, 2, 3)
29+
30+
XCTAssertEqual(state.provideAuthenticationContext(authContext), .sendStartupMessage(authContext))
31+
XCTAssertEqual(state.authenticationMessageReceived(.md5(salt: salt)),
32+
.closeConnectionAndCleanup(.init(action: .close, tasks: [], error: .authMechanismRequiresPassword, closePromise: nil)))
33+
}
34+
2535
func testAuthenticateOkAfterStartUpWithoutAuthChallenge() {
2636
let authContext = AuthContext(username: "test", password: "abc123", database: "test")
2737
var state = ConnectionStateMachine(.waitingToStartAuthentication)

Tests/PostgresNIOTests/New/Connection State Machine/ConnectionStateMachineTests.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ class ConnectionStateMachineTests: XCTestCase {
2525
XCTAssertEqual(state.authenticationMessageReceived(.md5(salt: salt)), .sendPasswordMessage(.md5(salt: salt), authContext))
2626
}
2727

28+
func testSSLStartupFailHandler() {
29+
struct SSLHandlerAddError: Error, Equatable {}
30+
31+
var state = ConnectionStateMachine()
32+
XCTAssertEqual(state.connected(requireTLS: true), .sendSSLRequest)
33+
XCTAssertEqual(state.sslSupportedReceived(), .establishSSLConnection)
34+
let failError: PSQLError = .failedToAddSSLHandler(underlying: SSLHandlerAddError())
35+
XCTAssertEqual(state.errorHappened(failError), .closeConnectionAndCleanup(.init(action: .close, tasks: [], error: failError, closePromise: nil)))
36+
}
37+
2838
func testSSLStartupSSLUnsupported() {
2939
var state = ConnectionStateMachine()
3040

Tests/PostgresNIOTests/New/PSQLBackendMessageTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ class PSQLBackendMessageTests: XCTestCase {
269269
XCTAssertEqual("\(PSQLBackendMessage.authentication(.sspi))",
270270
".authentication(.sspi)")
271271

272+
XCTAssertEqual("\(PSQLBackendMessage.parameterStatus(.init(parameter: "foo", value: "bar")))",
273+
#".parameterStatus(parameter: "foo", value: "bar")"#)
272274
XCTAssertEqual("\(PSQLBackendMessage.backendKeyData(.init(processID: 1234, secretKey: 4567)))",
273275
".backendKeyData(processID: 1234, secretKey: 4567)")
274276

0 commit comments

Comments
 (0)